jenkins迁移

Jenkins迁移

# 原Jenkins
# 拷贝旧Jenkins主目录的这几个文件 jobs users plugins config.xml
# 查看jenkins主目录
[root@old_jenkins ~]# cat /etc/sysconfig/jenkins
## Path:        Development/Jenkins
## Description: Jenkins Automation Server
## Type:        string
## Default:     "/var/lib/jenkins"		主目录路径
## ServiceRestart: jenkins
[root@old_jenkins ~]# cd /var/lib/jenkins
# 拷贝这几个主要文件 jobs plugins users config.xml
[root@old_jenkins jenkins]# tar czf users.tar users
[root@old_jenkins jenkins]# tar czf plugins.tar plugins
[root@old_jenkins jenkins]# tar czf jobs.tar jobs
[root@old_jenkins jenkins]# scp users.tar 172.168.10.16:/root/
[root@old_jenkins jenkins]# scp plugins.tar 172.168.10.16:/root/
[root@old_jenkins jenkins]# scp jobs.tar 172.168.10.16:/root/
[root@old_jenkins jenkins]# scp config.xml 172.168.10.16:/root/
[root@new_jenkins ~]#systemctl stop firewalld && systemctl disable firewalld && sed -ri s/SELINUX=.*$/SELINUX=disabled/g /etc/selinux/config && setenforce 0
[root@new_jenkins ~]# ssh-keygen
# 一直回车即可
# 安装依赖
[root@new_jenkins ~]# yum install -y wget git vim
[root@new_jenkins ~]# cd /etc/yum.repos.d
[root@new_jenkins ~]# wget http://pkg.jenkins.io/redhat/jenkins.repo
# 当出现报错需验证证书时,则执行以下命令后再次验证
# [root@new_jenkins ~]# yum install -y ca-certificates
[root@new_jenkins ~]# rpm --import https://pkg.jenkins.io/redhat/jenkins.io.key
# 安装jenkins
[root@new_jenkins ~]# yum install -y epel-release
[root@new_jenkins ~]# yum install -y jenkins
[root@new_jenkins ~]# mkdir /data/jenkins -p
[root@new_jenkins ~]# vim /etc/sysconfig/jenkins
# 修改jenkins的路径和用户
JENKINS_HOME="/data/jenkins"
JENKINS_USER="root"

[root@new_jenkins ~]# systemctl start jenkins
[root@new_jenkins ~]# cd /data/jenkins
[root@new_jenkins jenkins]# systemctl stop jenkins
# 备份文件
[root@new_jenkins jenkins]# tar czf plugins.bak.tar plugins
[root@new_jenkins jenkins]# tar czf jobs.bak.tar jobs
[root@new_jenkins jenkins]# tar czf users.bak.tar users
[root@new_jenkins jenkins]# mv config.xml{.,bak}
[root@new_jenkins jenkins]# rm -rf jobs users plugins
[root@new_jenkins jenkins]# cd
[root@new_jenkins ~]# tar xf plugins.tar
[root@new_jenkins ~]# tar xf jobs.tar
[root@new_jenkins ~]# tar xf users.tar
[root@new_jenkins ~]# mv plugins /data/jenkins/
[root@new_jenkins ~]# mv jobs /data/jenkins/
[root@new_jenkins ~]# mv users /data/jenkins/
[root@new_jenkins ~]# systemctl start jenkins && systemctl enable jenkins

jenkins 网址:http://172.168.10.16:8080

访问jenkins网址,点击系统管理 > 读取配置

jenkins迁移_第1张图片

在读取完jenkins配置后,因旧jenkins与新jenkins版本不一致需对插件进行升级

系统管理 > 插件管理 > 可更新 > 兼容的 > 下载待重启后安装 > 勾选安装完成后重启

jenkins迁移_第2张图片
jenkins迁移_第3张图片

# 安装jdk
[root@new_jenkins ~]# tar xf jdk1.8.0_131.tar.gz 
[root@new_jenkins ~]# mv jdk1.8.0_131 /data/java
[root@new_jenkins ~]# vim /etc/profile.d/java.sh
JAVA_HOME=/data/java
PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME PATH

[root@new_jenkins ~]# source /etc/profile.d/java.sh
[root@new_jenkins ~]# java -version
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)

# 安装maven
[root@new_jenkins ~]# cd /data/
[root@new_jenkins data]# wget https://mirrors.cnnic.cn/apache/maven/maven-3/3.8.3/binaries/apache-maven-3.8.3-bin.tar.gz
[root@new_jenkins data]# tar xf apache-maven-3.8.3-bin.tar.gz
[root@new_jenkins data]# vim /etc/profile.d/maven.sh
export MAVEN_HOME=/data/apache-maven-3.8.3
export PATH=${MAVEN_HOME}/bin:$PATH

[root@new_jenkins data]# source /etc/profile.d/maven.sh
[root@new_jenkins data]# mvn -version
Apache Maven 3.8.3 (ff8e977a158738155dc465c6a97ffaf31982d739)

# nodejs
[root@new_jenkins data]# mkdir nodejs
[root@new_jenkins data]# tar xf node-v10.14.0-linux-x64.tar.gz
[root@new_jenkins data]# ln -s /data/nodejs/node-v10.14.0-linux-x64/bin/node  /usr/bin/node && ln -s /data/nodejs/node-v10.14.0-linux-x64/bin/npm /usr/bin/npm && ln -s /data/nodejs/node-v10.14.0-linux-x64/bin/npx /usr/bin/npx && chmod +x /data/nodejs/node-v10.14.0-linux-x64/bin/* && npm install -g cnpm --registry=https://registry.npm.taobao.org && ln -s /data/nodejs/node-v10.14.0-linux-x64/bin/cnpm /usr/bin/cnpm && npm install -g pm2 && ln -s /data/nodejs/node-v10.14.0-linux-x64/bin/pm2 /usr/bin/pm2 && ln -s /data/nodejs/node-v10.14.0-linux-x64/bin/pm2-dev /usr/bin/pm2-dev && ln -s /data/nodejs/node-v10.14.0-linux-x64/bin/pm2-docker /usr/bin/pm2-docker && ln -s /data/nodejs/node-v10.14.0-linux-x64/bin/pm2-runtime /usr/bin/pm2-runtime
# 构建后jar包保存路径
[root@new_jenkins data]# mkdir appjar

# pom中心(或者是开发给的pom文件)
[root@new_jenkins data]# mkdir nexus
[root@new_jenkins data]# cd nexus
[root@new_jenkins nexus]# tar xf nexus-2.14.1-01-bundle.tar.gz
[root@neW_jenkins nexus]# ./nexus-2.14.1-01/bin/neuxs install
[root@new_jenkins nexus]# vim /etc/profile
# 在末尾添加以下内容
export RUN_AS_USER=root

[root@new_jenkins nexus]# source /etc/profile
[root@new_jenkins nexus]# vim /data/apache-maven-3.8.3/conf/settings.xml
# 修改以下内容
 <servers>
    <server>
      <id>nexus</id>
      <username>admin</username>
      <password>admin123</password>
    </server>
  </servers>
  <mirrors>
    <mirror>
        <id>GNWPNexus</id>
        <mirrorOf>central</mirrorOf>
        <name>Nexus Public Mirror</name>
        <url>http://172.168.10.16:8081/nexus/content/groups/public</url>
    </mirror>
    <mirror>
        <id>GNWPNexus</id>
        <mirrorOf>thirdparty</mirrorOf>
        <url>http://172.168.10.16:8081/nexus/content/groups/thirdparty</url>
    </mirror>
  </mirrors>
[root@neW_jenkins nexus]# ./nexus-2.14.1-01/bin/nexus start

neuxs web地址:http://172.168.10.16:8081

点击log in登陆(默认账号密码admin admin123)

在这里插入图片描述

如无法登陆解决方法如下

[root@new_jenkins ~]# cd /data/nexus/sonatype-work/nexus/conf
[root@new_jenkins conf]# rm -rf security*
[root@new_jenkins conf]# cd /data/nexus/nexus-2.14.1-01/bin/
[root@new_jenkins bin]# ./nexus restart 

配置jenkins全局工具

系统管理 > 全局工具配置

jenkins迁移_第4张图片

配置系统配置

系统管理 > 系统配置

配置gitlab账号

jenkins迁移_第5张图片

jenkins迁移_第6张图片

配置阿里云oss

jenkins迁移_第7张图片

配置ssh

jenkins迁移_第8张图片
jenkins迁移_第9张图片

构建时如出现此错误

[ERROR] Failed to execute goal on project gnw-pay-api: Could not resolve dependencies for project cn.gnw:gnw-pay-api:jar:0.0.1-SNAPSHOT: gnw.pub:bcprov-jdk:jar:14-128 was not found in http://172.168.10.16:8081/nexus/content/groups/public during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of GNWPNexus has elapsed or updates are forced -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
[ERROR] 
[ERROR] After correcting the problems, you can resume the build with the command
[ERROR]   mvn <goals> -rf :gnw-pay-api
# 解决方法如下
在旧的nexus上找到该包

jenkins迁移_第10张图片

然后下载该包,并上传到新的nexus服务器上,根据信息执行以下命令

[root@new_jenkins ~]# mvn install:install-file -DgroupId=gnw.pub -DartifactId=bcprov-jdk -Dversion=14-128 -Dpackaging=jar -Dfile=bcprov-jdk-14-128.jar
# 下载jar包web界面
[root@neW_jenkins ~]# tar xf nginx-1.8.1.tar.gz
[root@neW_jenkins data]# mv nginx-1.8.1 /data/nginx
# 安装编译环境
[root@neW_jenkins data]# yum install -y epel-release
[root@neW_jenkins data]# yum install -y gcc pcre-devel zlib-devel openssl openssl-devel unzip
[root@neW_jenkins data]# cd /data/nginx
# 添加nginx插件
[root@neW_jenkins data]# ./configure --with-http_ssl_module --with-http_stub_status_module --with-http_gzip_static_module --with-pcre
# 编译安装
[root@neW_jenkins data]# make && maek install
[root@neW_jenkins data]# cd /usr/local/nginx/conf
[root@neW_jenkins data]# vim nginx.conf
http {
    include       mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    sendfile        on;
    keepalive_timeout  65;
    server {
        listen       80;
        server_name  localhost;
        location / {
            root   html;
            index  index.html index.htm;
        }
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
        include /usr/local/nginx/conf/conf.d/*.conf;  # 添加此行
}
    

[root@neW_jenkins data]# mkdir conf.d
[root@neW_jenkins data]# vim conf.d/appjar.html
server {
    listen 8088;
    server_name 172.168.10.16;
    set $MAGE_ROOT /data/appjar;
    autoindex on;
    autoindex_exact_size off;
    autoindex_localtime on;
    error_log  /data/logs/nginx/jar_error.log;
    access_log  /data/logs/nginx/jar_access.log  main;
    location / {
    root $MAGE_ROOT;
    index default.php index.php index.html index.htm;
    }
    error_page 404 /error.html;
    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
    root html;
    }
    location ~ /\.ht {
    deny all;
    }
}
[root@neW_jenkins data]# mkdir /data/logs/nginx -p
[root@neW_jenkins data]# systemctl start nginx && systemctl enable nginx

你可能感兴趣的:(jenkins,运维,linux)