Deploy jenkins and use the common user tomcat to start the tomcat service

Install jdk+tomcat, deploy jenkins, and use common user tomcat to start the tomcat service

1. Environmental description

CentOS Linux release 7.3.1611 (Core)
jdk1.8.0_60
apache-tomcat-8.5.23

already installed

2. Compile and install the service daemon

cd /usr/local/apache-tomcat-8.5.23/bin/
tar xf commons-daemon-native.tar.gz
cd /usr/local/apache-tomcat-8.5.23/bin/commons-daemon-1.0.15-native-src/unix/
 ./configure

If the following error message appears during the compilation process, the JAVA_HOME variable is not set :

 Java compilation tools 
checking for JDK location... configure: error: Java Home not defined. Rerun with --with-java=... parameter

The JDK location can be specified via command line arguments
./configure --with-java=/usr/local/jdk1.8.0_60

After the configuration is successful, start compiling.

make
After executing make, a jsvc file will be generated and copied to the bin directory of tomcat
cp jsvc /usr/local/apache-tomcat-8.5.23/bin/

3. Create a user to run Tomcat as

useradd tomcat -s /usr/sbin/nologin

4. Modify the startup script file

vim /usr/local/apache-tomcat-8.5.23/bin/daemon.sh

   找到如下内容
test ".$TOMCAT_USER" = . && TOMCAT_USER=tomcat
#Set JAVA_HOME to working JDK or JRE
#JAVA_HOME=/opt/jdk-1.6.0.22
    修改TOMCAT_USER=tomcat为你指定用来运行tomcat的用户名,去除JAVA_HOME前的注释(即“#”号),并设置为JDK的所在目录。

    在文件靠前位置的注释中加入下面的内容

#chkconfig: - 80 20

5. Modify related directory and file permissions

chown -R tomcat.tomcat /usr/local/apache-tomcat-8.5.23
chmod a+x /usr/local/apache-tomcat-8.5.23/bin/daemon.sh

6. Configure environment variables

tail -6 /etc/profile

unset -f pathmunge
export PATH=/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/pureftpd/bin:/usr/local/tomcat/bin
export JAVA_HOME=/usr/local/jdk1.8.0_60
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
export TOMCAT_HOME=/usr/local/tomcat

source /etc/profile

7. Place the jenkins.war program in the site directory

root@VM_82_178_redhat tasks]# cd /usr/local/tomcat/webapps/
[root@VM_82_178_redhat webapps]# ls
jenkins.war  ROOT

8. Start the tomcat service

Check the basic syntax of the tomcat configuration file server.xml before starting

[root@VM_82_178_redhat bin]# which configtest.sh
/usr/local/tomcat/bin/configtest.sh

catalina.sh  configtest

View the version number of tomcat and jdk

catalina.sh version
daemon.sh version
[root@VM_82_178_redhat tomcat]# daemon.sh version
Still running according to PID file /usr/local/tomcat/logs/catalina-daemon.pid, PID is 21217
jsvc (Apache Commons Daemon) 1.0.15-dev
Copyright (c) 1999-2011 Apache Software Foundation.
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)
commons daemon version "1.0.15-dev"
commons daemon process (id: 22066, parent: 22065)
Server version: Apache Tomcat/8.5.23
Server built:   Sep 28 2017 10:30:11 UTC
Server number:  8.5.23.0
OS Name:        Linux
OS Version:     3.10.0-514.21.1.el7.x86_64
Architecture:   amd64
JVM Version:    1.8.0_60-b27
JVM Vendor:     Oracle Corporation

Start tomcat
daemon.sh start
daemon.sh stop to
view the startup process

[root@VM_82_178_redhat ~]# ps -ef|grep jsvc
root     21216     1  0 18:12 ?        00:00:00 jsvc.exec -java-home /usr/local/jdk1.8.0_60 -user tomcat -pidfile /usr/local/tomcat/logs/catalina-daemon.pid -wait 10 -outfile /usr/local/tomcat/logs/catalina-daemon.out -errfile &1 -classpath /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/commons-daemon.jar:/usr/local/tomcat/bin/tomcat-juli.jar -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Dcatalina.base=/usr/local/tomcat -Dcatalina.home=/usr/local/tomcat -Djava.io.tmpdir=/usr/local/tomcat/temp org.apache.catalina.startup.Bootstrap
tomcat   21217 21216 39 18:12 ?        00:00:22 jsvc.exec -java-home /usr/local/jdk1.8.0_60 -user tomcat -pidfile /usr/local/tomcat/logs/catalina-daemon.pid -wait 10 -outfile /usr/local/tomcat/logs/catalina-daemon.out -errfile &1 -classpath /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/commons-daemon.jar:/usr/local/tomcat/bin/tomcat-juli.jar -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Dcatalina.base=/usr/local/tomcat -Dcatalina.home=/usr/local/tomcat -Djava.io.tmpdir=/usr/local/tomcat/temp org.apache.catalina.startup.Bootstrap
root     21307 18138  0 18:13 pts/2    00:00:00 grep --color=auto jsvc

View service port

[root@VM_82_178_redhat ~]# netstat -lntup|grep jsvc
tcp        0      0 0.0.0.0:8009            0.0.0.0:*               LISTEN      21217/jsvc.exec     
tcp        0      0 0.0.0.0:8080            0.0.0.0:*               LISTEN      21217/jsvc.exec     
udp        0      0 0.0.0.0:33848           0.0.0.0:*                           21217/jsvc.exec     
udp        0      0 0.0.0.0:5353            0.0.0.0:*                           21217/jsvc.exec     
[root@VM_82_178_redhat ~]# ss -lntup|grep jsvc
udp    UNCONN     0      0         *:33848                 *:*                   users:(("jsvc",pid=21217,fd=192))
udp    UNCONN     0      0         *:5353                  *:*                   users:(("jsvc",pid=21217,fd=195))
tcp    LISTEN     0      100       *:8009                  *:*                   users:(("jsvc",pid=21217,fd=55))
tcp    LISTEN     0      100       *:8080                  *:*                   users:(("jsvc",pid=21217,fd=50))

Here tomcat starts successfully

9. The log of the console of the tomcat service

grep 'Jenkins initialization thread' /usr/local/tomcat/logs/catalina-daemon.out 

21-Apr-2018 17:57:30.599 INFO [Jenkins initialization thread] hudson.WebAppMain$3.run Jenkins is fully up and running
21-Apr-2018 18:12:53.998 WARNING [Jenkins initialization thread] hudson.util.PluginServletFilter.addFilter Filter instance is registered too early: jenkins.install.SetupWizard$1@26cb5d6
21-Apr-2018 18:12:54.004 WARNING [Jenkins initialization thread] hudson.util.PluginServletFilter.addFilter Filter instance is registered too early: hudson.security.HudsonPrivateSecurityRealm$5@25972a66
21-Apr-2018 18:12:54.878 INFO [Jenkins initialization thread] jenkins.install.SetupWizard.init 
21-Apr-2018 18:13:14.898 WARNING [Jenkins initialization thread] hudson.model.UpdateCenter.updateDefaultSite Upgrading Jenkins. Failed to update the default Update Site 'default'. Plugin upgrades may fail.
21-Apr-2018 18:13:14.989 INFO [Jenkins initialization thread] hudson.WebAppMain$3.run Jenkins is fully up and running
日志可以看到jenkins服务部署成功

At the same time, two hidden directories are generated under /home/tomcat/

[root@VM_82_178_redhat tomcat]# ls -al /home/tomcat/
total 16
drwxr-xr-x  4 tomcat tomcat 4096 Apr 21 18:12 .
drwxr-xr-x. 3 root   root   4096 Apr 21 17:40 ..
drwxr-xr-x  9 tomcat tomcat 4096 Apr 21 18:13 .jenkins
drwx------  2 tomcat tomcat 4096 Apr 21 18:12 .oracle_jre_usage

Deploy jenkins and use the common user tomcat to start the tomcat service

The .jenkins file stores important password files related to jenkins registration, etc.

[root@VM_82_178_redhat tomcat]# cat /home/tomcat/.jenkins/secrets/initialAdminPassword
e57476c34eca47869fbe5100900ade4a

10. Register the jenkins service

Deploy jenkins and use the common user tomcat to start the tomcat service
Deploy jenkins and use the common user tomcat to start the tomcat service
Deploy jenkins and use the common user tomcat to start the tomcat service
Deploy jenkins and use the common user tomcat to start the tomcat service
Deploy jenkins and use the common user tomcat to start the tomcat service

11. Let the tomcat service start automatically

ln -sv /usr/local/tomcat/bin/daemon.sh /etc/init.d/tomcat8

[root@VM_82_178_redhat ~]#ln -sv /usr/local/tomcat/bin/daemon.sh /etc/init.d/tomcat8
‘/etc/init.d/tomcat8’ -> ‘/usr/local/tomcat/bin/daemon.sh’
[root@VM_82_178_redhat ~]# ll /etc/init.d/tomcat8
lrwxrwxrwx 1 root root 31 Apr 21 19:19 /etc/init.d/tomcat8 -> /usr/local/tomcat/bin/daemon.sh
/etc/init.d/tomcat8 stop
/etc/init.d/tomcat8 start

[root@VM_82_178_redhat ~]# chkconfig --add tomcat8
[root@VM_82_178_redhat ~]# chkconfig tomcat8 on
[root@VM_82_178_redhat ~]# chkconfig --ist|grep tomcat8
--ist: unknown option
[root@VM_82_178_redhat ~]# chkconfig --list|grep tomcat8

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

tomcat8         0:off   1:off   2:on    3:on    4:on    5:on    6:off

Complete the introduction here

Tomcat service ordinary user start reference document:
https://www.cnblogs.com/allegro/p/5005352.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324671910&siteId=291194637