gitlab远程仓库
Gitlab
概述
Gitlab 是一个用于仓库管理系统的开源项目,是代码管理工具服务组成
- nginx 静态服务器
- gitlab-shell 用于处理git命令和修改authorized keys列表(ruby)
- gitlab-workhorse 轻量级反向代理服务器,会处理一些大的http请求,比如上传,下载(push/pull)和git包下载,其他请求会反向代理到gitlab rails应用,及反向代理给后端的unicorn(托管软件)
- logrotae 日志管理工具
- postgresql 数据库工具
- redis 缓存数据库工具
- sidekiq 用于在后台执行队列任务
- unicorn http服务器 gitlab rails应用托管在这里 有Ruby编写
- 工作流程
- 配置文件
/opt/gitlab ## gitlab主目录 /etc/gitlab ## 配置文件目录 /var/opt/gitlab ## 存放各个组件的目录 /var/log/gitlab ## 存放日志文件的目录
Gitlab 安装
准备环境
linux主机 | IP 192.168.100.200
—– | —–- 运行内存4G 两个核心 并且已经安装git
- gitlab版本
gitlab-ce-12.3.0-ce.0.el7.x86_64
[root@localhost ~]# rpm -ivh gitlab-ce-12.3.0-ce.0.el7.x86_64.rpm # 直接rpm安装,如果有依赖,就yum安装
- gitlab 命令
gitlab-ctl start/stop # 开启/关闭gitlab
gitlab-ctl start/stop 组件名 # 开启/关闭某个组件
gitlab-ctl tail # 查看gitlab日志
gitlab-ctl tail 组件名 # 查看gitlab某组件日志
gitlab-ctl reconfigure # 重新编译 ,修改完配置文件后执行。
gitlab-ctl status # 查看gitlab的状态
基础配置和首次登录设置
[root@localhost ~]# vim /etc/gitlab/gitlab.rb # 修改 external_url 'http://192.168.100.200' # 虚拟环境下写主机的ip就可以,如果是生产环境,就写主机的域名 wq # 保存退出 [root@localhost ~]# gitlab-ctl reconfigure # 重新编译 [root@localhost ~]# gitlab-ctl start # 启动gitlab
* 浏览器访问linux主机ip,登录到gitlab web管理界面
http://192.168.100.200
如果登录进不了web界面,尝试放行80,8080端口设置密码 最少八位 默认用户为root
Gitlab数据备份和恢复
- 备份数据
[root@localhost ~]# gitlab-rake gitlab:backup:create # 创建备份 [root@localhost ~]# ls /var/opt/gitlab/backups/ 1584167831_2020_03_14_12.3.0_gitlab_backup.tar # /var/opt/gitlab/backups/ 备份数据的存放目录
- 数据恢复
[root@localhost ~]# gitlab-ctl stop unicon # 停止托管功能 [root@localhost ~]# gitlab-ctl stop sidekiq # 停止消息队列功能 # 停止这两个组件的原因是防止数据紊乱 [root@localhost ~]# gitlab-rake gitlab:backup:restore BACKUP=1584167831_2020_03_14_12.3.0 # 恢复备份的数据 # 在恢复之前gitlab会清除所有的数据,然后再将备份的数据恢复 # 开启之前关闭的两个组件 [root@localhost ~]# gitlab-ctl start unicon [root@localhost ~]# gitlab-ctl start sidekiq
管理员密码恢复
- 密码忘记时
[root@localhost ~]# gitlab-rails console # 进到gitlab终端 # -------------------------------------------------------------------------------- GitLab: 12.3.0 (7099ecf77cb) GitLab Shell: 10.0.0 PostgreSQL: 10.9 # -------------------------------------------------------------------------------- Loading production environment (Rails 5.2.3) irb(main):001:0> user = User.where(id:1).first # 切换到id是1的root用户 => #<User id:1 @root> irb(main):002:0> user.password='12345678' # 强制修改密码为12345678 => "12345678" irb(main):003:0> user.save! # 保存 Enqueued ActionMailer::DeliveryJob (Job ID: 6460a86e-b0cf-4ea1-994f-bf4a67c5b8dc) to Sidekiq(mailers) with arguments: "DeviseMailer", "password_change", "deliver_now", #<GlobalID:0x00007f079c37fd20 @uri=#<URI::GID gid://gitlab/User/1>> => true irb(main):004:0> exit # 退出
Gitlab Web界面使用
创建用户
创建组
创建项目
往项目里添加文件
和github差不多
- 在主机生成秘钥
[root@localhost ~]# 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:nErtz98sTZ5S7S/5puIxNp1gwh1CfKsGUXWcrDRWrkg root@localhost.localdomain The key's randomart image is: +---[RSA 2048]----+ | oo..+o. | | ... =o+ | | .E+.+. | | o.+ +oo | | . S.+.= . | | . o oo oo..| | . .. ==o+ | | o .+** o| | ooo++=+| +----[SHA256]-----+ [root@localhost ~]# cat /root/.ssh/id_rsa.pub ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDakZr4ayqXb1+oIofBIk4GQUANLoPFlG9HEX5zGAXG/I30OI748Yu5ZrJFbaQadoDHpn0OlKfpvrbd5QjL9iCv4lhrbqp4jYgacCJEmK/Dns9TAgMzQ77wM9frR0WLHIVKT5WuQRYXn3zBiaK5Y4uMwV4ymFDgl16NyM/5OjIClixmCtWKQxNevM+NO0WrzCgZ0pLbjad/og1613VnUFuTf7F3W4A5ZRYbO14JvSzpMQpNC22/WLW7sIo8oyTGHKK3r8pUd2eo7gloZ+e7w3mZt1NdmGLd+pwE9b3beXmTDXXRnjxx/Gl6ST0YslgVBq0zC+4tKKqs/y7ZeUdChDSn root@localhost.localdomain # 把公钥复制到gitlab上
在主机创建一个本地git仓库
[root@localhost ~]# mkdir test # 创建本地仓库 [root@localhost ~]# cd test/ [root@localhost test]# git init # 初始化git仓库 初始化空的 Git 版本库于 /root/test/.git/ [root@localhost test]# git config --global user.email "1248287831@qq.com" #给本地仓库指定一个邮箱,让gitlab知道是谁上传的 [root@localhost test]# git config --global user.name "lmk" 指定一个名字 [root@localhost test]# git remote add origin git@192.168.100.200:hello/hello.git # 添加远程仓库 [root@localhost test]# echo lmk > 1.txt # 创建文件 [root@localhost test]# git add 1.txt # 添加到暂存区 [root@localhost test]# git commit -m "first" # 提交到本地仓库 [master(根提交) 5c97cdf] first 1 file changed, 1 insertion(+) create mode 100644 1.txt [root@localhost test]# git push origin master # 上传到远程仓库 The authenticity of host '192.168.100.200 (192.168.100.200)' can't be established. ECDSA key fingerprint is SHA256:lctkx1T1bLPxzCCYpVDcD4P7SvdrTR5LfZQpTBpVYfs. ECDSA key fingerprint is MD5:75:83:99:b3:7a:01:15:4b:43:62:2a:6e:16:78:78:45. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '192.168.100.200' (ECDSA) to the list of known hosts. Counting objects: 3, done. Writing objects: 100% (3/3), 200 bytes | 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) To git@192.168.100.200:hello/hello.git * [new branch] master -> master
查看gitlab
小结
- gitlab代码托管仓库和github非常相似 一般gitlab在公司都是存储私有项目的,gitlab存放开源的项目,不过也可存放私有项目
本博客所有文章是以学习为目的,如果有不对的地方可以一起交流沟通共同学习 邮箱:1248287831@qq.com!