CentOS 私有远程仓库Gitlab
  rYbDpQnHh4bw 2023年11月02日 47 0

私有远程仓库Gitlab

gitlab介绍

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

gitlab的架构

image.png

部署gitlab-ce

image.png

image.png

## 使用清华源,直接安装
[root@auto01 ~]# wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-12.3.5-ce.0.el7.x86_64.rpm --no-check-certificate

[root@auto01 ~]# yum localinstall -y gitlab-ce-10.2.2-ce.0.el7.x86_64.rpm

## 安装过程
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

For a comprehensive list of configuration options please see the Omnibus GitLab readme
https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md

# 1.修改配置文件
[root@auto01 ~]# vim /etc/gitlab/gitlab.rb
external_url 'http://gitlab.wsh.com'
gitlab_rails['gitlab_email_enabled'] = true
gitlab_rails['gitlab_email_from'] = '540080971@qq.com'
gitlab_rails['gitlab_email_display_name'] = 'wsh gitlab notice'

gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.qq.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "540080971@qq.com"
gitlab_rails['smtp_password'] = "prnqbkmvennpbegf"
gitlab_rails['smtp_domain'] = "qq.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true

prometheus['enable'] = false
prometheus['monitor_kubernetes'] = false
prometheus_monitoring['enable'] = false
node_exporter['enable'] = false
redis_exporter['enable'] = false
postgres_exporter['enable'] = false

grafana['enable'] = false
alertmanager['enable'] = false

# 2.重新加载配置文件
[root@auto01 ~]# gitlab-ctl reconfigure
Chef Client finished, 1/500 resources updated in 14 seconds
gitlab Reconfigured!

gitlab操作

# 查看当前服务状态
[root@auto01 ~]# gitlab-ctl status
run: gitaly: (pid 1238) 0s; run: log: (pid 1235) 0s
run: gitlab-workhorse: (pid 1237) 0s; run: log: (pid 1236) 0s
run: logrotate: (pid 6059) 514s; run: log: (pid 1245) 0s
run: nginx: (pid 1241) 0s; run: log: (pid 1239) 0s
run: postgresql: (pid 1229) 0s; run: log: (pid 1227) 0s
run: redis: (pid 1242) 0s; run: log: (pid 1240) 0s
run: sidekiq: (pid 1231) 0s; run: log: (pid 1230) 0s
run: unicorn: (pid 1234) 0s; run: log: (pid 1233) 0s

# 停止所有服务
[root@auto01 ~]# gitlab-ctl stop

# 启动所有服务
[root@auto01 ~]# gitlab-ctl start

# 重启所有服务
[root@auto01 ~]# gitlab-ctl restart

# 重启指定服务
[root@auto01 ~]# gitlab-ctl restart nginx

# 停止指定服务
[root@auto01 ~]# gitlab-ctl stop nginx

# 启动指定服务
[root@auto01 ~]# gitlab-ctl start nginx

# 查看gitlab所有组件日志
[root@auto01 ~]# gitlab-ctl tail

# 查看gitlab指定组件日志
[root@auto01 ~]# gitlab-ctl tail nginx

# 连接gitlab终端
[root@auto01 ~]# gitlab-rails console

## 测试发邮件
irb(main):002:0> Notify.test_email('wsh540080971@163.com','gitlab test','').deliver_now

image.png

[root@auto01 ~]# gitlab-rails console
## 登录root用户
irb(main):011:0> user = User.where(id: 1).first
irb(main):012:0> user.password='123456789'
irb(main):012:0> user.password_confirmation='123456789'
irb(main):012:0> user.save

## 打开浏览器访问

image.png

image.png

image.png

gitlab汉化

汉化网站:TP

image.png

## 1.下载汉化包
[root@auto01 ~]# wget https://gitlab.com/xhang/gitlab/-/archive/v12.3.5-zh/gitlab-v12.3.5-zh.tar.gz

## 2.解压汉化包
[root@auto01 ~]# tar xf gitlab-v12.3.5-zh.tar.gz

## 3.停止所有服务
[root@auto01 ~]# gitlab-ctl stop

## 4.覆盖
[root@auto01 ~]# \cp -a gitlab-v12.3.5-zh/* /opt/gitlab/embedded/service/gitlab-rails/
[root@auto01 ~]# cp -r gitlab-v12.3.5-zh/log /opt/gitlab/embedded/service/gitlab-rails/log
[root@auto01 ~]# cp -r gitlab-v12.3.5-zh/tmp /opt/gitlab/embedded/service/gitlab-rails/tmp

## 5.windows域名解析
10.0.0.81 gitlab.wsh.com

## 6.重新加载配置文件
[root@auto01 ~]# gitlab-ctl reconfigure

## 7.启动所有服务
[root@auto01 ~]# gitlab-ctl start

image.png

image.png

创建项目

image.png

image.png

image.png

## 网页添加ssh秘钥
[root@auto01 web]# ssh-keygen
[root@auto01 web]# cat ~/.ssh/id_rsa.pub 
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCvNirz5qwXW6xjms/rgAKtEgqtzizFAwsIuwop7Rsp3otIiStvOsecpwrFVMvt60GLRfv2a42FB7YruCTcLiaqGU3uKhQ4rXTXEczAiWg6UbJENZAVFFzZNVA8xJcBZEaSMQskttijnmzUHuNdhJBVwCtPJmZC9ig7HKT+2gtrLjYpwL8UdYdRsigW/+vs+aC98vGyj0ARLRKAHde3clDfkjGrl7FxYPmMshK08kZw8WMvXT/5y+UIUGTDlmom/n32VBRXATrSKNQDfDZtm2OoX2gRIv4XHzTnq3II3NvIwYdbfFakHhop0K/8eX+8DPtwS/8FuH3yBtjJzc9U1k33 root@auto01

image.png

image.png

## 全局设置
[root@auto01 ~]# git config --global user.name "Administrator"
[root@auto01 ~]# git config --global user.email "admin@example.com"

## 推送现有的 Git 仓库
[root@auto01 ~]# cd /web/
[root@auto01 web]# git remote rename origin old-origin
[root@auto01 web]# git remote add origin git@gitlab.wsh.com:root/git-test.git
[root@auto01 web]# git push -u origin --all
[root@auto01 web]# git push -u origin --tags

image.png

gitlab创建用户和用户组

image.png

image.png

image.png

image.png

image.png

image.png

image.png

image.png

image.png

image.png

image.png

image.png

image.png

image.png

image.png

image.png

下载git仓库中的代码

image.png

## 创建目录
[root@auto01 ~]# mkdir test

## 克隆代码
[root@auto01 ~]# cd test/
[root@auto01 test]# git clone  git@gitlab.wsh.com:root/git-test.git
Cloning into 'git-test'...
remote: Enumerating objects: 31, done.
remote: Counting objects: 100% (31/31), done.
remote: Compressing objects: 100% (30/30), done.
remote: Total 31 (delta 7), reused 0 (delta 0)
Receiving objects: 100% (31/31), done.
Resolving deltas: 100% (7/7), done.

## 同步仓库代码跟gitlab中保持一致
[root@auto01 git-test]# git pull

## 拉所有分支代码
[root@auto01 git-test]# git fetch -vp
From gitlab.wsh.com:root/git-test
 = [up to date]      master     -> origin/master
 = [up to date]      ceo_branch -> origin/ceo_branch
 = [up to date]      mishu_branch -> origin/mishu_branch
【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  4koL3J55wyKx   2023年11月13日   35   0   0 icogitCentOS
  9E2BTpjt8nym   2023年12月06日   34   0   0 WindowsgitCentOS
  3M67F8YJLxn2   2023年11月13日   30   0   0 vimgitc++
rYbDpQnHh4bw