gitlab介绍

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

git私有远程仓库gitlab_gitlab图形化

CentOS中发邮件的服务

sendmail postfix sendEmail

gitlab安装配置

gitlab安装官网:https://gitlab.cn/install/

git私有远程仓库gitlab_gitlab图形化_02

# 1.安装gitlab
[root@gitlab ~]# yum install -y https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-16.2.4-ce.0.el7.x86_64.rpm
      *.                  *.
      ***                 ***
     *****               *****
    .******             *******
    ********            ********
   ,,,,,,,,,***********,,,,,,,,,
  ,,,,,,,,,,,*********,,,,,,,,,,,
  .,,,,,,,,,,,*******,,,,,,,,,,,,
      ,,,,,,,,,*****,,,,,,,,,.
         ,,,,,,,****,,,,,,
            .,,,***,,,,
                ,*,.
  


     _______ __  __          __
    / ____(_) /_/ /   ____ _/ /_
   / / __/ / __/ /   / __ `/ __ \
  / /_/ / / /_/ /___/ /_/ / /_/ /
  \____/_/\__/_____/\__,_/_.___/
  

Thank you for installing GitLab!
GitLab was unable to detect a valid hostname for your instance.
Please configure a URL for your GitLab instance by setting `external_url`
configuration in /etc/gitlab/gitlab.rb file.
Then, you can start your GitLab instance by running the following command:
  sudo gitlab-ctl reconfigure

# 2.改配置文件
[root@gitlab ~]# vim /etc/gitlab/gitlab.rb

 32 external_url 'http://10.0.0.200'  修改为域名或者ip(有域名就用域名)端口修改 直接查找nginx的端口 

-#2.2修改邮箱配置文件
 105 gitlab_rails['gitlab_email_enabled'] = true
 109 gitlab_rails['gitlab_email_from'] = '1724723586@qq.com'
 110 gitlab_rails['gitlab_email_display_name'] = 'gitlab'
 
-#2.3修改邮件发送配置(类似于mail.rc中的配置)
 85 gitlab_rails['smtp_enable'] = true
 86 gitlab_rails['smtp_address'] = "smtp.qq.com"
 87 gitlab_rails['smtp_port'] = 465
 88 gitlab_rails['smtp_user_name'] = "1724723586@qq.com"
 89 gitlab_rails['smtp_password'] = "knlxluwgihwyxxx" //这个密码是授权码//
 90 gitlab_rails['smtp_domain'] = "qq.com"
 91 gitlab_rails['smtp_authentication'] = "login"
 92 gitlab_rails['smtp_enable_starttls_auto'] = false
 93 gitlab_rails['smtp_tls'] = true

 -# 把这些优化加到最后一行即可
 # 优化
 # 关闭普罗米修斯
 prometheus['enable'] = false
 prometheus['monitor_kubernetes'] = false
 prometheus_monitoring['enable'] = false
 
 # 告警关闭
 alertmanager['enable'] = false
 
 # 关闭前端node功能
 node_exporter['enable'] = false
 
 # 关闭redis功能
 redis_exporter['enable'] = false
 
 # 关闭postgre功能
 postgres_exporter['enable'] = false
 
 # 图形展示
 grafana['enable'] = false

# 3.更改配置文件后需重新加载配置 
[root@gitlab ~]# gitlab-ctl reconfigure   

-#(加载完会告诉初始用户和密码存放路径)(记下来)
Notes:
Default admin account has been configured with following details:
Username: root
Password: You didn't opt-in to print initial root password to STDOUT.
Password stored to /etc/gitlab/initial_root_password. This file will be cleaned up in first reconfigure run after 24 hours.

NOTE: Because these credentials might be present in your log files in plain text, it is highly recommended to reset the password following https://docs.gitlab.com/ee/security/reset_user_password.html#reset-your-root-password.

-#3.1查看密码(给记下来)
[root@gitlab ~]# cat /etc/gitlab/initial_root_password
# WARNING: This value is valid only in the following conditions
#          1. If provided manually (either via `GITLAB_ROOT_PASSWORD` environment variable or via `gitlab_rails['initial_root_password']` setting in `gitlab.rb`, it was provided before database was seeded for the first time (usually, the first reconfigure run).
#          2. Password hasn't been changed manually, either via UI or via command line.
#
#          If the password shown here doesn't work, you must reset the admin password following https://docs.gitlab.com/ee/security/reset_user_password.html#reset-your-root-password.

Password: cilOMbPer+Lc+LE8FD3KfY3u/2rXnRxGm1kBFiP4YFU=

# NOTE: This file will be automatically deleted in the first reconfigure run after 24 hours.



# 4.启动服务
[root@gitlab ~]# gitlab-ctl start

# 5.查看状态(看看起了那些服务)(这是优化过后的,少了很多)
[root@gitlab code]# gitlab-ctl start
ok: run: gitaly: (pid 26393) 7625s
ok: run: gitlab-kas: (pid 26399) 7623s
ok: run: gitlab-workhorse: (pid 26406) 7623s
ok: run: logrotate: (pid 37082) 733s
ok: run: nginx: (pid 25969) 7788s
ok: run: postgresql: (pid 25623) 7905s
ok: run: puma: (pid 33616) 2512s
ok: run: redis: (pid 25520) 7927s
ok: run: sidekiq: (pid 33578) 2519s

# 6.浏览器访问

Username: root
Password: cilOMbPer+Lc+LE8FD3KfY3u/2rXnRxGm1kBFiP4YFU=

操作

操作命令

# 查看状态
[root@gitlab ~]# gitlab-ctl status

# 重/启动/停止
[root@gitlab ~]# gitlab-ctl start
[root@gitlab ~]# gitlab-ctl restart
[root@gitlab ~]# gitlab-ctl stop

# 指定重/启动/停止某个服务
[root@gitlab ~]# gitlab-ctl start nginx
[root@gitlab ~]# gitlab-ctl restart nginx
[root@gitlab ~]# gitlab-ctl stop nginx

# 重新加载
[root@gitlab ~]# gitlab-ctl reconfigure 

# 查看日志
[root@gitlab ~]# gitlab-ctl tail nginx

# Json格式查看所有配置
[root@gitlab ~]# gitlab-ctl show-config

# 查看所有启动的服务
[root@gitlab ~]# gitlab-ctl service-list
alertmanager
gitaly*
gitlab-exporter
gitlab-kas*
gitlab-workhorse*
logrotate*
nginx*
node-exporter
postgres-exporter
postgresql*
prometheus
puma*
redis*
redis-exporter
sidekiq*

# 进入终端命令行
[root@gitlab ~]#  gitlab-rails console

发邮件测试

# 进入终端命令行
[root@gitlab ~]#  gitlab-rails console
--------------------------------------------------------------------------------
 Ruby:         ruby 3.0.6p216 (2023-03-30 revision 23a532679b) [x86_64-linux]
 GitLab:       16.2.4 (deac0811459) FOSS
 GitLab Shell: 14.23.0
 PostgreSQL:   13.11
------------------------------------------------------------[ booted in 51.85s ]
Loading production environment (Rails 7.0.6)
irb(main):001:0> Notify.test_email('1724723586@qq.com','gitlab test','测试').deliver_now
Delivered mail 64e6d669a4b14_96a32df0237ae@gitlab.mail (1306.4ms)
=> #<Mail::Message:495280, Multipart: false, Headers: <Date: Thu, 24 Aug 2023 12:02:49 +0800>, <From: gitlab <1724723586@qq.com>>, <Reply-To: gitlab <noreply@10.0.0.91>>, <To: 1724723586@qq.com>, <Message-ID: <64e6d669a4b14_96a32df0237ae@gitlab.mail>>, <Subject: gitlab test>, <Mime-Version: 1.0>, <Content-Type: text/html; charset=UTF-8>, <Content-Transfer-Encoding: 7bit>, <Auto-Submitted: auto-generated>, <X-Auto-Response-Suppress: All>>
irb(main):002:0>

修改密码(忘记密码)

# 查询id为1的用户
irb(main):002:0> User.where(id: 1).first
=> #<User id:1 @root>


# 忘记gitlab root密码
-# 进入终端命令行
[root@gitlab ~]#  gitlab-rails console
irb(main):008:0> user = User.where(id:1).first
=> #<User id:1 @root>
irb(main):009:0> user.password = 'wxk12345'
=> "wxk12345"
irb(main):010:0> user.password_confirmation = 'wxk12345'
=> "wxk12345"
irb(main):011:0> user.save
=> true

-#浏览器访问登陆试试

alertmanager['admin_email'] = 'admin@example.com'

gitlab图形化使用教程

汉化

git私有远程仓库gitlab_gitlab图形化_03

git私有远程仓库gitlab_git私有远程仓库gitlab_04

git私有远程仓库gitlab_git私有远程仓库gitlab_05

创建项目

项目——新创建项目——创建空白项目

git私有远程仓库gitlab_gitlab图形化_06

创建完成后,会有教程文档

git私有远程仓库gitlab_git私有远程仓库gitlab_07

上传代码
# 安装git
[root@gitlab ~]# yum install -y git

# 创建代码目录
[root@gitlab ~]# mkdir /code
[root@gitlab ~]# cd /code/

# 把代码目录初始化成git仓库
[root@gitlab code]# git init .
Initialized empty Git repository in /code/.git/

# 全局执行(一个项目执行一次) (收件箱)
[root@gitlab code]# git config --global user.name "Administrator"
[root@gitlab code]# git config --global user.email "1724723586@qq.com"

# 查看一下
[root@gitlab code]# cat .git/config 
[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true

没有则添加一下远程仓库

# 添加远程仓库
[root@gitlab code]# git remote add origin git@10.0.0.91:root/code.git

# 编写代码
[root@gitlab code]# ll
total 12
-rw-r--r-- 1 root root 370 Aug 23 18:58 index.html
-rw-r--r-- 1 root root 212 Aug 23 18:59 main.js
-rw-r--r-- 1 root root 964 Aug 23 19:05 style.css

# 上传提交代码

先添加了密钥后才能上传

点头像——偏好设置——SSH密钥

git私有远程仓库gitlab_git私有远程仓库gitlab_08

查看密钥后把密钥贴进去

配置ssh秘钥(谁想提交代码或者拉代码,谁就要把公钥放到git仓库)(xshell、Windows配置密钥教程在视频CICD-day03-03)

# 如果没有密钥:
-#生成公钥
[root@gitlab code]# ssh-keygen
-#查看公钥
[root@gitlab code]# cat ~/.ssh/id_rsa.pub

git私有远程仓库gitlab_git私有远程仓库gitlab_09

# 编辑完代码进行上传提交
[root@gitlab code]# git add .
[root@gitlab code]# git commit -m '第一次提交'
[master (root-commit) eba1ae1] 第一次提交
 3 files changed, 50 insertions(+)
 create mode 100644 index.html
 create mode 100644 main.js
 create mode 100644 style.css


# 推到gitlab上
[root@gitlab code]# git push --set-upstream origin --all

The authenticity of host '10.0.0.91 (10.0.0.91)' can't be established.
ECDSA key fingerprint is SHA256:+ozJmvMO+DwxKlqEHJ0fjVFlw1gjRAKORTqesgNgrxI.
ECDSA key fingerprint is MD5:78:ba:12:56:24:52:ad:78:59:46:a1:85:e5:3d:72:15.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.0.0.91' (ECDSA) to the list of known hosts.
Counting objects: 5, done.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 1.23 KiB | 0 bytes/s, done.
Total 5 (delta 0), reused 0 (delta 0)
To git@10.0.0.91:root/code.git
 * [new branch]      master -> master
Branch master set up to track remote branch master from origin.


# 如果后续有改动
[root@gitlab code]# git add --all
[root@gitlab code]# git commit -m '第二次提交'
[master 4dfad0c] 第二次提交
 2 files changed, 2 insertions(+), 2 deletions(-)
—#这里直接push(不用指定,除非换项目)
[root@gitlab code]# git push

注意!在gitlab里是main分支,我这里的master分支是因为代码是码云里面的打包过来用的

git私有远程仓库gitlab_git私有远程仓库gitlab_10

创建用户

头像——你的工作——管理中心——新建用户

git私有远程仓库gitlab_gitlab图形化_11

git私有远程仓库gitlab_gitlab图形化_12

git私有远程仓库gitlab_git私有远程仓库gitlab_13

方式二

git私有远程仓库gitlab_git私有远程仓库gitlab_14

git私有远程仓库gitlab_gitlab图形化_15

git私有远程仓库gitlab_gitlab图形化_16

创建群组

git私有远程仓库gitlab_gitlab图形化_17

git私有远程仓库gitlab_git私有远程仓库gitlab_18

邀请成员进项目

git私有远程仓库gitlab_git私有远程仓库gitlab_19

git私有远程仓库gitlab_gitlab图形化_20

git私有远程仓库gitlab_gitlab图形化_21