tomcat禁用8005端口的時候報錯 "SEVERE: No shutdown port configured. Shut down server through OS signal. Server not shut down.",報錯原因是因為:
禁用關閉命令端口在tomcat以windows服務或linux等系統的jsvc方式啟動時可以生效,在標准shell腳本啟動的方式下不會生效,這將阻止shutdown和catalina腳本停止tomcat
所以這里介紹jsvc方式啟動tomcat
安裝jsvc
[root@iZzm446eh1ux98Z apache-tomcat-8.5.57]# cd bin/ [root@iZzm446eh1ux98Z bin]# tar xfz commons-daemon-native.tar.gz [root@iZzm446eh1ux98Z bin]# cd commons-daemon-1.2.2-native-src/unix [root@iZzm446eh1ux98Z unix]# pwd /opt/softwares/apache-tomcat-8.5.57/bin/commons-daemon-1.2.2-native-src/unix
編譯安裝
[root@iZzm446eh1ux98Z unix]# ./configure --with-java=$JAVA_HOME *** Current host *** checking build system type... x86_64-pc-linux-gnu checking host system type... x86_64-pc-linux-gnu checking cached host system type... ok *** C-Language compilation tools *** checking for gcc... gcc checking whether the C compiler works... yes checking for C compiler default output file name... a.out checking for suffix of executables... checking whether we are cross compiling... no checking for suffix of object files... o checking whether we are using the GNU C compiler... yes checking whether gcc accepts -g... yes checking for gcc option to accept ISO C89... none needed checking for ranlib... ranlib checking for strip... strip *** Host support *** checking C flags dependant on host system type... ok *** Java compilation tools *** checking JAVA_HOME... /opt/softwares/jdk1.8.0_201 checking for JDK os include directory... linux gcc flags added checking how to run the C preprocessor... gcc -E checking for grep that handles long lines and -e... /usr/bin/grep checking for egrep... /usr/bin/grep -E checking for ANSI C header files... yes checking for sys/types.h... yes checking for sys/stat.h... yes checking for stdlib.h... yes checking for string.h... yes checking for memory.h... yes checking for strings.h... yes checking for inttypes.h... yes checking for stdint.h... yes checking for unistd.h... yes checking sys/capability.h usability... no checking sys/capability.h presence... no checking for sys/capability.h... no configure: WARNING: cannot find headers for libcap *** Writing output files *** configure: creating ./config.status config.status: creating Makefile config.status: creating Makedefs config.status: creating native/Makefile *** All done *** Now you can issue "make"
[root@iZzm446eh1ux98Z unix]# make (cd native; make all) make[1]: Entering directory '/opt/softwares/apache-tomcat-8.5.57/bin/commons-daemon-1.2.2-native-src/unix/native' gcc -g -O2 -DOS_LINUX -DDSO_DLFCN -DCPU=\"amd64\" -Wall -Wstrict-prototypes -I/opt/softwares/jdk1.8.0_201/include -I/opt/softwares/jdk1.8.0_201/include/linux -c jsvc-unix.c -o jsvc-unix.o jsvc-unix.c: In function ‘run_controller’: jsvc-unix.c:1293:20: warning: assignment to ‘__sighandler_t’ {aka ‘void (*)(int)’} from incompatible pointer type ‘void (*)(int, siginfo_t *, void *)’ {aka ‘void (*)(int, struct <anonymous> *, void *)’} [-Wincompatible-pointer-types] act.sa_handler = controller; ^ gcc -g -O2 -DOS_LINUX -DDSO_DLFCN -DCPU=\"amd64\" -Wall -Wstrict-prototypes -I/opt/softwares/jdk1.8.0_201/include -I/opt/softwares/jdk1.8.0_201/include/linux -c arguments.c -o arguments.o gcc -g -O2 -DOS_LINUX -DDSO_DLFCN -DCPU=\"amd64\" -Wall -Wstrict-prototypes -I/opt/softwares/jdk1.8.0_201/include -I/opt/softwares/jdk1.8.0_201/include/linux -c debug.c -o debug.o gcc -g -O2 -DOS_LINUX -DDSO_DLFCN -DCPU=\"amd64\" -Wall -Wstrict-prototypes -I/opt/softwares/jdk1.8.0_201/include -I/opt/softwares/jdk1.8.0_201/include/linux -c dso-dlfcn.c -o dso-dlfcn.o gcc -g -O2 -DOS_LINUX -DDSO_DLFCN -DCPU=\"amd64\" -Wall -Wstrict-prototypes -I/opt/softwares/jdk1.8.0_201/include -I/opt/softwares/jdk1.8.0_201/include/linux -c dso-dyld.c -o dso-dyld.o gcc -g -O2 -DOS_LINUX -DDSO_DLFCN -DCPU=\"amd64\" -Wall -Wstrict-prototypes -I/opt/softwares/jdk1.8.0_201/include -I/opt/softwares/jdk1.8.0_201/include/linux -c help.c -o help.o gcc -g -O2 -DOS_LINUX -DDSO_DLFCN -DCPU=\"amd64\" -Wall -Wstrict-prototypes -I/opt/softwares/jdk1.8.0_201/include -I/opt/softwares/jdk1.8.0_201/include/linux -c home.c -o home.o gcc -g -O2 -DOS_LINUX -DDSO_DLFCN -DCPU=\"amd64\" -Wall -Wstrict-prototypes -I/opt/softwares/jdk1.8.0_201/include -I/opt/softwares/jdk1.8.0_201/include/linux -c java.c -o java.o gcc -g -O2 -DOS_LINUX -DDSO_DLFCN -DCPU=\"amd64\" -Wall -Wstrict-prototypes -I/opt/softwares/jdk1.8.0_201/include -I/opt/softwares/jdk1.8.0_201/include/linux -c location.c -o location.o gcc -g -O2 -DOS_LINUX -DDSO_DLFCN -DCPU=\"amd64\" -Wall -Wstrict-prototypes -I/opt/softwares/jdk1.8.0_201/include -I/opt/softwares/jdk1.8.0_201/include/linux -c replace.c -o replace.o gcc -g -O2 -DOS_LINUX -DDSO_DLFCN -DCPU=\"amd64\" -Wall -Wstrict-prototypes -I/opt/softwares/jdk1.8.0_201/include -I/opt/softwares/jdk1.8.0_201/include/linux -c locks.c -o locks.o gcc -g -O2 -DOS_LINUX -DDSO_DLFCN -DCPU=\"amd64\" -Wall -Wstrict-prototypes -I/opt/softwares/jdk1.8.0_201/include -I/opt/softwares/jdk1.8.0_201/include/linux -c signals.c -o signals.o 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 ranlib libservice.a gcc jsvc-unix.o libservice.a -ldl -lpthread -o ../jsvc make[1]: Leaving directory '/opt/softwares/apache-tomcat-8.5.57/bin/commons-daemon-1.2.2-native-src/unix/native'
將編譯生成的jsvc拷貝到$CATALINA_BASE/bin下
[root@iZzm446eh1ux98Z unix]# ll total 412 -rw-r--r-- 1 root root 15791 Sep 5 15:48 config.log -rwxr-xr-x 1 root root 102 Sep 5 15:47 config.nice -rwxr-xr-x 1 root root 24865 Sep 5 15:48 config.status -rwxrwxr-x 1 1000 1000 147290 Sep 30 2019 configure -rw-r--r-- 1 1000 1000 5055 Sep 30 2019 configure.in -rw-r--r-- 1 1000 1000 2594 Sep 30 2019 INSTALL.txt -rwxr-xr-x 1 root root 190560 Sep 5 15:48 jsvc -rw-r--r-- 1 root root 1195 Sep 5 15:48 Makedefs -rw-r--r-- 1 1000 1000 1081 Sep 30 2019 Makedefs.in -rw-r--r-- 1 root root 1110 Sep 5 15:48 Makefile -rw-r--r-- 1 1000 1000 1110 Sep 30 2019 Makefile.in drwxr-xr-x 2 1000 1000 58 Sep 5 15:43 man drwxr-xr-x 2 1000 1000 4096 Sep 5 15:48 native drwxr-xr-x 2 1000 1000 158 Sep 5 15:43 support [root@iZzm446eh1ux98Z unix]# cp jsvc /opt/softwares/apache-tomcat-8.5.57/bin/
將$CATALINA_BASE/bin下的daemon.sh拷貝到/etc/init.d/下
[root@iZzm446eh1ux98Z unix]# cd /opt/softwares/apache-tomcat-8.5.57/bin/ [root@iZzm446eh1ux98Z bin]# ll total 1056 -rw-r----- 1 root root 36149 Jul 1 05:50 bootstrap.jar -rw-r----- 1 root root 16608 Jul 1 05:50 catalina.bat -rwxr-x--- 1 root root 25245 Jul 1 05:50 catalina.sh -rw-r----- 1 root root 1664 Jul 1 05:53 catalina-tasks.xml -rw-r----- 1 root root 2123 Jul 1 05:50 ciphers.bat -rwxr-x--- 1 root root 1997 Jul 1 05:50 ciphers.sh drwxr-xr-x 4 root root 95 Sep 5 15:43 commons-daemon-1.2.2-native-src -rw-r----- 1 root root 25197 Jul 1 05:50 commons-daemon.jar -rw-r----- 1 root root 206895 Jul 1 05:50 commons-daemon-native.tar.gz -rw-r----- 1 root root 2040 Jul 1 05:50 configtest.bat -rwxr-x--- 1 root root 1922 Jul 1 05:50 configtest.sh -rwxr-x--- 1 root root 9100 Jul 1 05:50 daemon.sh -rw-r----- 1 root root 2091 Jul 1 05:50 digest.bat -rwxr-x--- 1 root root 1965 Jul 1 05:50 digest.sh -rwxr-xr-x 1 root root 190560 Sep 5 15:49 jsvc -rw-r----- 1 root root 3460 Jul 1 05:50 setclasspath.bat -rwxr-x--- 1 root root 3708 Jul 1 05:50 setclasspath.sh -rw-r----- 1 root root 2020 Jul 1 05:50 shutdown.bat -rwxr-x--- 1 root root 1902 Jul 1 05:50 shutdown.sh -rw-r----- 1 root root 2022 Jul 1 05:50 startup.bat -rwxr-x--- 1 root root 1904 Jul 1 05:50 startup.sh -rw-r----- 1 root root 51232 Jul 1 05:50 tomcat-juli.jar -rw-r----- 1 root root 419572 Jul 1 05:50 tomcat-native.tar.gz -rw-r----- 1 root root 4574 Jul 1 05:50 tool-wrapper.bat -rwxr-x--- 1 root root 5540 Jul 1 05:50 tool-wrapper.sh -rw-r----- 1 root root 2026 Jul 1 05:50 version.bat -rwxr-x--- 1 root root 1908 Jul 1 05:50 version.sh
[root@iZzm446eh1ux98Z bin]# cp daemon.sh /etc/init.d/tomcat
設置環境變量
[root@iZzm446eh1ux98Z bin]# vim /etc/profile.d/catalina.sh export CATALINA_HOME=/opt/softwares/apache-tomcat-8.5.57 export CATALINA_BASE=/opt/softwares/apache-tomcat-8.5.57
[root@iZzm446eh1ux98Z bin]# vim /etc/profile export JAVA_HOME=/opt/softwares/jdk1.8.0_201 export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH export CLASSPATH=.$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar
修改/etc/init.d/tomcat
[root@iZzm446eh1ux98Z bin]# vim /etc/init.d/tomcat #!/bin/sh # chkconfig: 2345 25 85 #添加到頭部,這是服務配置信息 # description: Tomcat daemon project .... # ----------------------------------------------------------------------------- # Commons Daemon wrapper script. # ----------------------------------------------------------------------------- JAVA_HOME=/opt/softwares/jdk1.8.0_201 #配置環境變量 CATALINA_HOME=/opt/softwares/apache-tomcat-8.5.57 # resolve links - $0 may be a softlink test ".$TOMCAT_USER" = . && TOMCAT_USER=tomcat # 這里的tomcat改成tomcat啟動用戶,如果啟動報錯Invalid user name 'tomcat' specified,那么添加一下就可以了useradd -s /sbin/nologin -M tomcat
修改權限
[root@iZzm446eh1ux98Z bin]# chown -R tomcat.tomcat /opt/softwares/apache-tomcat-8.5.57/
添加開機自啟動
chkconfig --add tomcat
chkconfig --list
啟動
[root@iZzm446eh1ux98Z bin]# service tomcat start