部署jenkins,采用普通用户tomcat来启动tomcat服务
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了部署jenkins,采用普通用户tomcat来启动tomcat服务相关的知识,希望对你有一定的参考价值。
安装jdk+tomcat,部署jenkins,采用普通用户tomcat来启动tomcat服务
1.环境说明
CentOS Linux release 7.3.1611 (Core)
jdk1.8.0_60
apache-tomcat-8.5.23
已经安装好
2.编译安装服务守护程序
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
如果编译过程中出现如下错误提示,说明未设置JAVA_HOME变量:
Java compilation tools
checking for JDK location... configure: error: Java Home not defined. Rerun with --with-java=... parameter
可以通过命令行参数指定JDK位置./configure --with-java=/usr/local/jdk1.8.0_60
配置成功后,开始编译。
make
执行make后会生成一个jsvc的文件,将其复制到tomcat的bin目录cp jsvc /usr/local/apache-tomcat-8.5.23/bin/
3. 建立一个用来运行Tomcat的用户
useradd tomcat -s /usr/sbin/nologin
4. 修改启动脚本文件
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. 修改相关目录和文件权限
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.配置环境变量
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.放置jenkins.war程序到站点目录
[email protected]_82_178_redhat tasks]# cd /usr/local/tomcat/webapps/
[[email protected]_82_178_redhat webapps]# ls
jenkins.war ROOT
8.启动tomcat服务
启动前先检查tomcat配置文件 server.xml基本语法
[[email protected]_82_178_redhat bin]# which configtest.sh
/usr/local/tomcat/bin/configtest.sh
catalina.sh configtest
查看tomcat和jdk的版本号
catalina.sh version
daemon.sh version
[[email protected]_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
启动tomcat
daemon.sh start
daemon.sh stop
查看启动进程
[[email protected]_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
查看服务端口
[[email protected]_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
[[email protected]_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))
到此处tomcat启动成功
9.tomcat服务的控制台的日志
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: [email protected]
21-Apr-2018 18:12:54.004 WARNING [Jenkins initialization thread] hudson.util.PluginServletFilter.addFilter Filter instance is registered too early: [email protected]
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服务部署成功
同时在/home/tomcat/ 下面生成两个隐藏目录
[[email protected]_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
.jenkins文件下存放着jenkins注册时的相关的重要的密码文件等
[[email protected]_82_178_redhat tomcat]# cat /home/tomcat/.jenkins/secrets/initialAdminPassword
e57476c34eca47869fbe5100900ade4a
10.注册jenkins服务
11.让tomcat服务开机自启动
ln -sv /usr/local/tomcat/bin/daemon.sh /etc/init.d/tomcat8
[[email protected]_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’
[[email protected]_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
[[email protected]_82_178_redhat ~]# chkconfig --add tomcat8
[[email protected]_82_178_redhat ~]# chkconfig tomcat8 on
[[email protected]_82_178_redhat ~]# chkconfig --ist|grep tomcat8
--ist: unknown option
[[email protected]_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
到此处介绍完成
tomcat服务普通用户启动参考文档:
https://www.cnblogs.com/allegro/p/5005352.html
以上是关于部署jenkins,采用普通用户tomcat来启动tomcat服务的主要内容,如果未能解决你的问题,请参考以下文章
部署在tomcat下面的jenkins启动了多个实例,界面访问报错
用于启动 Tomcat 和 Jenkins 的非特权用户的 iOS 默认钥匙串