GitLab

Git服务器

一、概念

  • C/S 架构的 Git 服务端
  • 是存放代码的公用平台
  • 是多人并行协作的核心部分
  • 通常单独部署在一台独立的服务器上
  • 客户端可以通过网络访问服务器上的仓库

GitLab搭建

一、部署

1、安装依赖包

复制代码
[root@GitLab ~]# yum -y install policycoreutils-python-utils.noarch

2、安装gitlab-ce包

复制代码
[root@GitLab ~]# rpm -ivh --nodeps --force gitlab-ce-12.4.6-ce.0.el7.x86_64.rpm
[root@GitLab ~]# rpm -qa | grep gitlab
gitlab-ce-12.4.6-ce.0.el7.x86_64

3、GitLab配置

复制代码
# 重载GitLab应用配置
[root@GitLab ~]# gitlab-ctl reconfigure
...
Running handlers:
Running handlers complete
Chef Client finished, 527/1423 resources updated in 02 minutes 05 seconds
gitlab Reconfigured!

# 重启GitLab相关服务
[root@GitLab ~]# gitlab-ctl restart
ok: run: alertmanager: (pid 1975) 0s        //报警服务
ok: run: gitaly: (pid 1986) 1s              //Git后台服务
ok: run: gitlab-exporter: (pid 2014) 0s     //Prometheus数据采集器
ok: run: gitlab-workhorse: (pid 2020) 1s    //反向代理服务器
ok: run: grafana: (pid 2117) 0s             //数据可视化服务
ok: run: logrotate: (pid 2129) 0s           //日志文件管理服务
ok: run: nginx: (pid 2135) 1s               //静态WEB服务
ok: run: node-exporter: (pid 2142) 0s       //Prometheus数据采集器
ok: run: postgres-exporter: (pid 2148) 1s   //Prometheus数据采集器
ok: run: postgresql: (pid 2159) 0s          //数据库服务
ok: run: prometheus: (pid 2168) 0s          //Prometheus监控服务
ok: run: redis: (pid 2178) 1s               //缓存数据库服务
ok: run: redis-exporter: (pid 2183) 0s      //Prometheus数据采集器
ok: run: sidekiq: (pid 2192) 0s             //异步执行队列服务
ok: run: unicorn: (pid 2203) 0s             //Rails托管WEB服务

GitLab使用

一、GitLab初始化

管理员用户初始化

  • 管理员用户为root
  • 首次登陆需设置管理员密码
  • 登陆方式为浏览器访问
复制代码
# GitLab主机确认80端口被监听
[root@GitLab ~]# ss -anptul | grep :80
tcp   LISTEN 0      511          0.0.0.0:80        0.0.0.0:*    users:(("nginx",pid=11166,fd=7),("nginx",pid=11165,fd=7),("nginx",pid=11164,fd=7))  
[root@GitLab ~]# 

二、GitLab使用

1、用户管理

  • 可以通过用户管理创建多个用户
  • 可以设置用户权限

2、组管理

  • 当用户非常多时可以将用户进行分组
  • 可以对组进行权限控制
  • 可以对组内用户身份控制

3、项目管理

  • 服务器上可以托管多个项目(仓库)

  • 可以设置项目归属

  • 可以对不同的项目做权限控制

代码托管

一、GitLab与Git客户端关联

1、关联Git服务器与客户端

关联 Programer 主机的 myproject 仓库与 GitLab 服务器上创建的 myproject 项目

复制代码
# 参考提示命令"推送已有Git仓库部分"
[root@Programer ~]# cd myproject/
# 查看远程仓库关联信息
[root@Programer myproject]# git remote -v
# 关联远程项目
[root@Programer myproject]# git remote add origin http://192.168.88.20/devops/myproject.git
# 查看远程仓库关联信息
[root@Programer myproject]# git remote -v
origin  http://192.168.88.20/devops/myproject.git (fetch)
origin  http://192.168.88.20/devops/myproject.git (push)
# 推送本地仓库所有分支
[root@Programer myproject]# git push -u origin --all
Username for 'http://192.168.88.20': mark       #用户名
Password for 'http://mark@192.168.88.20':       #密码
枚举对象中: 29, 完成.
对象计数中: 100% (29/29), 完成.
使用 2 个线程进行压缩
压缩对象中: 100% (19/19), 完成.
写入对象中: 100% (29/29), 2.21 KiB | 2.21 MiB/s, 完成.
总共 29(差异 5),复用 0(差异 0),包复用 0
remote: 
remote: To create a merge request for feature, visit:
remote:   http://gitlab.example.com/devops/myproject/merge_requests/new?merge_request%5Bsource_branch%5D=feature
remote: 
remote: To create a merge request for hotfix, visit:
remote:   http://gitlab.example.com/devops/myproject/merge_requests/new?merge_request%5Bsource_branch%5D=hotfix
remote: 
To http://192.168.88.20/devops/myproject.git
 * [new branch]      feature -> feature
 * [new branch]      hotfix -> hotfix
 * [new branch]      master -> master
分支 'feature' 设置为跟踪来自 'origin' 的远程分支 'feature'。
分支 'hotfix' 设置为跟踪来自 'origin' 的远程分支 'hotfix'。
分支 'master' 设置为跟踪来自 'origin' 的远程分支 'master'。

# 推送本地仓库所有标签
[root@Programer myproject]# git push -u origin --tags
Username for 'http://192.168.88.20': mark       #用户名
Password for 'http://mark@192.168.88.20':       #密码
总共 0(差异 0),复用 0(差异 0),包复用 0
To http://192.168.88.20/devops/myproject.git
 * [new tag]         v1 -> v1

二、关联后效果展示

三、客户端免密推送

1、配置HTTP访问免密推送

复制代码
#每次推送都需要认证,可以设置免密推送
    #store:永久存储
    #cache:默认缓存15分钟,期间无需认证,可通过cache --timeout=3600设置超时时间
    #git remote add origin http://name:pass@192.168.88.20/devops/myproject.git
[root@Programer myproject]# git config --global credential.helper store #持久保存
[root@Programer myproject]# git push                        #推送代码(本次需要认证)
Username for 'http://192.168.88.20': mark   #用户名
Password for 'http://mark@192.168.88.20':   #密码
Everything up-to-date
[root@Programer myproject]# git push                        #再次推送测试免密
Everything up-to-date
[root@Programer myproject]# git config --list
user.name=mark
user.email=mark@tedu.cn
init.defaultbranch=master
credential.helper=store
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
remote.origin.url=http://192.168.88.20/devops/myproject.git
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.feature.remote=origin
branch.feature.merge=refs/heads/feature
branch.hotfix.remote=origin
branch.hotfix.merge=refs/heads/hotfix
branch.master.remote=origin
branch.master.merge=refs/heads/master
[root@Programer myproject]# cat ~/.git-credentials 
http://mark:1234.com@192.168.88.20
相关推荐
Ruiery5 小时前
Linux 6.6内核 CPU 深度解析(七):调度器启动 — 从单核到多核,调度器分阶段点亮
linux·运维·服务器
50万马克的面包5 小时前
CSDN-栈队列数组-知识点整理
linux·运维·服务器
MicrosoftCloud6 小时前
用户权限 04|/etc/sudoers 安全配置:从最小授权到「别把 ALL 随便给人」
运维·安全·ubuntu·sudo·sudoers
wjkjpcba6 小时前
PCBA烧录程序是什么:PCBA包工包料厂家解析烧录与测试
linux·数据库·人工智能·smt贴片加工·pcba贴片加工厂
꯭自꯭闭꯭7 小时前
达梦事物特性及MVCC
linux·运维·数据库
亚川楼宇自控系统数据中心厂家8 小时前
实验室智能化管理系统|人环物智一体化管控平台
运维
羔羊++8 小时前
18_实验十七_其他命令与自定义启动变量
linux
zmsup10 小时前
Agent 上下文调优:结合 OpsArk 运维智能体,设计模型每一步真正需要的信息
运维·agent·上下文压缩·运维智能体·上下文调优
DYWorker00111 小时前
Linux驱动:RK3568 GMAC + YT8531C 千兆以太网全流程解剖
linux
吴声子夜歌12 小时前
Nginx应用与运维——Nginx负载均衡应用实战(二)
运维·nginx·负载均衡