所需要用到的环境:
Gitlab: 172.20.7.70Jenkins: 172.20.7.71nginx: 172.20.7.72
gitlab 和Jenkins安装自行百度
开始实验操作
首先通过网页访问nginx,nginx默认测试页我是改了的 ,所以看到的不是它原生的
1、先在Jenkins机器上创建好ssh密钥对
[root@node2 ~]#ssh-keygen -t rsa
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:Tkn6vspyZyn5QUwyISsLNIA6zVmo06iZVMmNZf+HprI root@node2.dklwj.com
The key's randomart image is:
+---[RSA 2048]----+
|+o..*o. |
|o o=o+.. |
|o*oo. o.o |
|*o=o B... |
|o=. . S+ . |
|+ =o . |
| . o+. |
| ..*.+. |
| Eo*+. |
+----[SHA256]-----+
2、查看公钥文件
[root@node2 ~]#cat /root/.ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCvWyCl1WXHHrPHwUNgvx3BvMNhd5mbNlJz75gAtdm0ff+a6hr4eOm2ajHMONNQq7h2QdrVqi+o+OYYK7PFfLAxmKjWYlwEdz/3J1UeclTBQKAungiazYOBVGHqL6Omhm4kdljkTP0BljgApuJD1KHm0AisJ9bDJk7YTUXhrdF53ThVaPXIDkrsBi4a+D6dnWsopCXweadoLe9qHt26yPGHAzPjlCG6qL5c7oMFBdaG5sL4iMqw9fudbkZ8q3sv+CN0brTS1uM8MtfAjnaVGHVlBHjZOOLg5WcqIvE1LSONQSyElN7xvc/mYAGErOnhyGny0QE/R1WgbMFKrT5OB59z root@node2.dklwj.com
3、通过网页打开gitlab的操作界面
4、验证自动拉取是否成功
5、在Jenkins上配置ssh私钥
6、新建任务,需要提前在Jenkins主机把ssh免密钥文件复制到nginx主机上去
[root@node02 ~]#ssh-copy-id root@172.20.7.72
7、通过Jenkins构建之后再次访问nginx页面
转载于:https://blog.51cto.com/dklwj/2328104