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://[email protected]':       #密码
枚举对象中: 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://[email protected]':       #密码
总共 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:[email protected]/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://[email protected]':   #密码
Everything up-to-date
[root@Programer myproject]# git push                        #再次推送测试免密
Everything up-to-date
[root@Programer myproject]# git config --list
user.name=mark
[email protected]
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:[email protected]
相关推荐
姝孟19 分钟前
Linux学习笔记 1
linux·笔记·学习
清风~徐~来40 分钟前
【Linux】网络层协议 IP
linux·网络·tcp/ip
vortex51 小时前
探索 Shell 中的扩展通配符:从 Bash 到 Zsh
linux·运维·bash·shell·zsh
不爱学英文的码字机器1 小时前
[操作系统] 进程间通信:system V共享内存
linux·服务器·ubuntu
‍。。。1 小时前
Ubuntu 24.04 中文输入法安装
linux·运维·ubuntu
丁总学Java1 小时前
如何用 nvm alias default 18.20.8 实现全局 Node.js 版本管理?一篇保姆级指南!!!
linux·node.js·vim
Yang三少喜欢撸铁1 小时前
【Linux部署DHCP服务】
linux·运维·服务器
太极淘2 小时前
桌面版本及服务器版本怎么查看网络源软件包的url下载路径
运维·服务器·网络
Black_Rock_br2 小时前
Mac监控新风尚:酷炫界面,性能监控更直观!
运维·macos
程序员小软3 小时前
linux-添加开机自启动指定脚本
linux·运维