- 1、安装java环境
- 2、安装jenkins
- 3、启动jenkins
- 如果启动正常可以看到jenkins服务是处于活动状态的
- ubuntu@VM-9-8-ubuntu:~$ sudo systemctl status jenkins
- ● jenkins.service - LSB: Start Jenkins at boot time
- Loaded: loaded (/etc/init.d/jenkins; generated)
- Active: active (exited) since Fri 2021-04-30 12:58:31 CST; 28min ago
- Docs: man:systemd-sysv-generator(8)
1、安装java环境
sudo apt-get install openjdk-8-jdk
java -version 命令检查java环境是否正确安装,如下即安装成功。
ubuntu@VM-0-3-ubuntu:~$ java -version
openjdk version "1.8.0_292"
OpenJDK Runtime Environment (build 1.8.0_292-8u292-b10-0ubuntu1~18.04-b10)
OpenJDK 64-Bit Server VM (build 25.292-b10, mixed mode)
2、安装jenkins
包含在默认Ubuntu软件包中的Jenkins版本往往落后于项目本身的最新版本。 为了利用最新的修复和功能,我们将使用项目维护的软件包来安装Jenkins。
首先,我们将存储库密钥添加到系统:
wget -q -O - https://pkg.jenkins.io/debian/jenkins-ci.org.key | sudo apt-key add -
添加密钥后,系统将返回OK 。 接下来,我们将Debian包存储库地址附加到服务器的sources.list :
echo deb http://pkg.jenkins.io/debian-stable binary/ | sudo tee /etc/apt/sources.list.d/jenkins.list
运行update ,以便apt-get将使用新的存储库
sudo apt-get update
最后,我们将安装Jenkins及其依赖项
sudo apt-get install jenkins
3、启动jenkins
启动jenkins
sudo systemctl start jenkins
查看jenkins是否启动 ```bash sudo systemctl status jenkins
如果启动正常可以看到jenkins服务是处于活动状态的
ubuntu@VM-9-8-ubuntu:~$ sudo systemctl status jenkins
● jenkins.service - LSB: Start Jenkins at boot time
Loaded: loaded (/etc/init.d/jenkins; generated)
Active: active (exited) since Fri 2021-04-30 12:58:31 CST; 28min ago
Docs: man:systemd-sysv-generator(8)
<a name="SdMOV"></a>
####
<a name="Rb2VC"></a>
#### 4、修改jenkins端口
1. 修改/etc/init.d/jenkins文件下的do_start函数的check_tcp_port命令,端口号从8080换成8085
![image.png](https://cdn.nlark.com/yuque/0/2021/png/1170640/1619760735957-65f63bbc-ae42-4854-a124-9e684fea196d.png#clientId=ue8d1edf8-d319-4&from=paste&height=302&id=u9ceac58c&margin=%5Bobject%20Object%5D&name=image.png&originHeight=604&originWidth=1924&originalType=binary&size=242764&status=done&style=none&taskId=ue90dfc8a-4772-4cd6-a596-fbcf60877d3&width=962)
2. 修改/etc/default/jenkins文件,将端口8080改成8085
![image.png](https://cdn.nlark.com/yuque/0/2021/png/1170640/1619760771315-112e39af-93be-4101-a269-f3b2df52fd5c.png#clientId=ue8d1edf8-d319-4&from=paste&height=138&id=u6635ee67&margin=%5Bobject%20Object%5D&name=image.png&originHeight=276&originWidth=1394&originalType=binary&size=68859&status=done&style=none&taskId=u9fc5bf20-da1b-4f5c-955f-81fd4e8add1&width=697)
3. 重启jenkins
```bash
sudo systemctl restart jenkins
5、外网访问jenkins
登陆云服务设置安全组规则
比如我的腾讯云服务器ip是192.168.1.111,jenkins端口号为8085,那我可以通过访问 http://1192.168.1.111:8085登陆到jenkins。
tips:搭建环境问题排查记录
telnet ip port:查看是否可以成功访问到地址
ps -ef | grep jenkins : 查看jenkins进程
netstat -a | grep 8085:查看jenkins端口是否有服务占用