jenkins
1. 部署Jenkins
jenkins 部署与使用
https://jenkins.io/zh/download/ #官方下载地址
https://mirrors.tuna.tsinghua.edu.cn/jenkins/debian-stable/ #ubuntu安装包清华源下载地,我们选择国内源吧 它快。。。。
2. 准备JDK环境
#准备JDK
root@ubuntu1804:~# cd /usr/local/src/
root@ubuntu1804:/usr/local/src# ls
jdk-8u241-linux-x64.tar.gz
root@ubuntu1804:/usr/local/src# pwd
/usr/local/src
# tar xf jdk-8u241-linux-x64.tar.gz
# ln -sv /usr/local/src/jdk1.8.0_241 /usr/local/jdk
'/usr/local/jdk' -> '/usr/local/src/jdk1.8.0_241'
#准备JDK环境
# vim /etc/profile
export JAVA_HOME=/usr/local/jdk
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
#使之生效
source /etc/profile
#验证
root@ubuntu1804:/usr/local/src# java -version
java version "1.8.0_241"
Java(TM) SE Runtime Environment (build 1.8.0_241-b07)
Java HotSpot(TM) 64-Bit Server VM (build 25.241-b07, mixed mode)
3. 通过deb包安装Jenkins
#apt install daemon
root@ubuntu1804:~# dpkg -i jenkins_2.204.5_all.deb
(Reading database ... 71521 files and directories currently installed.)
Preparing to unpack jenkins_2.204.5_all.deb ...
Unpacking jenkins (2.204.5) over (2.204.5) ...
Setting up jenkins (2.204.5) ...
Job for jenkins.service failed because the control process exited with error code.
See "systemctl status jenkins.service" and "journalctl -xe" for details.
invoke-rc.d: initscript jenkins, action "start" failed.
● jenkins.service - LSB: Start Jenkins at boot time
Loaded: loaded (/etc/init.d/jenkins; generated)
Active: failed (Result: exit-code) since Tue 2020-03-10 16:45:54 CST; 7ms ago
Docs: man:systemd-sysv-generator(8)
Process: 16805 ExecStart=/etc/init.d/jenkins start (code=exited, status=1/FAILURE)
Mar 10 16:45:54 ubuntu1804 systemd[1]: Starting LSB: Start Jenkins at boot time...
Mar 10 16:45:54 ubuntu1804 jenkins[16805]: ERROR: No Java executable found in current PATH: /bin:/usr/bin:/sbin:/usr/sbin
Mar 10 16:45:54 ubuntu1804 jenkins[16805]: If you actually have java installed on the system make sure the executable is in the aforementioned path and that 'type -p java' returns the java executable path
Mar 10 16:45:54 ubuntu1804 systemd[1]: jenkins.service: Control process exited, code=exited status=1
Mar 10 16:45:54 ubuntu1804 systemd[1]: jenkins.service: Failed with result 'exit-code'.
Mar 10 16:45:54 ubuntu1804 systemd[1]: Failed to start LSB: Start Jenkins at boot time.
dpkg: error processing package jenkins (--install):
installed jenkins package post-installation script subprocess returned error exit status 1
Processing triggers for ureadahead (0.100.0-21) ...
Processing triggers for systemd (237-3ubuntu10.24) ...
Errors were encountered while processing:
jenkins #报错
# 解决报错
# ln -sv /usr/local/jdk/bin/java /usr/bin/
#再次执行dpkg -i jenkins_2.204.5_all.deb 即可
4. 启动并验证jenkins
# systemctl start jenkins
# systemctl enable jenkins
root@ubuntu1804:~# ps -ef |grep jenkins
jenkins 17009 1 0 16:46 ? 00:00:00 /lib/systemd/systemd --user
jenkins 17010 17009 0 16:46 ? 00:00:00 (sd-pam)
jenkins 17024 1 0 16:46 ? 00:00:00 /usr/bin/daemon --name=jenkins --inherit --env=JENKINS_HOME=/var/lib/jenkins --output=/var/log/jenkins/jenkins.log --pidfile=/var/run/jenkins/jenkins.pid -- /usr/bin/java -Djava.awt.headless=true -jar /usr/share/jenkins/jenkins.war --webroot=/var/cache/jenkins/war --httpPort=8080
jenkins 17026 17024 43 16:46 ? 00:00:17 /usr/bin/java -Djava.awt.headless=true -jar /usr/share/jenkins/jenkins.war --webroot=/var/cache/jenkins/war --httpPort=8080
root 17171 2075 0 16:47 pts/0 00:00:00 grep --color=auto jenkins
root@ubuntu1804:~# lsof -i:8080
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 17026 jenkins 156u IPv6 53215 0t0 TCP *:http-alt (LISTEN)
5. jenkins配置文件
root@ubuntu1804:~# vim /etc/default/jenkins
root@ubuntu1804:~# grep "^[a-Z]" /etc/default/jenkins
NAME=jenkins
JAVA_ARGS="-Djava.awt.headless=true"
PIDFILE=/var/run/$NAME/$NAME.pid
JENKINS_USER=$NAME # $NAME 影响大 配置文件中$NAME
JENKINS_GROUP=$NAME # 想要更改 改具体用户
JENKINS_WAR=/usr/share/$NAME/$NAME.war
JENKINS_HOME=/var/lib/$NAME
RUN_STANDALONE=true
JENKINS_LOG=/var/log/$NAME/$NAME.log
JENKINS_ENABLE_ACCESS_LOG="no"
MAXOPENFILES=8192
HTTP_PORT=8080
PREFIX=/$NAME
JENKINS_ARGS="--webroot=/var/cache/$NAME/war --httpPort=$HTTP_PORT"
6.访问web界面
systemctl start jenkins
systemctl enable jenkins
ip:8080
7. 解锁并下一步
# cat /var/lib/jenkins/secrets/initialAdminPassword
8. jenkins离线问题解决
-
如果显示jenkins已离线,将以下文件中的更新检查地址改成国内清华大学地址,然后重启jenkins即可
# cat /var/lib/jenkins/hudson.model.UpdateCenter.xml <?xml version='1.1' encoding='UTF-8'?> <sites> <site> <id>default</id> <url>https://mirrors.tuna.tsinghua.edu.cn/jenkins/updates/update-center.json</url> #此处更换为清华源地址 </site> </sites>
systemctl restart jenkins
-
修改完如果还是离线
# vim /var/lib/jenkins/updates/default.json
将图下的goole改为www.baidu.com即可,更改完重启服务
我的习惯是出现这种情况 更改完,安装完插件再将上述的baidu改回goole