jenkins自动化部署搭建

jenkins安装

基于centos

下载及安装

wget https://pkg.jenkins.io/redhat-stable/jenkins-2.204.5-1.1.noarch.rpm
rpm -ivh jenkins-2.204.5-1.1.noarch.rpm

修改配置

jdk环境变量配置

# 查阅jdk环境变量
echo $JAVA_HOME
vi /etc/init.d/jenkins

修改启动端口(默认8080)

# 改为8700(或其他)
vi /etc/sysconfig/jenkins

修改源地址等相关配置

hudson.model.UpdateCenter.xml & default.json文件
二者在/var/lib/jenkins/、``/var/lib/jenkins/updates/`目录下,如果没有,则需要新启动一次后方可生成,然后关闭进行配置修改

1.将源修改为国内,这样插件下载才会加速

<?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>

2.替换default.json中的地址

find / -name "default.json"

sed -i 's/http:\/\/updates.jenkins-ci.org\/download/https:\/\/mirrors.tuna.tsinghua.edu.cn\/jenkins/g' /var/lib/jenkins/updates/default.json && sed -i 's/http:\/\/www.google.com/https:\/\/www.baidu.com/g' /var/lib/jenkins/updates/default.json

3.修改nginx配置

即使修改了源,有时候下载依然满,是因为源内的地址仍然指向了国外

  1. nginx.conf
location /download/plugins
{
    proxy_next_upstream http_502 http_504 error timeout invalid_header;
    proxy_set_header Host mirrors.tuna.tsinghua.edu.cn;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    rewrite /download/plugins(.*) /jenkins/plugins/$1 break;
    proxy_pass https://mirrors.tuna.tsinghua.edu.cn;
}

2./etc/hosts

127.0.0.1 updates.jenkins-ci.org

3.重启nginx

/usr/local/nginx/sbin/nginx -s reload

登录

  1. 获取密码
vi /var/lib/jenkins/secrets/initialAdminPassword
  1. 启动登录
# 重启
systemctl restart jenkins
# 启动
systemctl start jenkins
# 停止
systemctl stop jenkins

卸载

  1. rpm卸载
rpm -e jenkins
  1. 检查是否卸载成功
rpm -ql jenkins 
  1. 彻底删除残留文件:
find / -iname jenkins | xargs -n 1000 rm -rf

你可能感兴趣的:(工程化专题,jenkins)