Jenkins实例安装使用以及流水线构建

Jenkins实例安装使用以及流水线构建

首页角色扮演D4DJ Groovy Mix更新时间:2024-05-09

###jenkins


- Jenkins 主机部署
- 主机设置固定ip 编辑位置 vim /etc/sysconfig/network-scripts/ifcfg-ens33
```
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=1a82ae28-b1d4-4618-8a37-5947b2878637
DEVICE=ens33
ONBOOT=yes
IPADDR=192.168.160.200
GATEWAY=192.168.160.2
PREFIX=24
DNS1=192.168.160.2
```
- 更新yum yum -y update
- 安装特定版本docker
- 安装需要的软件包, yum-util 提供yum-config-manager功能,另外两个是devicemapper驱动依赖的 yum install -y yum-utils device-mapper-persistent-data lvm2
- 设置yum源 yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
- 安装docker yum install -y docker-ce-18.06.1.ce-3.el7
- 启动并加入开机启动 systemctl enable docker && systemctl start docker
- 修改 docker 的daemon.json /etc/docker/daemon.json
``` daemon.json
{
"registry-mirrors": ["https://jxveu101.mirror.aliyuncs.com"], #切换ali镜像加速
"exec-opts": ["native.cgroupdriver=systemd"], #使用kubeadm安装 k8s集群 需要配置该项
"insecure-registries":["192.168.160.200","192.168.160.181","192.168.160.182","192.168.160.183"] #配置harbor仓库授权访问

}

```
- 重启docker sudo systemctl daemon-reload && systemctl restart docker
### 安装harbor仓库 略 [参看-Harbor仓库部署.md]
### 安装 gitlab
- 创建文件目录
```
mkdir -p /usr/local/java/docker/gitlab/etc
mkdir -p /usr/local/java/docker/gitlab/log
mkdir -p /usr/local/java/docker/gitlab/data
```
- docker 运行指令
```
docker run \
--detach \
--publish 8443:443 \
--publish 8090:80 \
--name gitlab \
--restart unless-stopped \
-v /usr/local/java/docker/gitlab/etc:/etc/gitlab \
-v /usr/local/java/docker/gitlab/log:/var/log/gitlab \
-v /usr/local/java/docker/gitlab/data:/var/opt/gitlab \
beginor/gitlab-ce:11.0.1-ce.0
```
- 修改 /root/docker/gitlab/etc 下 gitlab.rb
第13行 external_url 'http://192.168.160.200'
- git配置参数:
- git config --global user.name "root"
- git config --global --replace-all user.email "cglcoder@sina.com"
- git clone http://192.168.160.200:8090/aopioc/eureka-server.git
- git add .
- git commit -m "init"
- git push -u origin master
### 安装jenkins
- 安装容器化 jenkins
``` shell
docker run -u root --rm -d -p 8080:8080 -p 50000:50000 -v /usr/local/java/docker/jenkins:/var/jenkins_home -v /var/run/docker.sock:/var/run/docker.sock jenkinsci/blueocean
```
### 安装 rancher
- 安装容器化mysql
- 拉取镜像 docker pull mysql:5.7
- docker run -d -p 3306:3306 --name myMysql -e MYSQL_ROOT_PASSWORD=root mysql:5.7
- docker cp myMysql:/etc/mysql /usr/local/java/docker/mysql/mysqletc
- docker stop myMysql
- docker rm myMysql
- docker run -d --name mysql5.7 -p 33306:3306 --restart always --privileged=true -v /usr/local/java/docker/mysql/mysqletc/mysql:/etc/mysql -v /usr/local/java/docker/mysql/mysqletc/data:/var/lib/mysql -e MYSQL_USER="admin" -e MYSQL_PASSWORD="admin" -e MYSQL_ROOT_PASSWORD="root" mysql:5.7
- docker logs -f mysql5.7
```
--restart always -> 开机启动
--privileged=true -> 提升容器内权限
-v /root/docker/mysqletc/mysql:/etc/mysql -> 映射配置文件
-v /root/docker/mysqletc/data:/var/lib/mysql -> 映射数据目录
-e MYSQL_USER="summit" -> 添加用户summit
-e MYSQL_PASSWORD="summit" -> 设置summit用户的密码为summit
-e MYSQL_ROOT_PASSWORD="root" -> 设置root的密码为root
```
- 安装rancher实例 参见[3.Rancher实例安装使用.md]
### 整合软件 使用流水线
- docker 镜像 启用
- 访问地址 IP:8080
- 登录密码在 /usr/local/java/docker/jenkins/secrets/initialAdminPassword 文件中
- 安装插件
- 流水线 脚本
```Jenkinsfile
#!groovy
node("master"){
//下载代码
stage("GetCode"){
ws("${workspace}"){
checkout([$class: 'GitSCM', branches: [[name: '*/master']],
doGenerateSubmoduleConfigurations: false, extensions: [],
submoduleCfg: [], userRemoteConfigs: [[credentialsId: 'gitlab-id',
url: 'http://192.168.160.200:8090/aopioc/eureka-server.git']]])
}
}

//打包编译
stage("Build"){
ws("${workspace}"){
echo "${workspace}"
sh'''
/var/jenkins_home/env/apache-maven-3.6.1/bin/mvn clean install -DskipTests
'''
}

}
//构建镜像
stage("Build"){
ws("${workspace}"){
echo "${workspace}"
sh'''
cp ./Dockerfile ./target/
cd ./target
docker build -t eureka-server:uat .
docker tag eureka-server:uat 192.168.160.200/aopioc/eureka-server:uat
'''

}

}

//上传镜像
stage("PushImages"){
ws("${workspace}"){
sh """
docker login --username dev --password xxx 192.168.160.200
docker push 192.168.160.200/aopioc/eureka-server:uat
sleep 5
"""
}
}

//发布应用
stage("Deploy App"){
ws("${workspace}"){
sh """
curl -u "7E39F76AB18C2BF4E943:grphuLSjFVhmEh5KzemEdjdMUBgKPhuKZEkf2PuR" \
-X POST \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
-d '{"inServiceStrategy":{"type":"inServiceUpgradeStrategy", "batchSize":1, "intervalMillis":2000, "launchConfig":{"type":"launchConfig", "blkioWeight":null, "capAdd":[], "capDrop":[], "cgroupParent":null, "count":null, "cpuCount":null, "cpuPercent":null, "cpuPeriod":null, "cpuQuota":null, "cpuRealtimePeriod":null, "cpuRealtimeRuntime":null, "cpuSet":null, "cpuSetMems":null, "cpuShares":null, "dataVolumes":[], "dataVolumesFrom":[], "description":null, "devices":[], "diskQuota":null, "dns":[], "dnsSearch":[], "domainName":null, "healthInterval":null, "healthRetries":null, "healthTimeout":null, "hostname":null, "imageUuid":"docker:192.168.160.200/tkpint/eureka-server:uat", "instanceTriggeredStop":"stop", "ioMaximumBandwidth":null, "ioMaximumIOps":null, "ip":null, "ip6":null, "ipcMode":null, "isolation":null, "kernelMemory":null, "kind":"container", "labels":{"io.rancher.container.pull_image":"always"}, "logConfig":{"type":"logConfig", "config":{}, "driver":null}, "memory":null, "memoryMb":null, "memoryReservation":null, "memorySwap":null, "memorySwappiness":null, "milliCpuReservation":null, "networkMode":"managed", "oomScoreAdj":null, "pidMode":null, "pidsLimit":null, "ports":[], "privileged":false, "publishAllPorts":false, "readOnly":false, "requestedIpAddress":null, "runInit":false, "secrets":[], "shmSize":null, "startOnCreate":true, "stdinOpen":true, "stopSignal":null, "stopTimeout":null, "system":false, "tty":true, "user":null, "userdata":null, "usernsMode":null, "uts":null, "version":"9e201534-4596-4c93-b6fb-a33d7daf5c73", "volumeDriver":null, "workingDir":null, "dataVolumesFromLaunchConfigs":[], "networkLaunchConfig":null, "vcpu":1, "drainTimeoutMs":0}, "previousLaunchConfig":{"type":"launchConfig", "capAdd":[], "capDrop":[], "dataVolumes":[], "dataVolumesFrom":[], "devices":[], "dns":[], "dnsSearch":[], "imageUuid":"docker:192.168.160.200/tkpint/eureka-server:uat", "instanceTriggeredStop":"stop", "kind":"container", "labels":{"io.rancher.container.pull_image":"always"}, "logConfig":{"type":"logConfig", "config":{}, "driver":""}, "networkMode":"managed", "ports":[], "privileged":false, "publishAllPorts":false, "readOnly":false, "runInit":false, "secrets":[], "startOnCreate":true, "stdinOpen":true, "system":false, "tty":true, "version":"0", "dataVolumesFromLaunchConfigs":[], "vcpu":1, "drainTimeoutMs":0}, "previousSecondaryLaunchConfigs":[], "secondaryLaunchConfigs":[], "startFirst":true}, "toServiceStrategy":null}' \
'http://192.168.160.200:9000/v2-beta/projects/1a5/services/1s9/?action=upgrade'
sleep 50
curl -u "7E39F76AB18C2BF4E943:grphuLSjFVhmEh5KzemEdjdMUBgKPhuKZEkf2PuR" \
-X POST \
-H 'Accept: application/json' \
-H 'Content-Type: application/json' \
'http://192.168.160.200:9000/v2-beta/projects/1a5/services/1s9/?action=finishupgrade'
"""
}
}
//清除工作目录
stage("Clean Workspace"){
ws("${workspace}"){
sh """
docker rmi 192.168.160.200/tkpint/eureka-server:uat
docker rmi eureka-server:uat

"""
}
}
}
```

查看全文
大家还看了
也许喜欢
更多游戏

Copyright © 2024 妖气游戏网 www.17u1u.com All Rights Reserved