一、gitlab的安装
1)安装依赖包

sudo yum install git vim gcc glibc-statc telnet -y sudo yum install -y curl policycoreutils-python openssh-server sudo systemctl enable sshd sudo systemctl start sshd sudo yum install postfix sudo systemctl enable postfix sudo systemctl start postfix
2)设置防火墙(可选)

sudo firewall-cmd --permanent --add-service=http
sudo systemctl reload firewalld
3)添加gitlab安装源
3.1)设置国内安装源,如设置清华大学的源

vim /etc/yum.repos.d/gitlab-ce.repo [gitlab-ce] name=Gitlab CE Repository baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/ gbgcheck=0 enable=1
3.2)在国外,设置国外源

curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh | sudo bash
4)安装gitlab
4.1)设置域名方式安装

sudo EXTERNAL_URL="http://gitlab.example.com" yum install -y gitlab-ce
4.11)可购买真实发域名方式,替换上面的域名
4.12)本地域名测试,在 /etc/hosts里面添加
192.168.1.20 gitlab.example.com
4.2)不设置域名安装方式
yum install gitlab-ce 安装
gitlab-ctl reconfigure 修改配置
4.3)如果安装遇到问题解决。--nogpgcheck
EXTERNAL_URL="http://gitlab.example.com" yum install -y gitlab-ce --nogpgcheck
安装好修改配置文件
5)启动查看状态

gitlab-ctl reconfigure [root@gitlab ~]# gitlab-ctl status run: alertmanager: (pid 4313) 431s; run: log: (pid 4324) 430s run: gitaly: (pid 4245) 432s; run: log: (pid 4272) 432s run: gitlab-monitor: (pid 4284) 432s; run: log: (pid 4287) 431s run: gitlab-workhorse: (pid 4230) 432s; run: log: (pid 4295) 431s run: logrotate: (pid 3810) 487s; run: log: (pid 4238) 432s run: nginx: (pid 3779) 493s; run: log: (pid 4237) 432s run: node-exporter: (pid 3912) 475s; run: log: (pid 4273) 432s run: postgres-exporter: (pid 4331) 430s; run: log: (pid 4336) 430s run: postgresql: (pid 3494) 534s; run: log: (pid 4221) 432s run: prometheus: (pid 4297) 431s; run: log: (pid 4304) 431s run: redis: (pid 3432) 540s; run: log: (pid 4220) 432s run: redis-exporter: (pid 4036) 463s; run: log: (pid 4288) 431s run: sidekiq: (pid 3744) 501s; run: log: (pid 4223) 432s run: unicorn: (pid 3704) 507s; run: log: (pid 4222) 432s
6)本地测试访问注意问题

虚拟机中 /etc/hosts里面添加 192.168.0.49 gitlab.example.com 本地电脑中 C:WindowsSystem32driversetchosts 192.168.0.49 gitlab.example.com
访问成功
7)gitlab常用命令

sudo gitlab-ctl start # 启动所有 gitlab 组件; sudo gitlab-ctl stop # 停止所有 gitlab 组件; sudo gitlab-ctl restart # 重启所有 gitlab 组件; sudo gitlab-ctl status # 查看服务状态; sudo gitlab-ctl reconfigure # 启动服务; sudo vim /etc/gitlab/gitlab.rb # 修改默认的配置文件; gitlab-rake gitlab:check SANITIZE=true --trace # 检查gitlab; sudo gitlab-ctl tail # 查看日志;
二、使用gitlab
1)创建用户名登录
跳转至登录界面
2)添加秘钥设置
在服务器上生成秘钥,复制公钥内容进来
可使用ssh秘钥免费下载
[root@redis02 gitlab_test]# git clone git@192.168.10.239:user/public.git Cloning into 'public'... The authenticity of host '192.168.10.239 (192.168.10.239)' can't be established. RSA key fingerprint is b5:f4:49:a4:92:2f:fd:5d:41:ba:8c:a4:e4:c2:62:5d. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '192.168.10.239' (RSA) to the list of known hosts. remote: Enumerating objects: 6, done. remote: Counting objects: 100% (6/6), done. remote: Compressing objects: 100% (3/3), done. remote: Total 6 (delta 0), reused 0 (delta 0) Receiving objects: 100% (6/6), done. Checking connectivity... done.
修改代码上传
[root@redis02 public]# git config --global user.email "1257073656@qq.com" [root@redis02 public]# git config --global user.name "user" [root@redis02 public]# git commit -m "change on linux" [master 3bb2d0d] change on linux 1 file changed, 1 insertion(+) [root@redis02 public]# git push origin master Counting objects: 3, done. Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 287 bytes | 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) To git@192.168.10.239:caojin/public.git 18965a3..3bb2d0d master -> master
三、新版本gitlab测试
1)取消注册功能
2)创建项目之前先创建组
2)创建项目。可以选择之前的建立的组
3)git对提交代码的版本控制
[root@node02 demo]# git show|grep commit commit f0e08a0c0df9d6e82ebaf4833bd446d7edd48422 [root@node02 demo]# git show|grep commit|cut -d ' ' -f2 f0e08a0c0df9d6e82ebaf4833bd446d7edd48422 [root@node02 demo]# API_VERL=$(git show|grep commit|cut -d ' ' -f2) [root@node02 demo]# echo $API_VERL f0e08a0c0df9d6e82ebaf4833bd446d7edd48422 [root@node02 demo]# echo ${API_VERL:0:6} f0e08a [root@node02 demo]# API_VER=$(echo ${API_VERL:0:6}) [root@node02 demo]# echo $API_VER f0e08a
4)修改拉取代码的默认url
vim /etc/gitlab/gitlab.rb ..... # external_url 'http://gitlab.example.com' external_url 'http://192.168.10.24' [root@node02 gitlab]# gitlab-ctl reconfigure 重启