文章目录
展开gitlab介绍
私有代码仓库 ,除了gitlab以外 还有gogs
精细化的权限配置
控制用户/用户组权限,避免任何用户都可以将代码提交到master
CentOS中发邮件的服务:
-
sendmail
-
postfix
-
sendEmail
gitlab安装配置
##安装gitlab(清华源的rpm包)
[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
## 修改配置文件
## 修改邮箱配置文件
[root@gitlab ~]# vim /etc/gitlab/gitlab.rb
external_url 'http://gitlab.wodeyumengouwo.com'
### Email Settings
gitlab_rails['gitlab_email_enabled'] = true
gitlab_rails['gitlab_email_from'] = '1637991558@qq.com'
gitlab_rails['gitlab_email_display_name'] = 'gitlab'
## 邮件发送配置(类似于mail.rc中的配置)
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.qq.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "1637991558@qq.com"
gitlab_rails['smtp_password'] = "QQ邮箱授权码"
gitlab_rails['smtp_domain'] = "qq.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = false
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
##重新加载配置文件
[root@gitlab ~]# gitlab-ctl reconfigure
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.
##查看密码
[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: VDc7mk5P/ynYQgp0Ak8aFXWUotTujyWDBRfXsd6jYds=
##访问网站:http://gitlab.wodeyumengouwo.com
gitlab操作
## 查看状态
[root@gitlab ~]# gitlab-ctl status
run: alertmanager: (pid 5775) 363s; run: log: (pid 5466) 489s
run: gitaly: (pid 5663) 383s; run: log: (pid 4938) 608s
run: gitlab-exporter: (pid 5754) 367s; run: log: (pid 5387) 509s
run: gitlab-kas: (pid 5732) 370s; run: log: (pid 5135) 589s
run: gitlab-workhorse: (pid 5740) 370s; run: log: (pid 5294) 531s
run: logrotate: (pid 4865) 621s; run: log: (pid 4873) 620s
run: nginx: (pid 5304) 528s; run: log: (pid 5318) 524s
run: node-exporter: (pid 5747) 369s; run: log: (pid 5360) 515s
run: postgres-exporter: (pid 5783) 363s; run: log: (pid 5499) 479s
run: postgresql: (pid 4990) 598s; run: log: (pid 5059) 595s
run: prometheus: (pid 5761) 366s; run: log: (pid 5438) 496s
run: puma: (pid 5213) 547s; run: log: (pid 5221) 543s
run: redis: (pid 4895) 616s; run: log: (pid 4921) 613s
run: redis-exporter: (pid 5756) 367s; run: log: (pid 5408) 504s
run: sidekiq: (pid 5242) 541s; run: log: (pid 5250) 540s
## 连接gitlab终端
[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 62.10s ]
Loading production environment (Rails 7.0.6)
##测试发送邮件
irb(main):003:0> Notify.test_email('1637991558@qq.com','gitlab test','测试').deliver_now
# 退出终端
irb(main):003:0> exit
## 重启所有服务
[root@gitlab ~]# gitlab-ctl restart
# 停止所有服务
[root@gitlab ~]# gitlab-ctl stop
# 启动所有服务
[root@gitlab ~]# gitlab-ctl start
## 重启指定服务
[root@gitlab ~]# gitlab-ctl restart nginx
## 启动指定服务
[root@gitlab ~]# gitlab-ctl start nginx
## 停止指定服务
[root@gitlab ~]# gitlab-ctl stop nginx
## 查看指定组件日志
[root@gitlab ~]# gitlab-ctl tail nginx
## 查看所有组件日志
[root@gitlab ~]# gitlab-ctl tail
## 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密码
##连接终端
[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 24.59s ]
Loading production environment (Rails 7.0.6)
irb(main):001:0>
## 查询id为1的用户
irb(main):001:0> User.where(id: 1).first
=> #<User id:1 @root>
## 设置变量
irb(main):002:0> user = User.where(id:1).first
=> #<User id:1 @root>
##设置新密码
irb(main):003:0> user.password = 'zdh12345678'
=> "zdh12345678"
##确认新密码
irb(main):004:0> user.password_confirmation = 'zdh12345678'
=> "zdh12345678"
##保存修改
irb(main):005:0> user.save
=> true
gitlab汉化
- 当前版本汉化
点击左侧栏右上角小头像选择preferences
下拉找到language选择简体中文点击save changes保存后刷新页面
- 其他版本(需要汉化网站有的版本)
汉化网站:TP
- 选择版本
- 复制下载链接地址
# 1.下载汉化包
[root@gitlab ~]# wget https://gitlab.com/xhang/gitlab/-/archive/12-3-stable-zh/gitlab-12-3-stable-zh.tar.gz
# 2.解压汉化包
[root@gitlab ~]# tar xf gitlab-12-3-stable-zh.tar.gz
# 3.停止所有服务
[root@gitlab ~]# gitlab-ctl stop
# 4.覆盖
[root@gitlab ~]# \cp -a gitlab-12-3-stable-zh/* /opt/gitlab/embedded/service/gitlab-rails/
# 5.重新加载配置文件
[root@gitlab ~]# gitlab-ctl reconfigure
# 6.启动所有服务
[root@gitlab ~]# gitlab-ctl start
## 刷新网页
创建项目
- 点击左上角进入主页创建项目
- 创建空白项目
## 命令行指令
Git 全局设置
git config --global user.name "Administrator"
git config --global user.email "admin@example.com"
创建一个新仓库
git clone git@gitlab.wodeyumengouwo.com:root/code.git
cd code
git switch --create main
touch README.md
git add README.md
git commit -m "add README"
git push --set-upstream origin main
推送现有文件夹
cd existing_folder
git init --initial-branch=main
git remote add origin git@gitlab.wodeyumengouwo.com:root/code.git
git add .
git commit -m "Initial commit"
git push --set-upstream origin main
推送现有的 Git 仓库
cd existing_repo
git remote rename origin old-origin
git remote add origin git@gitlab.wodeyumengouwo.com:root/code.git
git push --set-upstream origin --all
git push --set-upstream origin --tags
添加git远程仓库
##下载git
[root@gitlab ~]# yum install -y git
##全局设置(收件箱)
[root@gitlab ~]# git config --global user.name 'admin'
[root@gitlab ~]# git config --global user.email '1637991558@qq.com'
##添加
[root@gitlab code]# git remote add origin git@gitlab.wodeyumengouwo.com:root/root.git
## 生成密钥
[root@gitlab ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:1J7i6gf7JsGBxKi4s8pE71W0vQoDYxFABRkyxUoVdb8 root@gitlab
The key's randomart image is:
+---[RSA 2048]----+
|+BOBo. . |
|.+o + . .. |
|oo o . .... |
|+ o o.o... |
| o + . +SEo |
|+ o o =. .. |
| + . + +.. |
|+ . . =.+ |
|o. . .o*. |
+----[SHA256]-----+
## 查看公钥
[root@gitlab ~]# cat .ssh/id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC5Fy1WBJEMPzLoBZUDs+h2sj0Q/wT3ZC428VP+rJq+0Xnq1vfdv4wv4HT/+4xpI48t5+74owhloOCdkNxLxgUEBJJggXThf7L/rcJAQqMfkHS5IxvSubjQK5nLmUdYVJfVGD9siJjNdwgd5rWe7IQiAGbMg0HqNV+TrjMNoDKmIf8VfcB3l9MKO7yCoSI9KUQIKQ2LClM25d7wUaF99DBsS7wHgl+Rr2XInyuLDsJl7hLz+xC91B2dtjiJq5vqqHWtL81nmqpLjg1qkzwPrfZyLQ13P6ACe4+RTdPk/KMJjWCBsWWVaIAxZziENuXgz+D2nnBE0KPHPqGTGy3fgbMD root@gitlab
##网页添加ssh
推送代码到远程仓库
[root@gitlab code]# git add .
[root@gitlab code]# git commit -m 'v2.0'
[master fc2b832] v2.0
1 file changed, 375 insertions(+)
create mode 100644 README.md
[root@gitlab code]# git push --set-upstream origin --all
[root@gitlab code]# git add .
[root@gitlab code]# git commit -m 'v2.0'
[master fc2b832] v2.0
1 file changed, 375 insertions(+)
create mode 100644 README.md
[root@gitlab code]# git push --set-upstream origin --all
下载git仓库中的代码
##克隆代码
[root@gitlab code]# git clone git@gitlab.wodeyumengouwo.com:root/root.git
## 同步仓库代码跟gitlab中保持一致(pull要先克隆 才能同步)
[root@gitlab root]# git pull
## 拉取所有分支
[root@gitlab root]# git fetch -vp
From gitlab.wodeyumengouwo.com:root/root
= [up to date] master -> origin/master
= [up to date] ceo_branch -> origin/ceo_branch
= [up to date] mishu_branch -> origin/mishu_branch
创建群组
##克隆代码
[root@gitlab code]# git clone git@gitlab.wodeyumengouwo.com:root/root.git
## 同步仓库代码跟gitlab中保持一致(pull要先克隆 才能同步)
[root@gitlab root]# git pull
## 拉取所有分支
[root@gitlab root]# git fetch -vp
From gitlab.wodeyumengouwo.com:root/root
= [up to date] master -> origin/master
= [up to date] ceo_branch -> origin/ceo_branch
= [up to date] mishu_branch -> origin/mishu_branch
Comments | NOTHING