私有远程代码仓库-Gitlab
环境准备
主机名 | IP地址 | 角色 | 配置 |
---|---|---|---|
gitlab | 10.0.0.91 | 远程代码仓库 | 1H4G |
jenkins | 10.0.0.92 | 代码上线工具 | 1H4G |
gitlab介绍
-
私有代码仓库,除了gitlab以外还有gogs
-
精细化的权限配置
-
控制用户/用户组权限,避免任何用户都可以将代码提交到master
gitlab架构
gitlab下载
gitlab官网
中文版gitlab
https://gitlab.com/xhang/gitlab
清华源
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
# 编辑配置文件
[root@gitlab ~]# vim /etc/gitlab/gitlab.rb
32 external_url 'http://gitlab.xiaoyuanwiki.com'
## 邮箱配置
### 邮件发送配置(类似于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'] = "1060243063@qq.com"
89 gitlab_rails['smtp_password'] = "gmmfiyecfczkbdgd"
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
### 修改邮箱配置文件
105 gitlab_rails['gitlab_email_enabled'] = true
109 gitlab_rails['gitlab_email_from'] = '1060243063@qq.com'
110 gitlab_rails['gitlab_email_display_name'] = 'Gitlab'
## 在最后填写优化
### 关闭普罗米修斯
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
# 启动gitlab
[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.
[root@gitlab ~]# cat /etc/gitlab/initial_root_password
Password: 2KHqFAYgp14n0jdBYAjczBD8bF+L09Mf9TmWx2WeMb4=
# 检查gitlab状态
[root@gitlab ~]# gitlab-ctl status
run: gitaly: (pid 24419) 2674s; run: log: (pid 23763) 2790s
run: gitlab-kas: (pid 24434) 2667s; run: log: (pid 23958) 2776s
run: gitlab-workhorse: (pid 24441) 2667s; run: log: (pid 24110) 2732s
run: logrotate: (pid 23692) 2803s; run: log: (pid 23700) 2802s
run: nginx: (pid 28126) 41s; run: log: (pid 24138) 2727s
run: postgresql: (pid 23813) 2785s; run: log: (pid 23920) 2782s
run: puma: (pid 28055) 74s; run: log: (pid 24036) 2743s
run: redis: (pid 23729) 2797s; run: log: (pid 23738) 2796s
run: sidekiq: (pid 28019) 83s; run: log: (pid 24066) 2737s
打开浏览器访问页面
http://gitlab.xiaoyuanwiki.com
操作技巧
# Json格式查看所有配置
[root@gitlab ~]# gitlab-ctl show-config
# 查看所有启动的服务
[root@gitlab ~]# gitlab-ctl service-list
# 重启所有服务
[root@gitlab ~]# gitlab-ctl restart
# 重启指定服务
[root@gitlab ~]# gitlab-ctl restart nginx
# 停止指定服务
[root@gitlab ~]# gitlab-ctl stop nginx
# 查看所有日志
[root@gitlab ~]# gitlab-ctl tail
# 查看指定日志
[root@gitlab ~]# gitlab-ctl tail nginx
# 连接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 17.24s ]
Loading production environment (Rails 7.0.6)
irb(main):001:0>
## 发送邮箱在gitlab控制台操作
irb(main):001:0> Notify.test_email('1060243063@qq.com','gitlab test','测试').deliver_now
## 忘记密码时在gitlab控制台操作(需要8位数且包含两个字母及以上)
### 查询id为1的用户
irb(main):002:0> user = User.where(id: 1).first
=> #<User id:1 @root>
### 设置密码
irb(main):003:0> user.password = "ljy123456"
=> "ljy123456"
### 确认密码
irb(main):004:0> user.password_confirmation = "ljy123456"
=> "ljy123456"
### 保存密码
irb(main):005:0> user.save
=> true
# 标签(对最新上传的代码)
-a 设置标签名 如果需要指定可以写出对应版本名
-m 对标签的描述信息
[root@gitlab code]# git tag -a 'v1.4' -m '第一次上传'
# 标签操作流程
git add . (git add --all)
git commit -m '描述'
git tag -a '指定版本号或对最新上传的进行标签名设置' -m '指定描述'
git push --all (或者指定上传 #例:git push --tag)
git push --tag
# 删除git账号
git remote remove origin(用户名)
# 删除本地某个标签
git tag -d {标签名}
[root@gitlab code]# git tag -d v1.1
# 删除远程仓库某个标签
git push origin :refs/tags/{标签名}
[root@gitlab code]# git push origin :refs/tags/v1.1
修改成中文版
创建项目
配置ssh密钥(谁想提交代码或者拉代码,谁就要把公钥放在git仓库)
# 如果没有公钥,创建公钥
[root@db01 .ssh]# ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa >/dev/null 2>&1
# 查看公钥
[root@db01 .ssh]# cat ~/.ssh/id_dsa.pub
命令行指引
您还可以按照以下说明从计算机中上传现有文件。
Git 全局设置
git config --global user.name "Administrator"
git config --global user.email "admin@example.com"
创建一个新仓库
git clone http://gitlab.xiaoyuanwiki.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.xiaoyuanwiki.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.xiaoyuanwiki.com:root/code.git
git push --set-upstream origin --all
git push --set-upstream origin --tags
已有仓库(http)
# 安装git
[root@gitlab ~]# yum install -y git
# 导入配置
code.tar.gz
# 配置全局设置
[root@gitlab code]# git config --global user.name "Administrator"
[root@gitlab code]# git config --global user.email "1060243063@qq.com"
# 生成为gitlab仓库
[root@gitlab code]# git remote rename origin old-origin
[root@gitlab code]# git remote add origin http://gitlab.xiaoyuanwiki.com/root/code.git
# 第一次上传
[root@gitlab code]# git push --set-upstream origin --all
Username for 'http://gitlab.xiaoyuanwiki.com': root # git账号
Password for 'http://root@gitlab.xiaoyuanwiki.com': ljy123456 # git密码
# 安装git
[root@gitlab ~]# yum install -y git
# 创建git目录
[root@gitlab ~]# mkdir /code
# 创建为git仓库
[root@gitlab ~]# cd /code/
[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 "1060243063@qq.com"
# 生成为gitlab仓库
[root@gitlab code]# git remote rename origin old-origin
[root@gitlab code]# git remote add origin http://gitlab.xiaoyuanwiki.com/root/code.git
# 第一次上传
[root@gitlab code]# git push --set-upstream origin --all
Username for 'http://gitlab.xiaoyuanwiki.com': root # git账号
Password for 'http://root@gitlab.xiaoyuanwiki.com': ljy123456 # git密码
创建用户和群组
创建群组
创建用户
创建用户后收到设置密码邮箱
邀请成员
成员在组内展示
拓展
CentOS中发邮件的服务:
- sendmail
- postfix
- sendEmail
web应用
weblogic/nginx/apache/IIS