[CentOS] JDK+tomcat 集群 + nginx 一鍵安裝腳本 整理了一下在 CentOS 下 JDK+tomcat 集群 + nginx 的安裝腳本。支持 CentOS6.x/7.x
1. 安裝前準備
# is root user
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
完整的安裝腳本
is root user#
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