centos7安装jenkins
1、先安java
先下载jdk1.8.tar包安装
tar -zxvf jdk1.8.tar.gz -C /usr/local/java
vi /etc/profile
source /etc/profile
测试jdk安装情况
运行java、javac、java -version
2、安装tomcat
tar -zxvf apache-tomcat-9.0.54.tar.gz -C /usr/local/tomcat
vi /etc/profile
添加入CATALINA_HOME=/usr/local/tomcat/apache-tomcat-9.0.54
source /etc/profile
cd /usr/local/tomcat/apache-tomcat-9.0.54
、启动tomcat
./startup.sh
3、tomcat 注册为 systemctl
1、catalina.sh文件,在catlinabase行下添加pid配置。
2、tomcat.service放在/usr/lib/systemd/system下。
------catalina.sh内容添加CATALINA_PID="$CATALINA_BASE/tomcat.pid"(注意上下位置):
Copy CATALINA_BASE from CATALINA_HOME if not already set
[ -z "\(CATALINA_BASE" ] && CATALINA_BASE="\)CATALINA_HOME"
只添加下面这句,上下为catalina.sh已有的,用来确定位置
CATALINA_PID="$CATALINA_BASE/tomcat9.pid"
Ensure that any user defined CLASSPATH variables are not used on startup,
but allow them to be specified in setenv.sh, in rare case when it is needed.
CLASSPATH=
-------tomcat.service文件示例:
[Unit]
Description=tomcat9
After=syslog.target
[Service]
Type=forking
Environment="JAVA_HOME=/usr/local/tools/jdk1.8.0_161"
ExecStart=/opt/apache-tomcat-9.0.26/bin/startup.sh
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
User=root
Group=root
[Install]
WantedBy=multi-user.target
-------tomcat.service文件配置注意
After为在哪个服务后面启动。如果需要mysql数据库,tomcat可配置在mysql后启动(After=mariadb.service)。
Environment="JAVA_HOME=/usr/local/tools/jdk1.8.0_161"必须配置,etc/profile中的配置在此处不起作用。
ExecStart为启动地址。
-------systemctl命令
--修改service文件后,需刷新
systemctl daemon-reload
--关闭和打开
systemctl stop tomcat.service
systemctl start tomcat.service
--是否开机自启
systemctl disable tomcat.service
systemctl enable tomcat.service
4、发布jenkins
jenkins.war包上传到tomcat 下 的webapps 目录 ,tomcat 9会自动发布jenkins tomcat9 具有热发布功能
查看jenkins密码