Home > 系统管理 > [CentOS] JDK+tomcat集群+nginx一键安装脚本

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

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

1.安装前准备

1
2
3
4
5
# is root user
if [ "$(whoami)" != 'root' ]; then
echo "install need root user"
exit
fi

2.下载必要的安装文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
echo "========================preparing install packages======================"
file1=./jdk-8u144-linux-x64.tar.gz
if [ ! -f "$file1" ]; then
echo "need jdk-8u144-linux-x64.tar.gz,try to downloading."
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 "need apache-tomcat-8.0.45.tar.gz, try to downloading."
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 "need nginx-1.13.4.tar.gz, try to downloading."
curl -O  http://nginx.org/download/nginx-1.13.4.tar.gz
fi

3.安装JDK

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#)install JDK
echo "========================jdk is installing======================"
tar zxvf jdk-8u144-linux-x64.tar.gz
mv jdk1.8.0_144 /usr/local/jdk1.8.0_144
echo "jdk1.8.0_144 is rename to /usr/local/jdk1.8.0_144"
ln -s /usr/local/jdk1.8.0_144 /usr/local/jdk
echo "jdk1.8.0_144 is link to /usr/local/jdk"
;
 
#)Add the environment variable to /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实例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#)Install tomcat
echo "====================apache-tomcat is installing==================="
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
#)Configure 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
#)Configure 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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#install nginx
echo "====================nginx is installing==================="
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
 
#make symbol links
ln -s /usr/local/nginx-1.13.4 /usr/local/nginx

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

1
2
3
echo "====================install subversion==================="
#install subversion
yum install -y subversion

7.启动应用

1
2
3
4
5
6
7
8
9
10
echo "====================startup application==================="
#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

完整的安装脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
 
# is root user
if [ "$(whoami)" != 'root' ]; then
echo "install need root user"
exit
fi
 
echo "========================preparing install packages======================"
file1=./jdk-8u144-linux-x64.tar.gz
if [ ! -f "$file1" ]; then
echo "need jdk-8u144-linux-x64.tar.gz,try to downloading."
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 "need apache-tomcat-8.0.45.tar.gz, try to downloading."
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 "need nginx-1.13.4.tar.gz, try to downloading."
curl -O  http://nginx.org/download/nginx-1.13.4.tar.gz
fi
 
#)install JDK
echo "========================jdk is installing======================"
tar zxvf jdk-8u144-linux-x64.tar.gz
mv jdk1.8.0_144 /usr/local/jdk1.8.0_144
echo "jdk1.8.0_144 is rename to /usr/local/jdk1.8.0_144"
ln -s /usr/local/jdk1.8.0_144 /usr/local/jdk
echo "jdk1.8.0_144 is link to /usr/local/jdk"
;
 
#)Add the environment variable to /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
 
#)Install tomcat
echo "====================apache-tomcat is installing==================="
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
#)Configure 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
#)Configure 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
 
#install nginx
echo "====================nginx is installing==================="
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
 
#make symbol links
ln -s /usr/local/nginx-1.13.4 /usr/local/nginx
 
echo "====================install subversion==================="
#install subversion
yum install -y subversion
 
echo "====================startup application==================="
#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
Categories: 系统管理 Tags: , ,
  1. No comments yet.
  1. No trackbacks yet.