新版本jenkins安装后竟然有两份启动文件, 一份是 /etc/init.d/jenkins
, 另一份是/usr/lib/systemd/system/jenkins.service
, 使用systemd启动jenkins的文件可以自定义下,其实这个systemd文件可以直接用来纯war包安装,就省去了rpm包的麻烦,也不用安装tomcat
执行systemctl edit jenkins.service
,写入如下内容
[Unit]
Description=Jenkins Server
After=network.target network.service rsyslog.service
Documentation=https://www.jenkins.io/doc
[Service]
Type=simple
EnvironmentFile=/etc/sysconfig/jenkins
WorkingDirectory=/usr/lib/jenkins
ExecStart=/opt/java/jdk11.0.17_8/bin/java \
-Duser.country=CN \
-Duser.timezone=Asia/Shanghai \
-Dfile.encoding=UTF-8 \
-Djava.awt.headless=true \
-DJENKINS_HOME=${JENKINS_HOME} \
-jar jenkins.war \
--logfile=/var/log/jenkins/jenkins.log \
--webroot=/var/cache/jenkins/war \
--httpPort=${JENKINS_PORT} \
--httpListenAddress=${JENKINS_LISTEN_ADDRESS} \
--debug=${JENKINS_DEBUG_LEVEL} \
--handlerCountMax=${JENKINS_HANDLER_MAX} \
--handlerCountMaxIdle=${JENKINS_HANDLER_IDLE}
Restart=on-failure
LimitNOFILE=65535
User=jenkins
Group=jenkins
StandardOutput=null
StandardError=null
[Install]
WantedBy=multi-user.target
值得需要注意的是,我们需要改改/etc/sysconfig/jenkins
, 只留下咱们能用得着的
JENKINS_HOME="/data/jenkins"
JENKINS_PORT="8080"
JENKINS_LISTEN_ADDRESS="127.0.0.1"
JENKINS_DEBUG_LEVEL="5"
JENKINS_HANDLER_MAX="100"
JENKINS_HANDLER_IDLE="20"
# PATH 是我自主加的,避免jenkins找不到java/node/maven/gradle等的执行文件
PATH="/opt/java/jdk1.8.0_202/bin:/opt/maven/apache-maven-3.8.6/bin:/opt/gradle/gradle-7.5.1/bin:/opt/node/node-v16.17.0/bin:/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin"
最后我们直接删除/etc/init.d/jenkins
就行了,systemctl enable --now jenkins.service
即可使用systemd启动jenkins了