目录
docker安装gitlab+jenkins
环境准备:
Gitlab 2G内存 192.168.194.130
jenkins 1G内存 192.168.194.131
1. 关闭防火墙
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# setenforce 0
2. 安装docker
上传docker的yum源
链接: https://pan.baidu.com/s/1O62uD1nHrP7K2WYfwD3AMw 提取码: svw8 复制这段内容后打开百度网盘手机App,操作更方便哦
安装docker
[root@localhost ~]# yum -y install docker-ce
3. 启动docker
[root@localhost ~]# systemctl start docker
[root@localhost ~]# cd /etc/docker/
[root@localhost docker]# cat daemon.json #加速拉取操作
{
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2",
"registry-mirrors":[
"https://kfwkfulq.mirror.aliyuncs.com",
"https://2lqq34jg.mirror.aliyuncs.com",
"https://pee6w651.mirror.aliyuncs.com",
"http://hub-mirror.c.163.com",
"https://docker.mirrors.ustc.edu.cn",
"https://registry.docker-cn.com"
]
}
[root@localhost docker]# systemctl restart docker
Gitlab操作
1. 导入gitlab镜像
链接: https://pan.baidu.com/s/1Gbni7XDRUdL25pJ80H27sg 提取码: kcr3 复制这段内容后打开百度网盘手机App,操作更方便哦
或使用
[root@localhost ~]# docker search gitlab #找到对应的jenkins进行拉取
[root@localhost ~]# docker pull 镜像名
[root@localhost ~]# tar xzf gitlab.tar.gz #先解压缩包
[root@localhost ~]# docker load -i gitlab.tar
0a42ee6ceccb: Loading layer 118.8MB/118.8MB
c2af38e6b250: Loading layer 15.87kB/15.87kB
5e95929b2798: Loading layer 14.85kB/14.85kB
2166dba7c95b: Loading layer 5.632kB/5.632kB
bcff331e13e3: Loading layer 3.072kB/3.072kB
527e096b25ed: Loading layer 75.85MB/75.85MB
3e031abda158: Loading layer 2.048kB/2.048kB
115b085a9532: Loading layer 2.048kB/2.048kB
e06226fa16d9: Loading layer 2.048kB/2.048kB
3cf24c3b30df: Loading layer 15.87kB/15.87kB
270818ad6531: Loading layer 1.329GB/1.329GB
21b8cfcf8608: Loading layer 16.4MB/16.4MB
b3d18f681941: Loading layer 20.65MB/20.65MB
b84c6e1d76b7: Loading layer 120.7MB/120.7MB
eef9e0816bf9: Loading layer 14.34kB/14.34kB
5c56fa0ee48e: Loading layer 217.1kB/217.1kB
838a41303ef5: Loading layer 58.37kB/58.37kB
9ca1aa372fbc: Loading layer 2.303MB/2.303MB
bfea59f3dc0e: Loading layer 2.949MB/2.949MB
Loaded image: twang2218/gitlab-ce-zh:latest
2. 创建容器gitlab
[root@localhost ~]# docker run --name gitlab -d -p 80:80 -p 4422:22 twang2218/gitlab-ce-zh
03ca161073865a7b1bc1b87d1e70db2ed4109a530afaaa1bbd188c8a6e9e36e9
3. 登录网页(192.168.194.130)
gitlab响应有点慢得要稍等几分钟
4. 创建项目
5. ssh私钥
[root@localhost ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:i7Fn3v6ReQTErsW4JItEVZVS+8jQnCemuylcFeHoEHA root@localhost.localdomain
The key's randomart image is:
+---[RSA 2048]----+
| .oE..+=o |
| .. ..*+o |
| . . o=X.. |
| . .oo==* |
| ...S+o=o o |
| .+..+. + |
| o.+.. + . |
| +o. o o |
| .o=.. |
+----[SHA256]-----+
[root@localhost ~]# cat .ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDIvVsetBdTJXwicJr7WCQtYZRQYOJuNwL3bcGrwgIOnjgIrYiltWjIwVsNbd2yVqYktXYpHGku81XvhajEAkL8oiq3RODP3fp3MR3e4U8P5W3n6iuvqFjsFFaeyG3kfrusup3LTNxj+waNFHeVhJMF9EVtE91tdJUVYn23U7PBEV5ECR0O2e06ffykuXZiIsKFfUmoNr/FwiuToZGhN69Lh1Z387qAMouC4I/xJpHNvYmWVp5Uha6B1Nzb0X9IIcLcatUzABn3Q3RGPXrMMPJyxG5oBQIgnRfmF2RRCHKceemLkTC7p2b3+6BtAiLe9CFxRbgMI6JcSiE/z4FBD/d7 root@localhost.localdomain
安装git工具
[root@localhost ~]# yum -y install git
测试将文件克隆到本地
[root@localhost ~]# git clone ssh://git@192.168.194.130:4422/root/demo.git
正克隆到 'demo'...
The authenticity of host '[192.168.194.130]:4422 ([192.168.194.130]:4422)' can't be established.
ECDSA key fingerprint is SHA256:E3mgIRHkOBU4Zjv4C0fMDpB9hGh1om1GHu3gEqPa45Q.
ECDSA key fingerprint is MD5:f2:31:e9:b7:31:85:59:80:fa:29:af:19:5f:fa:64:17.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[192.168.194.130]:4422' (ECDSA) to the list of known hosts.
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
接收对象中: 100% (3/3), done.
[root@localhost ~]# ls ##克隆成功
demo
[root@localhost ~]# cd demo/
[root@localhost demo]# cat cs #查看文件内容
this is file
Jenkins操作
1. 导入jenkins镜像
链接: https://pan.baidu.com/s/1QnQ4aJ2otcp84bD7MTslXA 提取码: my34 复制这段内容后打开百度网盘手机App,操作更方便哦
[root@localhost ~]# docker search jenkins #找到对应的jenkins进行拉取
[root@localhost ~]# docker pull 镜像名
[root@localhost ~]# docker load -i jenkins.tar
7948c3e5790c: Loading layer 105.6MB/105.6MB
4d1ab3827f6b: Loading layer 24.1MB/24.1MB
69dfa7bd7a92: Loading layer 8.005MB/8.005MB
01727b1a72df: Loading layer 146.4MB/146.4MB
e43c0c41b833: Loading layer 10.1MB/10.1MB
bd76253da83a: Loading layer 3.584kB/3.584kB
d81d8fa6dfd4: Loading layer 205.7MB/205.7MB
c66fa523f0ae: Loading layer 153.9MB/153.9MB
12c492d83a0a: Loading layer 338.9kB/338.9kB
08957f5bce36: Loading layer 3.584kB/3.584kB
062c102eebd5: Loading layer 9.728kB/9.728kB
1d0066935898: Loading layer 868.9kB/868.9kB
8e4f73a75f04: Loading layer 67.28MB/67.28MB
0a647d19a0f3: Loading layer 3.584kB/3.584kB
7310a36006c5: Loading layer 6.002MB/6.002MB
e80c9812d613: Loading layer 9.728kB/9.728kB
58da6528e65c: Loading layer 5.12kB/5.12kB
ce5eb73cb093: Loading layer 3.072kB/3.072kB
cea6da0449e8: Loading layer 2.56kB/2.56kB
6abbb5362789: Loading layer 13.82kB/13.82kB
Loaded image: jenkins/jenkins:latest
2. 创建容器jenkins
[root@localhost ~]# docker run --name jenkins -d -p 80:8080 jenkins/jenkins
08cb848c4e4c678184190399ad7556c3d46acae8d0829d0090153545916a895e
3. 登录网页(192.168.194.131)
4. 解锁jenkins
[root@localhost ~]# docker exec -it jenkins bash #登录jenkins容器内部查看
jenkins@08cb848c4e4c:/$ cat /var/jenkins_home/secrets/initialAdminPassword
cd44f7c7f8f646c0b8d0d3f94a28c41e
5. 进入jenkins界面
6. 安装插件
7. 登录jenkins容器生成ssh秘钥
[root@localhost ~]# docker exec -it jenkins bash
jenkins@08cb848c4e4c:/$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/var/jenkins_home/.ssh/id_rsa):
Created directory '/var/jenkins_home/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /var/jenkins_home/.ssh/id_rsa.
Your public key has been saved in /var/jenkins_home/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:HMFGxGaPTuprIx6ldEtGP5p0sQlZufQCKZwC2dKOBfQ jenkins@08cb848c4e4c
The key's randomart image is:
+---[RSA 2048]----+
|+B . . *=. |
|o * + ooO. |
| = E .+*o= |
|. . . +==o |
| . *+S. |
| . B.=.. |
| o.+ |
| ..+ |
| ..o.o |
+----[SHA256]-----+
jenkins@08cb848c4e4c:/$ cat /var/jenkins_home/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC9TjOdlDE6mwDP/g1PRzRVMFRSgeXNsCz6Ff6QlnnliCe+XPCVUBm23guIgeU4Zo7ewRzBwNuQ4LWbLN77oYmvs2vw7AMAHzYYzqu0JY62mFBl4lwKKiwt3cDXN/jiPrlcxghr+EiCySuExVQefqiDyPYEYOM4a826MBVm8ts/yVXHUhnAFPsmqQs954Hfj9vu1xJAKiL6eUkrraIulYoU0rdSwGaS4x1eiNDKNuFdRfKv/q3I+/jXzhGtmECrsrYZ+UMQnCFA/6tAGGtnf7f5ueFHVmysSVCMq8Cs9BXim8bdg+HoNXlQjXYktriwPJT1UZ+zCbhkmBm5KBba2tzz jenkins@08cb848c4e4c
将秘钥发送到gitlab
8. jenkins配置