自动部署tomcat,并以普通用户身份运行 for centos6

 

 

 1 #!/bin/bash
 2 
 3 ########    install jdk    
 4 
 5 install_jdk () {
 6 rpm -e ‘rpm -qa |grep jdk’
 7 
 8 wget \
 9     --no-check-certificate \
10     --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" \
11     http://download.oracle.com/otn-pub/java/jdk/8u102-b14/jdk-8u102-linux-x64.tar.gz
12 
13 tar zxf jdk-8u102-linux-x64.tar.gz -C /usr/local/src/
14 
15 ln -s /usr/local/src/jdk1.8.0_102 /usr/local/jdk
16 
17 sed -i '$a \
18 JAVA_HOME=/usr/local/jdk \
19 CLASSPATH=$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar \
20 PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH \
21 export JAVA_HOME \
22 export PATH \
23 export CLASSPATH' /etc/profile
24 
25 source /etc/profile
26 
27 java -version && echo 'JDK 安装成功 '|| echo 'JDK 安装失败 '
28 
29 }
30 
31 ########    install tomcat
32 
33 install_tomcat () {
34 wget http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-7/v7.0.76/bin/apache-tomcat-7.0.76.tar.gz
35 
36 tar zxf apache-tomcat-7.0.76.tar.gz -C /usr/local/
37 
38 ln -s /usr/local/apache-tomcat-7.0.76 /usr/local/tomcat
39 }
40 
41 ########    install jsvc
42 
43 install_jsvc () {
44 
45 cd /usr/local/tomcat/bin/
46 tar xf commons-daemon-native.tar.gz
47 cd `find . -type d -name 'commons-daemon*'`
48 cd unix
49 ./configure --with-java=/usr/local/jdk
50 make
51 cp jsvc /usr/local/tomcat/bin/
52 echo "JAVA_HOME=/usr/local/jdk
53 TOMCAT_USER=tomcat
54 JSVC_OPTS='-jvm server'
55 JAVA_OPTS=
56 " >/usr/local/tomcat/bin/setenv.sh
57 useradd -s /sbin/nologin -M tomcat
58 chown -R tomcat /usr/local/tomcat
59 ln -s /usr/local/tomcat/bin/daemon.sh /etc/init.d/tomcat
60 sed -i '1a \
61 # chkconfig: - 86 14\
62 # description: Tomcat7 daemon\
63 # processname: tomcat
64 ' /usr/local/tomcat/bin/daemon.sh
65 
66 chkconfig --add tomcat
67 service tomcat start
68 }
69 
70 install_jdk
71 install_tomcat
72 install_jsvc

 

 

 

  1 [root@4sztj ~]# sh -x in.sh |tee a.log
  2 + install_jdk
  3 + rpm -e $'\342\200\230rpm' -qa
  4 + grep $'jdk\342\200\231'
  5 + wget --no-check-certificate --no-cookies --header 'Cookie: oraclelicense=accept-securebackup-cookie' http://download.oracle.com/otn-pub/java/jdk/8u102-b14/jdk-8u102-linux-x64.tar.gz
  6 --2017-03-21 00:40:53--  http://download.oracle.com/otn-pub/java/jdk/8u102-b14/jdk-8u102-linux-x64.tar.gz
  7 Resolving download.oracle.com... 80.239.178.64, 80.239.178.88
  8 Connecting to download.oracle.com|80.239.178.64|:80... connected.
  9 HTTP request sent, awaiting response... 302 Moved Temporarily
 10 Location: https://edelivery.oracle.com/otn-pub/java/jdk/8u102-b14/jdk-8u102-linux-x64.tar.gz [following]
 11 --2017-03-21 00:40:53--  https://edelivery.oracle.com/otn-pub/java/jdk/8u102-b14/jdk-8u102-linux-x64.tar.gz
 12 Resolving edelivery.oracle.com... 104.77.43.178, 2600:1417:9:28c::2d3e, 2600:1417:9:287::2d3e
 13 Connecting to edelivery.oracle.com|104.77.43.178|:443... connected.
 14 HTTP request sent, awaiting response... 302 Moved Temporarily
 15 Location: http://download.oracle.com/otn-pub/java/jdk/8u102-b14/jdk-8u102-linux-x64.tar.gz?AuthParam=1490028175_14998b431b1fff4df93acf9fec0dc9ac [following]
 16 --2017-03-21 00:40:54--  http://download.oracle.com/otn-pub/java/jdk/8u102-b14/jdk-8u102-linux-x64.tar.gz?AuthParam=1490028175_14998b431b1fff4df93acf9fec0dc9ac
 17 Connecting to download.oracle.com|80.239.178.64|:80... connected.
 18 HTTP request sent, awaiting response... 200 OK
 19 Length: 181435897 (173M) [application/x-gzip]
 20 Saving to: “jdk-8u102-linux-x64.tar.gz”
 21 
 22 100%[=============================================================================================>] 181,435,897 1.93M/s   in 98s     
 23 
 24 2017-03-21 00:42:33 (1.76 MB/s) - “jdk-8u102-linux-x64.tar.gz” saved [181435897/181435897]
 25 
 26 + tar zxf jdk-8u102-linux-x64.tar.gz -C /usr/local/src/
 27 + ln -s /usr/local/src/jdk1.8.0_102 /usr/local/jdk
 28 + sed -i '$a \
 29 JAVA_HOME=/usr/local/jdk \
 30 CLASSPATH=$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar \
 31 PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH \
 32 export JAVA_HOME \
 33 export PATH \
 34 export CLASSPATH' /etc/profile
 35 + source /etc/profile
 36 ++ '[' -x /usr/bin/id ']'
 37 ++ '[' -z 0 ']'
 38 +++ id -un
 39 ++ USER=root
 40 ++ LOGNAME=root
 41 ++ MAIL=/var/spool/mail/root
 42 ++ '[' 0 = 0 ']'
 43 ++ pathmunge /sbin
 44 ++ case ":${PATH}:" in
 45 ++ pathmunge /usr/sbin
 46 ++ case ":${PATH}:" in
 47 ++ pathmunge /usr/local/sbin
 48 ++ case ":${PATH}:" in
 49 +++ /bin/hostname
 50 ++ HOSTNAME=4sztj
 51 ++ HISTSIZE=1000
 52 ++ '[' ignoredups = ignorespace ']'
 53 ++ export HISTCONTROL=ignoredups
 54 ++ HISTCONTROL=ignoredups
 55 ++ export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL
 56 ++ '[' 0 -gt 199 ']'
 57 ++ umask 022
 58 ++ for i in '/etc/profile.d/*.sh'
 59 ++ '[' -r /etc/profile.d/colorls.sh ']'
 60 ++ '[' hxB '!=' hxB ']'
 61 ++ . /etc/profile.d/colorls.sh
 62 ++ for i in '/etc/profile.d/*.sh'
 63 ++ '[' -r /etc/profile.d/cvs.sh ']'
 64 ++ '[' hxB '!=' hxB ']'
 65 ++ . /etc/profile.d/cvs.sh
 66 ++ for i in '/etc/profile.d/*.sh'
 67 ++ '[' -r /etc/profile.d/glib2.sh ']'
 68 ++ '[' hxB '!=' hxB ']'
 69 ++ . /etc/profile.d/glib2.sh
 70 ++ for i in '/etc/profile.d/*.sh'
 71 ++ '[' -r /etc/profile.d/lang.sh ']'
 72 ++ '[' hxB '!=' hxB ']'
 73 ++ . /etc/profile.d/lang.sh
 74 ++ for i in '/etc/profile.d/*.sh'
 75 ++ '[' -r /etc/profile.d/less.sh ']'
 76 ++ '[' hxB '!=' hxB ']'
 77 ++ . /etc/profile.d/less.sh
 78 ++ for i in '/etc/profile.d/*.sh'
 79 ++ '[' -r /etc/profile.d/qt.sh ']'
 80 ++ '[' hxB '!=' hxB ']'
 81 ++ . /etc/profile.d/qt.sh
 82 ++ for i in '/etc/profile.d/*.sh'
 83 ++ '[' -r /etc/profile.d/vim.sh ']'
 84 ++ '[' hxB '!=' hxB ']'
 85 ++ . /etc/profile.d/vim.sh
 86 ++ for i in '/etc/profile.d/*.sh'
 87 ++ '[' -r /etc/profile.d/which2.sh ']'
 88 ++ '[' hxB '!=' hxB ']'
 89 ++ . /etc/profile.d/which2.sh
 90 ++ unset i
 91 ++ unset -f pathmunge
 92 ++ JAVA_HOME=/usr/local/jdk
 93 ++ CLASSPATH=/usr/local/jdk/lib/dt.jar:/usr/local/jdk/lib/tools.jar
 94 ++ PATH=/usr/local/jdk/bin:/usr/local/jdk/jre/bin:/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
 95 ++ export JAVA_HOME
 96 ++ export PATH
 97 ++ export CLASSPATH
 98 + java -version
 99 java version "1.8.0_102"
100 Java(TM) SE Runtime Environment (build 1.8.0_102-b14)
101 Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode)
102 + echo 'JDK 安装成功 '
103 + install_tomcat
104 + wget http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-7/v7.0.76/bin/apache-tomcat-7.0.76.tar.gz
105 JDK 安装成功 
106 --2017-03-21 00:42:43--  http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-7/v7.0.76/bin/apache-tomcat-7.0.76.tar.gz
107 Resolving mirrors.tuna.tsinghua.edu.cn... 166.111.206.177, 2402:f000:1:416:166:111:206:177
108 Connecting to mirrors.tuna.tsinghua.edu.cn|166.111.206.177|:80... connected.
109 HTTP request sent, awaiting response... 200 OK
110 Length: 8957288 (8.5M) [application/octet-stream]
111 Saving to: “apache-tomcat-7.0.76.tar.gz”
112 
113 100%[=============================================================================================>] 8,957,288   16.8M/s   in 0.5s    
114 
115 2017-03-21 00:42:44 (16.8 MB/s) - “apache-tomcat-7.0.76.tar.gz” saved [8957288/8957288]
116 
117 + tar zxf apache-tomcat-7.0.76.tar.gz -C /usr/local/
118 + ln -s /usr/local/apache-tomcat-7.0.76 /usr/local/tomcat
119 + install_jsvc
120 + cd /usr/local/tomcat/bin/
121 + tar xf commons-daemon-native.tar.gz
122 ++ find . -type d -name 'commons-daemon*'
123 + cd ./commons-daemon-1.0.15-native-src
124 + cd unix
125 + ./configure --with-java=/usr/local/jdk
126 *** Current host ***
127 checking build system type... x86_64-unknown-linux-gnu
128 checking host system type... x86_64-unknown-linux-gnu
129 *** C-Language compilation tools ***
130 checking cached host system type... ok
131 checking for gcc... gcc
132 checking for C compiler default output file name... a.out
133 checking whether the C compiler works... yes
134 checking whether we are cross compiling... no
135 checking for suffix of executables... 
136 checking for suffix of object files... o
137 checking whether we are using the GNU C compiler... yes
138 checking whether gcc accepts -g... yes
139 checking for gcc option to accept ANSI C... none needed
140 checking for ranlib... *** Host support ***
141 ranlib
142 checking for strip... strip
143 checking C flags dependant on host system type... *** Java compilation tools ***
144 ok
145 checking JAVA_HOME... /usr/local/jdk
146 checking for JDK os include directory...  linux
147 gcc flags added
148 checking how to run the C preprocessor... gcc -E
149 checking for egrep... grep -E
150 checking for ANSI C header files... yes
151 checking for sys/types.h... yes
152 checking for sys/stat.h... yes
153 checking for stdlib.h... yes
154 checking for string.h... yes
155 checking for memory.h... yes
156 checking for strings.h... yes
157 checking for inttypes.h... yes
158 checking for stdint.h... yes
159 checking for unistd.h... yes
160 checking sys/capability.h usability... no
161 checking sys/capability.h presence... configure: WARNING: cannot find headers for libcap
162 *** Writing output files ***
163 no
164 checking for sys/capability.h... no
165 configure: creating ./config.status
166 config.status: creating Makefile
167 config.status: creating Makedefs
168 config.status: creating native/Makefile
169 *** All done ***
170 Now you can issue "make"
171 + make
172 (cd native; make  all)
173 make[1]: Entering directory `/usr/local/apache-tomcat-7.0.76/bin/commons-daemon-1.0.15-native-src/unix/native'
174 gcc -g -O2 -DOS_LINUX -DDSO_DLFCN -DCPU=\"amd64\" -Wall -Wstrict-prototypes   -I/usr/local/jdk/include -I/usr/local/jdk/include/linux -c jsvc-unix.c -o jsvc-unix.o
175 gcc -g -O2 -DOS_LINUX -DDSO_DLFCN -DCPU=\"amd64\" -Wall -Wstrict-prototypes   -I/usr/local/jdk/include -I/usr/local/jdk/include/linux -c arguments.c -o arguments.o
176 gcc -g -O2 -DOS_LINUX -DDSO_DLFCN -DCPU=\"amd64\" -Wall -Wstrict-prototypes   -I/usr/local/jdk/include -I/usr/local/jdk/include/linux -c debug.c -o debug.o
177 gcc -g -O2 -DOS_LINUX -DDSO_DLFCN -DCPU=\"amd64\" -Wall -Wstrict-prototypes   -I/usr/local/jdk/include -I/usr/local/jdk/include/linux -c dso-dlfcn.c -o dso-dlfcn.o
178 gcc -g -O2 -DOS_LINUX -DDSO_DLFCN -DCPU=\"amd64\" -Wall -Wstrict-prototypes   -I/usr/local/jdk/include -I/usr/local/jdk/include/linux -c dso-dyld.c -o dso-dyld.o
179 gcc -g -O2 -DOS_LINUX -DDSO_DLFCN -DCPU=\"amd64\" -Wall -Wstrict-prototypes   -I/usr/local/jdk/include -I/usr/local/jdk/include/linux -c help.c -o help.o
180 gcc -g -O2 -DOS_LINUX -DDSO_DLFCN -DCPU=\"amd64\" -Wall -Wstrict-prototypes   -I/usr/local/jdk/include -I/usr/local/jdk/include/linux -c home.c -o home.o
181 gcc -g -O2 -DOS_LINUX -DDSO_DLFCN -DCPU=\"amd64\" -Wall -Wstrict-prototypes   -I/usr/local/jdk/include -I/usr/local/jdk/include/linux -c java.c -o java.o
182 gcc -g -O2 -DOS_LINUX -DDSO_DLFCN -DCPU=\"amd64\" -Wall -Wstrict-prototypes   -I/usr/local/jdk/include -I/usr/local/jdk/include/linux -c location.c -o location.o
183 gcc -g -O2 -DOS_LINUX -DDSO_DLFCN -DCPU=\"amd64\" -Wall -Wstrict-prototypes   -I/usr/local/jdk/include -I/usr/local/jdk/include/linux -c replace.c -o replace.o
184 gcc -g -O2 -DOS_LINUX -DDSO_DLFCN -DCPU=\"amd64\" -Wall -Wstrict-prototypes   -I/usr/local/jdk/include -I/usr/local/jdk/include/linux -c locks.c -o locks.o
185 gcc -g -O2 -DOS_LINUX -DDSO_DLFCN -DCPU=\"amd64\" -Wall -Wstrict-prototypes   -I/usr/local/jdk/include -I/usr/local/jdk/include/linux -c signals.c -o signals.o
186 ar cr libservice.a arguments.o debug.o dso-dlfcn.o dso-dyld.o help.o home.o java.o location.o replace.o locks.o signals.o
187 ranlib libservice.a
188 gcc   jsvc-unix.o libservice.a -ldl -lpthread -o ../jsvc
189 make[1]: Leaving directory `/usr/local/apache-tomcat-7.0.76/bin/commons-daemon-1.0.15-native-src/unix/native'
190 + cp jsvc /usr/local/tomcat/bin/
191 + echo 'JAVA_HOME=/usr/local/jdk
192 TOMCAT_USER=tomcat
193 JSVC_OPTS='\''-jvm server'\''
194 JAVA_OPTS=
195 '
196 + useradd -s /sbin/nologin -M tomcat
197 + chown -R tomcat /usr/local/tomcat
198 + ln -s /usr/local/tomcat/bin/daemon.sh /etc/init.d/tomcat
199 + sed -i '1a \
200 # chkconfig: - 86 14\
201 # description: Tomcat7 daemon\
202 # processname: tomcat
203 ' /usr/local/tomcat/bin/daemon.sh
204 + chkconfig --add tomcat
205 + service tomcat start
206 [root@4sztj ~]# 

 

posted @ 2017-03-21 00:46  三角形  阅读(1775)  评论(0编辑  收藏  举报