Jenkins+Gitlab+Ansible自动化部署(一)

Jenkins+Gitlab+Ansible自动化部署

一、实验环境要求(更新时间 2021-08-09)

1、服务器环境要求

主机名 IP地址 服务 系统版本 内核版本
gitlab 192.168.200.157 gitlab CentOS Linux release 7.6.1810 (Core) 3.10.0-957.el7.x86_64
jenkins 192.168.200.158 jenkins CentOS Linux release 7.6.1810 (Core) 3.10.0-957.el7.x86_64
ansible 192.168.200.159 ansible CentOS Linux release 7.6.1810 (Core) 3.10.0-957.el7.x86_64

2、客户端环境要求

  • 宿主机win10系统下的C:\Windows\System32\drivers\etc\hosts文件中添加如下内容
192.168.200.157 gitlab.example.com 
192.168.200.158 jenkins.example.com 
192.168.200.159 ansible.example.com 

二、基础环境配置

1、修改主机名

[root@lqf ~]# hostnamectl --static set-hostname gitlab
[root@lqf ~]# hostnamectl --static set-hostname jenkins
[root@lqf ~]# hostnamectl --static set-hostname ansible

2、配置 hosts

[root@gitlab ~]# vim /etc/hosts
192.168.200.157 gitlab.example.com 
192.168.200.158 jenkins.example.com 
192.168.200.159 ansible.example.com 
[root@gitlab ~]# scp -P54077  /etc/hosts [email protected]:/etc/hosts
[root@gitlab ~]# scp -P54077  /etc/hosts [email protected]:/etc/hosts

3、关闭防火墙和selinux

[root@gitlab ~]# sed -i "s/enforcing/disabled/" /etc/selinux/config
[root@gitlab ~]# systemctl stop firewalld && systemmctl disable firewalld
[root@gitlab ~]# reboot
[root@gitlab ~]# getenforce
Permissive
[root@gitlab ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:firewalld(1)

三、Gitlab 服务安装配置(版本 13.8.3-ce.0.el7 )

1、安装 postfix 并启动

[root@gitlab ~]# yum install postfix
[root@gitlab ~]# systemctl start postfix && systemctl enable postfix

2、安装 Gitlab 组件及 gitlab-ce

[root@gitlab ~]# yum install -y policycoreutils openssh-server openssh-clients
[root@gitlab ~]# curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
[root@gitlab ~]# yum install -y gitlab-ce 

3、创建证书

1、创建私有密钥
[root@gitlab ~]# mkdir -p /etc/gitlab/ssl
[root@gitlab ~]# openssl genrsa -out "/etc/gitlab/ssl/gitlab.example.com.key"  2048
Generating RSA private key, 2048 bit long modulus
...............+++
...............................................................................+++
e is 65537 (0x10001)
2、创建私有证书
[root@gitlab ~]# openssl req -new -key "/etc/gitlab/ssl/gitlab.example.com.key"  -out "/etc/gitlab/ssl/gitlab.example.com.csr"
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:cn
State or Province Name (full name) []:sh
Locality Name (eg, city) [Default City]:sh
Organization Name (eg, company) [Default Company Ltd]:  #输入空格,然后回车
Organizational Unit Name (eg, section) []:  #输入空格,然后回车
Common Name (eg, your name or your server's hostname) []:gitlab.example.com
Email Address []:[email protected]

Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:1234.com
An optional company name []:  #直接回车
查看
[root@gitlab ~]# ll /etc/gitlab/ssl/
total 8
-rw-r--r-- 1 root root 1066 Aug  6 18:09 gitlab.example.com.csr
-rw-r--r-- 1 root root 1679 Aug  6 18:08 gitlab.example.com.key
3、创建CRT签署证书
  • 利用私有密钥和私有证书创建CRT签署证书
[root@gitlab ~]# openssl x509 -req -days 365 -in "/etc/gitlab/ssl/gitlab.example.com.csr" -signkey "/etc/gitlab/ssl/gitlab.example.com.key" -out "/etc/gitlab/ssl/gitlab.example.com.crt"
Signature ok
subject=/C=cn/ST=sh/L=sh/O= /OU= /CN=gitlab.example.com/[email protected]
Getting Private key
查看
[root@gitlab ~]# ll /etc/gitlab/ssl/
total 12
-rw-r--r-- 1 root root 1265 Aug  6 18:10 gitlab.example.com.crt
-rw-r--r-- 1 root root 1066 Aug  6 18:09 gitlab.example.com.csr
-rw-r--r-- 1 root root 1679 Aug  6 18:08 gitlab.example.com.key
4、创建pem证书
  • 利用openssl命令输出pem证书
[root@gitlab ~]# openssl dhparam -out /etc/gitlab/ssl/dhparam.pem 2048
Generating DH parameters, 2048 bit long safe prime, generator 2
This is going to take a long time
........................................................+................................................................................+.....................................+..................................................................................+..............................................+..................................................................................................................................+..+..

你可能感兴趣的:(#,gitlab,jenkins)