CentOS7 deploys cicd service in Jenkins

WBOY
Release: 2024-02-20 08:30:03
forward
1296 people have browsed it

项目地址

https://www.jenkins.io/zh/

CentOS7 deploys cicd service in Jenkins

设置主机名:

hostnamectl set-hostname jenkins
Copy after login

不带时间的个性主机名

echo "PS1='[e[37;1m][[e[36;40m][e[32;40m]u[e[33;40m]@[e[31;40m]h [e[34;40m]w[e[37;1m]]\$[e[m]'" >>.bashrc
Copy after login

关闭CentOS7自带的防火墙服务

systemctl disable firewalld && systemctl stop firewalld
Copy after login

关闭SeLsinux

sed -i 's/enforcing/disabled/' /etc/selinux/config && setenforce 0
Copy after login

安装Git

yum install git -y
Copy after login

安装JDK

yum install -y java-1.8.0
yum install -y java-1.8.0-openjdk*
Copy after login

添加Jenkins源

最新版:
wget -O /etc/yum.repos.d/jenkins.repo http://pkg.jenkins.io/redhat/jenkins.repo

稳定版本:
wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
Copy after login

导入Jenkins密钥

最新版:
rpm --import http://pkg.jenkins.io/redhat/jenkins.io.key

稳定版本
rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
Copy after login

ps:如果在以前从Jenkins导入过密钥,那么“rpm –import”将失败,因为在服务器上已经有了一个密钥。所以,这个错误信息可以忽略

安装Jenkins

### 安装当时最新稳定版
yum install -y jenkins

### rpm包安装指定版本,具体当前稳定版是哪个?https://www.jenkins.io/zh/download/
# redhat老版本
https://mirror.tuna.tsinghua.edu.cn/jenkins/redhat/
# redhat稳定版
https://mirror.tuna.tsinghua.edu.cn/jenkins/redhat-stable/

# 下载稳定版
wget https://mirror.tuna.tsinghua.edu.cn/jenkins/redhat-stable/jenkins-2.303.2-1.1.noarch.rpm

# 需要的依赖软件
yum install daemonize -y

# 开始安装
[root@jenkins ~]#rpm -ivh jenkins-2.303.2-1.1.noarch.rpm 
Preparing...################################# [100%]
Updating / installing...
 1:jenkins-2.303.2-1.1################################# [100%]
Copy after login

可选-挂载磁盘-设置Jenkins目录

格式化磁盘
mkfs.ext4 /dev/vdb 
创建data目录
mkdir /data/
挂载目录
mount /dev/vdb /data
设置开机自动挂载
echo "/dev/vdb /data ext4 defaults 0 0" >> /etc/fstab
创建Jenkins目录
mkdir /data/jenkins
设置Jenkins目录所属组所属用户
chown -R jenkins.jenkins /data/jenkins/
Copy after login

修改Jenkins的用户和端口号

ps:此处是因为Jenkins的端口号默认是8080,与tomcat的默认端口冲突
所以可以根据自己的条件判断是否需要修改,此处我是已经修改为9999端口
ps:此处是因为Jenkins的用户默认是jenkins,我们可以改为root用户来管理jenkins

vim /etc/sysconfig/jenkins

# 配置Jenkins的运行用户,这里不是登录用户
JENKINS_USER="root"

# 配置Jenkins的端口
JENKINS_PORT="8080"

# 配置Jenkins的目录
JENKINS_HOME="/data/jenkins"

# 配置资源限制
JENKINS_JAVA_OPTIONS="-Djava.awt.headless=true -Xms256m -Xmx512m -XX:MaxNewSize=256m"
Copy after login

设置开机自启

systemctl start jenkins && /sbin/chkconfig jenkins on && systemctl status jenkins
Copy after login

获取Jenkins密码

cat /var/lib/jenkins/secrets/initialAdminPassword
Copy after login

网页访问

打开xxx.xxx.xxx.xxx:8080
Copy after login

选择需要安装的插件

选择默认推荐即可,会安装通用的社区插件,剩下的可以在使用的时候再进行安装。
Copy after login

The above is the detailed content of CentOS7 deploys cicd service in Jenkins. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:mryunwei.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template