[toc]

部署gitlab

  • 私有代码仓库 ,除了gitlab以外 还有gogs
  • 精细化的权限配置
  • 控制用户/用户组权限,避免任何用户都可以将代码提交到master

image-20230516155525310

下载安装包

image-20230516155621601

image-20230516155628033

image-20230516155631839

image-20230516155635736

1
2
3
4
5
# 下载gitlab
wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-12.3.5-ce.0.el7.x86_64.rpm

# 安装gitlab
yum localinstall -y gitlab-ce-12.3.5-ce.0.el7.x86_64.rpm

安装成功

image-20230516155749457

修改配置文件

  • 备份配置文件

    1
    # cp /etc/gitlab/gitlab.rb{,.bak}
  • 配置邮箱

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    # 修改配置你文件 添加域名
    vim /etc/gitlab/gitlab.rb
    13 external_url 'http://gitlab.xxx.com'

    # 配置邮箱
    ## 用于:用户激活、用户注册、找回密码、合并通知、领导审批、邮件告警
    52 gitlab_rails['gitlab_email_enabled'] = true
    53 gitlab_rails['gitlab_email_from'] = '2412628480@qq.com'
    54 gitlab_rails['gitlab_email_display_name'] = 'xxx gitlab notice'

    # 邮件发送配置(类似于mail.rc中的配置)
    559 gitlab_rails['smtp_enable'] = true
    560 gitlab_rails['smtp_address'] = "smtp.qq.com"
    561 gitlab_rails['smtp_port'] = 465
    562 gitlab_rails['smtp_user_name'] = "QQ号码"
    563 gitlab_rails['smtp_password'] = "自己的授权码"
    564 gitlab_rails['smtp_domain'] = "qq.com"
    565 gitlab_rails['smtp_authentication'] = "login"
    566 gitlab_rails['smtp_enable_starttls_auto'] = true
    567 gitlab_rails['smtp_tls'] = true
  • 优化配置文件

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    # 关闭普罗米修斯
    1460 prometheus['enable'] = false
    1461 prometheus['monitor_kubernetes'] = false
    1631 prometheus_monitoring['enable'] = false

    # 告警关闭
    1529 alertmanager['enable'] = false

    # 关闭前端node功能
    1551 node_exporter['enable'] = false

    # 关闭redis功能
    1570 redis_exporter['enable'] = false

    # 关闭postgre功能
    1588 postgres_exporter['enable'] = false

    # 内部监控
    1589 gitlab_monitor['enable'] = false

    # 图形展示
    1638 grafana['enable'] = false
  • 重新加载配置文件 初始化

    1
    # gitlab-ctl reconfigure

    image-20230516160550647

  • 检查端口是否启动

    1
    2
    # netstat -lntup
    tcp 0 0 127.0.0.1:8080 0.0.0.0:* LISTEN 79490/unicorn maste

gitlab命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# 查看当前的服务状态
gitlab-ctl status

# 停止所有的服务
gitlab-ctl stop

# 停掉的服务状态为down
gitlab-ctl status

# 启动所有服务
gitlab-ctl start

# 查看服务状态:run为开启、down为关闭
gitlab-ctl status

# 停止单个服务
gitlab-ctl stop nginx

# 启动单个服务
gitlab-ctl start nginx

# 查看gitlav所有组件日志
gitlab-ctl tail nginx
==> /var/log/gitlab/nginx/error.log <==
==> /var/log/gitlab/nginx/gitlab_access.log <==
==> /var/log/gitlab/nginx/gitlab_error.log <==
==> /var/log/gitlab/nginx/access.log <==
==> /var/log/gitlab/nginx/current <==

# 查看单独服务日志
gitlab-ctl tail nginx
==> /var/log/gitlab/nginx/error.log <==
==> /var/log/gitlab/nginx/gitlab_access.log <==
==> /var/log/gitlab/nginx/gitlab_error.log <==
==> /var/log/gitlab/nginx/access.log <==
==> /var/log/gitlab/nginx/current <==

# 连接gitlab终端
gitlab-rails console

# 发送测试邮件
Notify.test_email('*********@qq.com','gitlab test','测试').deliver_now

image-20230516162757787

在gitlab终端修改密码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# 启动服务
gitlab-ctl start

# 进入终端
gitlab-rails console

# 查看所有用户
User.all

# 切换到root用户
User.where(id:1).first

# 修改密码
user.password="12345678"

# 保存密码
user.save!

配置远端私有仓库

访问web界面

1
2
3
4
5
# 本地DNS
10.0.0.91 gitlab.xxx.com

# 浏览器访问
gitlab.xxx.com

image-20230516163804288

image-20230516163824018

image-20230516163850024

完全汉化

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 解压汉化包
tar xf gitlab-v12.3.5-zh.tar.gz

# 查看版本
cat /root/gitlab-v12.3.5-zh/VERSION
12.3.5

# 停止所有服务
gitlab-ctl stop

# 覆盖
\cp -r -a /root/gitlab-v12.3.5-zh/* /opt/gitlab/embedded/service/gitlab-rails/

# 重新加载配置文件
gitlab-ctl reconfigure

# 启动所有服务
gitlab-ctl start

创建远程私有仓库

image-20230516164544847

添加密钥

1
2
3
4
# 查看生成的密钥
cat .ssh/id_rsa.pub

# 在以下配置页面输入密钥

image-20230516164624139

image-20230516164635820

配置远程仓库并与本地仓库同步

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# 在本地仓库应用Git全局设置
git config --global user.name "Administrator"
git config --global user.email "admin@example.com"

# 创建本地仓库文件夹
mkdir /root/test

# 切换到本地仓库目录
cd test

# 初始化本地仓库
git init

# 添加远端仓库地址(ssh或http)
git remote add origin git@gitlab.xxx.com:root/test.git

# 将本地仓库内容添加到暂存区
git add .

# 提交更改并备注
git commit -m "Initial commit"

# 添加远端仓库的域名解析
10.0.0.91 gitlab.xxx.com

# 将本地仓库同步到远端仓库
git push -u origin master

# 将远端仓库下载到本地
git clone git@git.......

用和群组管理

用户组

image-20230517201534202

image-20230517201538075

image-20230517201542425

image-20230517201552371

创建用户

image-20230517201604642

image-20230517201613471

image-20230517201623278