一、简介
Jenkins在devops的发展中起着很重要的作用,目前不管是Linux, MacOS, docker, kubernetes等主流平均均支持jenkins的使用。下面就Ubuntu 18.04 TLS系统安装和使用做简单演示:
参考Jenkins官方:
https://www.jenkins.io/doc/book/installing/linux/#debianubuntu
https://pkg.jenkins.io/debian-stable/
二、安装部署Jenkins
1.在程序包仓库中添加key
wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -
2.将jenkins程序包仓库地址添加到系统仓库配置文件
sudo sh -c 'echo deb https://pkg.jenkins.io/debian-stable binary/ > /etc/apt/sources.list.d/jenkins.list'
3.更新程序仓库索引
apt-get update
4.安装Jenkins
apt-get install jenkins
提示:
如果安装过程有报错:“jenkins : Depends: daemon but it is not installable”,可以添加社区维护的免费开源的“universe” 仓库地址加入系统仓库配置文件。
然后执行命令:
sudo add-apt-repository universe
5.安装过程介绍
在安装过程中,jenkins有如下几个动作:
- 将Jenkins作为守护进程运行,可通过/etc/init.d/jenkins查看详细信息;
- 自动创建Jenkins用户来运行Jenkins
- 管理控制台日志文件保存在/var/log/jenkins/jenkins.log中
- 用启动的配置参数自动填充到/etc/default/jenkins中并启动,如JENKINS_HOME
- Jenkins监听主机的8080端口,可在浏览器中用此端口进行访问和配置jenkins
- 如果想更换默认端口,可以在配置文件/etc/default/jenkins中进行更改。
三、安装Java环境
因为jenkins的运行依赖于java环境,所以要先安装java。java环境有多种实现方式,目前最常用的是openjdk。
1.查找目前可用的程序
apt search openjdk
2.选择其一并安装
apt install openjdk-11-jdk
3.检查是否安装成功
java -version
四、验证并配置jenkins
1.确认java安装成功
java -version
提示:
若java因jenkins依赖安装报错,可以先kill掉所有的jenkins进程,重新安装java, 然后再重启jenkins
systemctl restart jenkins
2.确认jenkins正常运行
# systemctl status jenkins
● jenkins.service - LSB: Start Jenkins at boot time
Loaded: loaded (/etc/init.d/jenkins; generated)
Active: active (exited) since Sun 2021-10-31 07:37:53 UTC; 5min ago
Docs: man:systemd-sysv-generator(8)
Process: 74034 ExecStop=/etc/init.d/jenkins stop (code=exited, status=0/SUCCESS)
Process: 74081 ExecStart=/etc/init.d/jenkins start (code=exited, status=0/SUCCESS)
Oct 31 07:37:52 ecs-64a3 jenkins[74081]: # Ec2: #
Oct 31 07:37:52 ecs-64a3 jenkins[74081]: # strict_id: false #
Oct 31 07:37:52 ecs-64a3 jenkins[74081]: **************************************************************************
Oct 31 07:37:52 ecs-64a3 jenkins[74081]: Disable the warnings above by:
Oct 31 07:37:52 ecs-64a3 jenkins[74081]: touch /var/lib/jenkins/.cloud-warnings.skip
Oct 31 07:37:52 ecs-64a3 jenkins[74081]: or
Oct 31 07:37:52 ecs-64a3 jenkins[74081]: touch /var/lib/cloud/instance/warnings/.skip
Oct 31 07:37:52 ecs-64a3 su[74138]: pam_unix(su:session): session closed for user jenkins
Oct 31 07:37:53 ecs-64a3 jenkins[74081]: ...done.
Oct 31 07:37:53 ecs-64a3 systemd[1]: Started LSB: Start Jenkins at boot time.
3.确认默认端口8080被主机监听
# netstat -tanlp |grep 8080
tcp6 0 0 :::8080 :::* LISTEN 74161/java
4.浏览器访问jenkins
domain:8080
评论前必须登录!
注册