gitlab的安装和基本使用

一、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=
enable=

国内清华源

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

gitlab的安装和基本使用

EXTERNAL_URL="http://gitlab.example.com" yum install -y gitlab-ce --nogpgcheck

安装好修改配置文件

gitlab的安装和基本使用

gitlab的安装和基本使用

5)启动查看状态

gitlab-ctl reconfigure
[root@gitlab ~]# gitlab-ctl status
run: alertmanager: (pid ) 431s; run: log: (pid ) 430s
run: gitaly: (pid ) 432s; run: log: (pid ) 432s
run: gitlab-monitor: (pid ) 432s; run: log: (pid ) 431s
run: gitlab-workhorse: (pid ) 432s; run: log: (pid ) 431s
run: logrotate: (pid ) 487s; run: log: (pid ) 432s
run: nginx: (pid ) 493s; run: log: (pid ) 432s
run: node-exporter: (pid ) 475s; run: log: (pid ) 432s
run: postgres-exporter: (pid ) 430s; run: log: (pid ) 430s
run: postgresql: (pid ) 534s; run: log: (pid ) 432s
run: prometheus: (pid ) 431s; run: log: (pid ) 431s
run: redis: (pid ) 540s; run: log: (pid ) 432s
run: redis-exporter: (pid ) 463s; run: log: (pid ) 431s
run: sidekiq: (pid ) 501s; run: log: (pid ) 432s
run: unicorn: (pid ) 507s; run: log: (pid ) 432s

启动

6)本地测试访问注意问题

虚拟机中   /etc/hosts里面添加
192.168.0.49 gitlab.example.com 本地电脑中 C:\Windows\System32\drivers\etc\hosts
192.168.0.49 gitlab.example.com

强调hosts文件

gitlab的安装和基本使用

访问成功

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常用命令

二、使用gitlab

1)创建用户名登录

gitlab的安装和基本使用

跳转至登录界面

gitlab的安装和基本使用

gitlab的安装和基本使用

2)添加秘钥设置

在服务器上生成秘钥,复制公钥内容进来

gitlab的安装和基本使用

可使用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::a4::2f:fd:5d::ba:8c:a4:e4:c2::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: , done.
remote: Counting objects: % (/), done.
remote: Compressing objects: % (/), done.
remote: Total (delta ), reused (delta )
Receiving objects: % (/), 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
file changed, insertion(+)
[root@redis02 public]# git push origin master
Counting objects: , done.
Compressing objects: % (/), done.
Writing objects: % (/), bytes | bytes/s, done.
Total (delta ), reused (delta )
To git@192.168.10.239:caojin/public.git
18965a3..3bb2d0d master -> master

三、新版本gitlab测试

1)取消注册功能

gitlab的安装和基本使用

2)创建项目之前先创建组

gitlab的安装和基本使用

2)创建项目。可以选择之前的建立的组

gitlab的安装和基本使用

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::}
f0e08a
[root@node02 demo]# API_VER=$(echo ${API_VERL::})
[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 重启
上一篇:angular2报错


下一篇:Android注入事件的三种方法比较