Jenkins + Ansible + Gitlab(一)

Gitlab篇

参考:https://www.gitlab.com.cn/installation/#centos-7

好处不多说...

关闭防火墙:

[root@gitlab ~]# systemctl stop firewalld.service 
[root@gitlab ~]# systemctl disable firewalld.service 

关selinux

[root@gitlab ~]# sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
[root@gitlab ~]# setenforce 0

安装依赖

[root@gitlab ~]# yum install curl  policycoreutils openssh-server openssh-clients postfix -y

安装仓库

[root@gitlab ~]# curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash

启动postfix邮件服务

[root@gitlab ~]# systemctl start postfix
[root@gitlab ~]# systemctl enable postfix

修改yum源,官方慢得跟蜗牛

安装gitlab-ce

[root@gitlab ~]# yum install gitlab-ce -y

创建域名证书

[root@gitlab ~]# mkdir /etc/gitlab/ssl -p
[root@gitlab ~]# openssl genrsa -out "/etc/gitlab/ssl/gitlab.example.key" 2048
Generating RSA private key, 2048 bit long modulus
......................+++
..........................+++
e is 65537 (0x10001)
[root@gitlab ~]# openssl req -new -key "/etc/gitlab/ssl/gitlab.example.key" -out "/etc/gitlab/ssl/gitlab.example.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) []:bj
Locality Name (eg, city) [Default City]:bj
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 []:123456
An optional company name []:
[root@gitlab ~]# ll /etc/gitlab/ssl/
总用量 8
-rw-r--r-- 1 root root 1062 2月  14 20:50 gitlab.example.csr
-rw-r--r-- 1 root root 1679 2月  14 20:47 gitlab.example.key
[root@gitlab ~]# openssl x509 -req -days 365 -in "/etc/gitlab/ssl/gitlab.example.csr" -signkey "/etc/gitlab/ssl/gitlab.example.key" -out "/etc/gitlab/ssl/gitlab.example.crt"
Signature ok
subject=/C=cn/ST=bj/L=bj/O=Default Company Ltd/CN=gitlab.example.com/[email protected]
Getting Private key
[root@gitlab ~]# ll /etc/gitlab/ssl/
总用量 12
-rw-r--r-- 1 root root 1257 2月  14 20:53 gitlab.example.crt
-rw-r--r-- 1 root root 1062 2月  14 20:50 gitlab.example.csr
-rw-r--r-- 1 root root 1679 2月  14 20:47 gitlab.example.key
[root@gitlab ~]# 
[root@gitlab ~]# openssl dhparam -out "/etc/gitlab/ssl/dhparams.pem" 2048
[root@gitlab ~]# ll /etc/gitlab/ssl/
总用量 16
-rw-r--r-- 1 root root  424 2月  14 20:57 dhparams.pem
-rw-r--r-- 1 root root 1257 2月  14 20:53 gitlab.example.crt
-rw-r--r-- 1 root root 1062 2月  14 20:50 gitlab.example.csr
-rw-r--r-- 1 root root 1679 2月  14 20:47 gitlab.example.key
[root@gitlab ~]# chmod 600 /etc/gitlab/ssl/*
[root@gitlab ~]# ll /etc/gitlab/ssl/
总用量 16
-rw------- 1 root root  424 2月  14 20:57 dhparams.pem
-rw------- 1 root root 1257 2月  14 20:53 gitlab.example.crt
-rw------- 1 root root 1062 2月  14 20:50 gitlab.example.csr
-rw------- 1 root root 1679 2月  14 20:47 gitlab.example.key

修改gitlab配置文件

[root@gitlab gitlab]# gitlab-ctl reconfigure

修改nginx配置文件,重定向http到https

[root@gitlab ~]# vim /var/opt/gitlab/nginx/conf/gitlab-http.conf 
 rewrite ^(.*)$ https://$host$1 permanent;
[root@gitlab ~]# gitlab-ctl restart

修改windows的hosts文件,加入下面这行,

域名重定向

192.168.2.108 gitlab.example.com

登陆gitlab,设置密码,登陆

创建一个项目:

克隆仓库:

提交一个文件,并提交

[root@node1 repo]# cd test-repo/
[root@node1 test-repo]# vim test.py
[root@node1 test-repo]# git add .
^[[3~[root@node1 test-repo]# git add .
[root@node1 test-repo]# git commit -m "First commit"

*** Please tell me who you are.

Run

  git config --global user.email "[email protected]"
  git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: unable to auto-detect email address (got 'root@node1.(none)')
[root@node1 test-repo]# git config --global user.email "[email protected]"
[root@node1 test-repo]# git config --global user.name "admin"
[root@node1 test-repo]# git commit -m "First commit"
[master(根提交) 95aaefb] First commit
 1 file changed, 1 insertion(+)
 create mode 100644 test.py

[root@node1 test-repo]# git -c http.sslVerify=false push origin master
Username for 'https://gitlab.example.com': root
Password for 'https://[email protected]': 
Counting objects: 3, done.
Writing objects: 100% (3/3), 230 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To https://gitlab.example.com/root/test-repo.git
 * [new branch]      master -> master

web界面如图:


运维人如何检查GitLab系统健康状况

创建两个普通账号:开发和领导

可以自行编辑账户密码



分配权限:

用户的密码修改:


dev开发人员提交代码

克隆仓库

[root@node1 repo]# rm test-repo/ -rf
[root@node1 repo]# git -c http.sslVerify=false clone https://gitlab.example.com/root/test-repo.git
正克隆到 'test-repo'...
Username for 'https://gitlab.example.com': dev
Password for 'https://[email protected]': 
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.

新建分支,切换分支,修改文件,提交到本地仓库,提交到远程的release-1.0分支

[root@node1 test-repo]# ls
test.py
[root@node1 test-repo]# git checkout -b release-1.0
切换到一个新分支 'release-1.0'
[root@node1 test-repo]# ls
test.py
[root@node1 test-repo]# vim test.py 
[root@node1 test-repo]# cat test.py 
print "This is a test code release-1.0"

[root@node1 test-repo]# git add .
[root@node1 test-repo]# git commit -m"release-1.0"
[release-1.0 0667463] release-1.0
 1 file changed, 2 insertions(+), 1 deletion(-)
[root@node1 test-repo]# git -c http.sslVerify=false push origin release-1.0
Username for 'https://gitlab.example.com': dev
Password for 'https://[email protected]': 
Counting objects: 5, done.
Writing objects: 100% (3/3), 273 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: 
remote: To create a merge request for release-1.0, visit:
remote:   https://gitlab.example.com/root/test-repo/merge_requests/new?merge_request%5Bsource_branch%5D=release-1.0
remote: 
To https://gitlab.example.com/root/test-repo.git
 * [new branch]      release-1.0 -> release-1.0

此时开发人员视角的gitlab

开发人员可以申请合并分支:

申请如下:


此时项目leader的视角

查看merge请求:

leader查看仓库:

猜你喜欢

转载自blog.csdn.net/qq_33317586/article/details/87294521
今日推荐