banner
李大仁博客

李大仁博客

天地虽大,但有一念向善,心存良知,虽凡夫俗子,皆可为圣贤。

[CentOS] JDK+tomcat集群+nginx一键安装脚本

[CentOS] JDK+tomcat 集群 + nginx 一键安装脚本 整理了一下在 CentOS 下 JDK+tomcat 集群 + nginx 的安装脚本。支持 CentOS6.x/7.x

1. 安装前准备

# 是 root 用户
if [ "$(whoami)" != 'root' ]; then
echo "安装需要 root 用户"
exit
fi

2. 下载必要的安装文件

echo "======================== 准备安装包 ======================"
file1=./jdk-8u144-linux-x64.tar.gz
if [ ! -f "$file1" ]; then
echo "需要 jdk-8u144-linux-x64.tar.gz,尝试下载."
curl -L -C - -b "oraclelicense=accept-securebackup-cookie" -O http://download.oracle.com/otn-pub/java/jdk/8u144-b01/090f390dda5b47b9b721c7dfaa008135/jdk-8u144-linux-x64.tar.gz
fi

file2=./apache-tomcat-8.0.45.tar.gz
if [ ! -f "$flie2" ]; then
echo "需要 apache-tomcat-8.0.45.tar.gz, 尝试下载."
curl -O http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.0.45/bin/apache-tomcat-8.0.45.tar.gz
fi

file3=./nginx-1.13.4.tar.gz
if [ ! -f "$flie3" ]; then
echo "需要 nginx-1.13.4.tar.gz, 尝试下载."
curl -O http://nginx.org/download/nginx-1.13.4.tar.gz
fi

3. 安装 JDK

#) 安装 JDK
echo "========================jdk 正在安装 ======================"
tar zxvf jdk-8u144-linux-x64.tar.gz
mv jdk1.8.0_144 /usr/local/jdk1.8.0_144
echo "jdk1.8.0_144 重命名为 /usr/local/jdk1.8.0_144"
ln -s /usr/local/jdk1.8.0_144 /usr/local/jdk
echo "jdk1.8.0_144 链接到 /usr/local/jdk"
;

#) 将环境变量添加到 /etc/profile
echo "export JAVA_HOME=/usr/local/jdk" >> /etc/profile
echo "export PATH=$JAVA_HOME/bin:$PATH" >> /etc/profile
echo "export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar" >> /etc/profile
;
source /etc/profile

4. 安装 Tomcat,此处使用单独实例方式安装多个 Tomcat 实例

#) 安装 tomcat
echo "====================apache-tomcat 正在安装 ==================="
tar zxvf apache-tomcat-8.0.45.tar.gz
mv apache-tomcat-8.0.45 /usr/local/tomcat1
cp -p /usr/local/tomcat1/bin/catalina.sh /etc/init.d/tomcat1
#) 配置 tomcat
sed -i '1a\. /etc/init.d/functions' /etc/init.d/tomcat1
sed -i '2a\:' /etc/init.d/tomcat1
sed -i '3a\JAVA_HOME=/usr/local/jdk' /etc/init.d/tomcat1
sed -i '4a\CATALINA_BASE=/usr/local/tomcat1' /etc/init.d/tomcat1
sed -i '5a\CATALINA_HOME=/usr/local/tomcat1' /etc/init.d/tomcat1
;
#/etc/init.d/tomcat1
#chkconfig --add tomcat1
#chkconfig tomcat1 on

tar zxvf apache-tomcat-8.0.45.tar.gz
mv apache-tomcat-8.0.45 /usr/local/tomcat2
cp -p /usr/local/tomcat2/bin/catalina.sh /etc/init.d/tomcat2
#) 配置 tomcat
sed -i '1a\. /etc/init.d/functions' /etc/init.d/tomcat2
sed -i '2a\:' /etc/init.d/tomcat2
sed -i '3a\JAVA_HOME=/usr/local/jdk/' /etc/init.d/tomcat2
sed -i '4a\CATALINA_BASE=/usr/local/tomcat2' /etc/init.d/tomcat2
sed -i '5a\CATALINA_HOME=/usr/local/tomcat2' /etc/init.d/tomcat2
;
/etc/init.d/tomcat2

#chkconfig --add tomcat2
#chkconfig tomcat2 on

#/usr/local/tomcat1/bin/startup.sh
#/usr/local/tomcat1/bin/startup.sh

5. 安装 nginx

#安装 nginx
echo "====================nginx 正在安装 ==================="
yum install -y make gcc
yum install -y pcre*
yum install -y openssl*
yum install -y zlib zlib-devel

tar zxvf nginx-1.13.4.tar.gz

cd nginx-1.13.4
./configure --prefix=/usr/local/nginx-1.13.4 \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-pcre

make install

#创建符号链接
ln -s /usr/local/nginx-1.13.4 /usr/local/nginx

6. 安装 svn,管理代码和应用发布

echo "==================== 安装 subversion==================="
#安装 subversion
yum install -y subversion

7. 启动应用

echo "==================== 启动应用 ==================="
#tomcat1
/etc/init.d/tomcat1 stop
/etc/init.d/tomcat1 start
#tomcat2
/etc/init.d/tomcat1 stop
/etc/init.d/tomcat2 start
#nginx
/usr/local/nginx/sbin/nginx -s stop
/usr/local/nginx/sbin/nginx

完整的安装脚本

是 root 用户#

if [ "$(whoami)" != 'root' ]; then
echo "安装需要 root 用户"
exit
fi

echo "======================== 准备安装包 ======================"
file1=./jdk-8u144-linux-x64.tar.gz
if [ ! -f "$file1" ]; then
echo "需要 jdk-8u144-linux-x64.tar.gz,尝试下载."
curl -L -C - -b "oraclelicense=accept-securebackup-cookie" -O http://download.oracle.com/otn-pub/java/jdk/8u144-b01/090f390dda5b47b9b721c7dfaa008135/jdk-8u144-linux-x64.tar.gz
fi

file2=./apache-tomcat-8.0.45.tar.gz
if [ ! -f "$flie2" ]; then
echo "需要 apache-tomcat-8.0.45.tar.gz, 尝试下载."
curl -O http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-8/v8.0.45/bin/apache-tomcat-8.0.45.tar.gz
fi

file3=./nginx-1.13.4.tar.gz
if [ ! -f "$flie3" ]; then
echo "需要 nginx-1.13.4.tar.gz, 尝试下载."
curl -O http://nginx.org/download/nginx-1.13.4.tar.gz
fi

#) 安装 JDK
echo "========================jdk 正在安装 ======================"
tar zxvf jdk-8u144-linux-x64.tar.gz
mv jdk1.8.0_144 /usr/local/jdk1.8.0_144
echo "jdk1.8.0_144 重命名为 /usr/local/jdk1.8.0_144"
ln -s /usr/local/jdk1.8.0_144 /usr/local/jdk
echo "jdk1.8.0_144 链接到 /usr/local/jdk"
;

#) 将环境变量添加到 /etc/profile
echo "export JAVA_HOME=/usr/local/jdk" >> /etc/profile
echo "export PATH=$JAVA_HOME/bin:$PATH" >> /etc/profile
echo "export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar" >> /etc/profile
;
source /etc/profile

#) 安装 tomcat
echo "====================apache-tomcat 正在安装 ==================="
tar zxvf apache-tomcat-8.0.45.tar.gz
mv apache-tomcat-8.0.45 /usr/local/tomcat1
cp -p /usr/local/tomcat1/bin/catalina.sh /etc/init.d/tomcat1
#) 配置 tomcat
sed -i '1a\. /etc/init.d/functions' /etc/init.d/tomcat1
sed -i '2a\:' /etc/init.d/tomcat1
sed -i '3a\JAVA_HOME=/usr/local/jdk' /etc/init.d/tomcat1
sed -i '4a\CATALINA_BASE=/usr/local/tomcat1' /etc/init.d/tomcat1
sed -i '5a\CATALINA_HOME=/usr/local/tomcat1' /etc/init.d/tomcat1
;
#/etc/init.d/tomcat1
#chkconfig --add tomcat1
#chkconfig tomcat1 on

tar zxvf apache-tomcat-8.0.45.tar.gz
mv apache-tomcat-8.0.45 /usr/local/tomcat2
cp -p /usr/local/tomcat2/bin/catalina.sh /etc/init.d/tomcat2
#) 配置 tomcat
sed -i '1a\. /etc/init.d/functions' /etc/init.d/tomcat2
sed -i '2a\:' /etc/init.d/tomcat2
sed -i '3a\JAVA_HOME=/usr/local/jdk/' /etc/init.d/tomcat2
sed -i '4a\CATALINA_BASE=/usr/local/tomcat2' /etc/init.d/tomcat2
sed -i '5a\CATALINA_HOME=/usr/local/tomcat2' /etc/init.d/tomcat2
;
/etc/init.d/tomcat2
#chkconfig --add tomcat2
#chkconfig tomcat2 on

#/usr/local/tomcat1/bin/startup.sh
#/usr/local/tomcat1/bin/startup.sh

#安装 nginx
echo "====================nginx 正在安装 ==================="
yum install -y make gcc
yum install -y pcre*
yum install -y openssl*
yum install -y zlib zlib-devel

tar zxvf nginx-1.13.4.tar.gz

cd nginx-1.13.4
./configure --prefix=/usr/local/nginx-1.13.4 \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-pcre
make install

#创建符号链接
ln -s /usr/local/nginx-1.13.4 /usr/local/nginx

echo "==================== 安装 subversion==================="
#安装 subversion
yum install -y subversion

echo "==================== 启动应用 ==================="
#tomcat1
/etc/init.d/tomcat1 stop
/etc/init.d/tomcat1 start
#tomcat2
/etc/init.d/tomcat1 stop
/etc/init.d/tomcat2 start
#nginx
/usr/local/nginx/sbin/nginx -s stop
/usr/local/nginx/sbin/nginx

加载中...
此文章数据所有权由区块链加密技术和智能合约保障仅归创作者所有。