Linux에서 GitLab 설치 및 구성

Linux에서 GitLab 설치 및 구성

GitLab이란 무엇입니까?
GitLab은 창고 관리 시스템을위한 오픈 소스 프로젝트로 Git을 코드 관리 도구로 사용하고이를 기반으로 웹 서비스를 구축합니다.

GitLab의 기능적 특성은 애플리케이션
의 관리, 계획, 생성, 검증, 패키징, 게시, 구성, 모니터링 및 보호 기능을 제공합니다. 온라인 코드웨어 하우스 호스팅 소프트웨어이자 코드 호스팅, 제출 검토 및 발행을 제공하는 코드 관리 플랫폼입니다. 추적.

서버 요구 사항 : 권장 구성은 CPU2 코어, 메모리 4G 이상
입니다.
Git , GitLab 및 GitHub의 차이점. 명령을 기반으로하는 Git 버전 작업, 전체 명령 작업, 시각적 인터페이스 없음;

Gitlab은 기업 내에서 사용할 수있는 웹 관리 인터페이스를 제공하는 Git 기반의 온라인 코드웨어 하우스 소프트웨어입니다.

Github는 Git 기반의 온라인 코드웨어 하우스 소프트웨어로, 시각적 관리 인터페이스를 제공하고 개방형 및 개인용웨어 하우스를 제공합니다. 대부분의 오픈 소스 프로젝트는 코드 호스팅웨어 하우스로 Github를 선택합니다.

서비스 구성 요소
nginx : 정적 웹 서버 : 포트 번호는 80입니다.

gitlab-shell : git 명령을 처리하고 인증 된 키 목록을 수정하는 데 사용됩니다.

gitlab-workhorse : 경량 리버스 프록시 서버 (go 언어);

gitlab-workhorse는 민첩한 역방향 프록시로, 파일 업로드, 다운로드, git과 같은 대규모 HTTP 요청을 처리합니다.

푸시 / 풀 및 git 패키지 다운로드, 다른 요청은 gitlab rails 애플리케이션에 대한 역방향 프록시, 즉 백엔드에서 unicorn에 대한 역방향 프록시입니다.

logrotate : 로그 파일 관리 도구;

postgresql : 데이터베이스;

리드 : 캐시 데이터베이스;

sidekiq : 백그라운드에서 큐 작업을 실행하는 데 사용됩니다 (비동기 실행) (ruby);

unicorn : 루비로 작성된 HTTP 서버 : 포트 번호는 8080입니다.

gitlab rails 애플리케이션 :이 서버에서 호스팅 됨

기능 소개
웹 기반 관리 플랫폼;

완전한 권한 제어 및 신원 인증 모듈을 보유합니다.

문제 추적 및 코드 품질 관리

코드 리뷰 (리뷰) 기능;

문서 관리, 지식 기반 관리;

GitLab 설치 단계


[root@localhost ~]# ls /var/cache/yum/x86_64/\$releasever/gitlab_gitlab-ce/packages/     //从网络上yum下载的包的位置
[root@localhost ~]# yum install -y curl openssh-server openssh-clients cronie policycoreutils-python postfix     //安装依赖包
[root@localhost ~]# curl -s https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash   //下载gitlab的yum(仓库)源,sudo用于提权(适用于普通用户)
[root@localhost ~]# yum list | grep gitlab-ce           //查看是否有gitlab-ce
gitlab-ce.x86_64                        11.7.5-ce.0.el7            gitlabgitlab-ce
[root@localhost ~]# yum -y install gitlab-ce        //安装gitlab-ce 
[root@localhost ~]# ls /var/cache/yum/x86_64/\$releasever/gitlab_gitlab-ce/packages/     //从网络上yum下载的包的位置

###设置URL
[root@localhost ~]# vim /etc/gitlab/gitlab.rb  //修改一个URL地址
  external_url 'http://gitlab.bdqn.cn'
[root@localhost ~]# vim /etc/hosts  //编辑一个域名解析
  192.168.1.21    gitlab.bdqn.cn
[root@localhost ~]# gitlab-ctl reconfigure   //重新配置gitlab的配置文件

[root@localhost ~]# gitlab-ctl start   //启动gitlab服务
ok: run: alertmanager: (pid 5151) 363s
ok: run: gitaly: (pid 4934) 368s
ok: run: gitlab-monitor: (pid 5070) 366s
ok: run: gitlab-workhorse: (pid 4897) 370s
ok: run: logrotate: (pid 4120) 416s
ok: run: nginx: (pid 4071) 418s
ok: run: node-exporter: (pid 4974) 367s
ok: run: postgres-exporter: (pid 5178) 362s
ok: run: postgresql: (pid 3564) 458s
ok: run: prometheus: (pid 5111) 364s
ok: run: redis: (pid 3420) 464s
ok: run: redis-exporter: (pid 5090) 365s
ok: run: sidekiq: (pid 3934) 430s
ok: run: unicorn: (pid 3862) 431s
[root@localhost ~]# gitlab-ctl restart          //重新启动gitlab服务
[root@localhost ~]# free -m    //查看运行内存
[root@localhost ~]# firefox gitlab.bdqn.cn   //查看gitlab页面,或者使用ip地址访问
[root@localhost ~]# firefox 192.168.1.21

gitlab 페이지 문제, 포트 80, 8080 점유
여부 확인, 홈페이지 502 방문 포트 8080 점유 여부 확인


gitlab相关命令
gitlab-ctl start       //启动gitlab服务
gitlab-ctl stop        //停止gitlab服务
gitlab-ctl start unicorn(添加组件名称)   //单独开启某个组件
gitlab-ctl status        //查看gitlab的运行状态
gitlab-ctl reconfigure    //修改完配置文件重新编译
gitlab-ctl tail       //查看gitlab的日志

GitLab 메일 서비스
sendmail / postfix / smtp
고대 메일 함 메일 서비스 서버 온라인 메일 함 구성

SMTP 사서함을 구성하는 단계


###修改配置文件
[root@localhost ~]# vim /etc/gitlab/gitlab.rb
 gitlab_rails['gitlab_email_from'] = '[email protected]'   //说明邮箱从哪里发,设置自己的邮箱地址
 #ctrl+v 进入可视块 +x
 gitlab_rails['smtp_enable'] = true
 gitlab_rails['smtp_address'] = "smtp.163.com" //在线邮件服务器地址
 gitlab_rails['smtp_port'] = 25   //端口号,开启本地发邮件的端口
 gitlab_rails['smtp_user_name'] = "[email protected]"  //邮箱地址
 gitlab_rails['smtp_password'] = "qwerty567890"  //邮箱授权码,调用邮箱
 ###邮箱授权码的获取
 设置 
 POP3/SMTP/IMAP
 客户端授权密码,在里面就可以设置授权码

 gitlab_rails['smtp_domain'] = "163.com"
 gitlab_rails['smtp_authentication'] = "login"   //在登录时,查看是否有授权码
 gitlab_rails['smtp_enable_starttls_auto'] = true   //加密方式
 gitlab_rails['smtp_tls'] = false    //加密方式

  user['git_user_email'] = "[email protected]"
###修改完成

重新编译配置文件
[root@localhost ~]# gitlab-ctl reconfigure
重启gitlab服务
[root@localhost ~]# gitlab-ctl restart
进入控制台
[root@localhost ~]# gitlab-rails console
-------------------------------------------------------------------------------------
 GitLab:       11.7.5 (c5b5b18)
 GitLab Shell: 8.4.4
 postgresql:   9.6.11
-------------------------------------------------------------------------------------
Loading production environment (Rails 5.0.7.1)
irb(main):001:0> Notify.test_email('[email protected]','yangxiaofeiNB','hello,world!').deliver_now  //发送邮件,deliver_now代表立刻发送
(格式:收件人的邮箱地址,邮件标题,邮件内容)
irb(main):003:0> exit   //退出控制台

GitLab의 일상 운영

gitlab的备份
[root@localhost ~]# gitlab-rake gitlab:backup:create    //gitlab的备份
备份的数据的目录
[root@localhost ~]# ls /var/opt/gitlab/backups/
1550541218_2019_02_19_11.7.5_gitlab_backup.tar   //备份完成后会形成tar包,文件名格式:时间戳,当前日期,当前gitlab版本,backup备份包

恢复数据的步骤
首先停止一下两个组件
[root@localhost ~]# gitlab-ctl stop sidekiq
ok: down: sidekiq: 0s, normally up
[root@localhost ~]# gitlab-ctl stop unicorn
ok: down: unicorn: 0s, normally up

切换到备份目录
[root@localhost ~]# cd /var/opt/gitlab/backups/
[root@localhost backups]# ls
1550541218_2019_02_19_11.7.5_gitlab_backup.tar
[root@localhost backups]# gitlab-rake gitlab:backup:restore BACKUP=1550541218_2019_02_19_11.7.5   //进行数据的恢复,名字为上面的时间戳,日期,版本号组成
出现以下提示
Do you want to continue (yes/no)? yes
Do you want to continue (yes/no)? yes
[root@localhost backups]# gitlab-ctl start sidekiq  //启动组件服务
ok: run: sidekiq: (pid 19474) 0s
[root@localhost backups]# gitlab-ctl start unicorn  //启动组件服务
ok: run: unicorn: (pid 19536) 1s
数据恢复完成

gitlab 웹 페이지
http://gitlab.bdqn.com 또는 http : // localhost IP 주소를 방문 하십시오.

콘솔에 들어가는 두 가지 방법

1、[root@localhost ~]# gitlab-rails console   //进入控制台
-------------------------------------------------------------------------------------
 GitLab:       11.7.5 (c5b5b18)
 GitLab Shell: 8.4.4
 postgresql:   9.6.11
-------------------------------------------------------------------------------------
Loading production environment (Rails 5.0.7.1)  //加载生产环境
irb(main):001:0>
#2、[root@localhost ~]# gitlab-rails console production
-------------------------------------------------------------------------------------
 GitLab:       11.7.5 (c5b5b18)
 GitLab Shell: 8.4.4
 postgresql:   9.6.11
-------------------------------------------------------------------------------------
Loading production environment (Rails 5.0.7.1)
irb(main):001:0>

루트 암호를 잊어 버렸습니다. 수정하십시오.


[root@localhost ~]# gitlab-rails console production
-------------------------------------------------------------------------------------
 GitLab:       11.7.5 (c5b5b18)
 GitLab Shell: 8.4.4
 postgresql:   9.6.11
-------------------------------------------------------------------------------------
Loading production environment (Rails 5.0.7.1)
irb(main):001:0> user = User.where(id:1).first   //切换到root用户
=> #<User id:1 @root>    
irb(main):002:0> user.password='1234.com'   //''里面修改密码,密码为8位
=> "1234.com"
irb(main):003:0> user.save!
Enqueued ActionMailer::DeliveryJob (Job ID: 7661b452-fcb4-48a0-b9f0-35995ba21258) to Sidekiq(mailers) with arguments: "DeviseMailer", "password_change", "deliver_now", #<GlobalID:0x00007f4360748a10 @uri=#<URI::GID gid://gitlab/User/1>>
=> true
irb(main):004:0> exit

验证是都修改成功,使用web进行登录测试
##至此修改完成

GitLab 로그보기


[root@localhost ~]# gitlab-ctl tail   //查看整体的日志
查看组件的相关日志
[root@localhost ~]# gitlab-ctl tail redis   //查看redis的日志
[root@localhost ~]# gitlab-ctl tail logrotate

SSH 원격 연결을 통해 GitLab에 파일 업로드

查看密钥
[root@localhost ~]# ssh-keygen -t rsa -C "[email protected]"  //为创建用户时输入的邮箱地址
[root@localhost .ssh]# pwd 
/root/.ssh
[root@localhost .ssh]# ls
id_rsa  id_rsa.pub
[root@localhost .ssh]# cat id_rsa.pub 
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDG+woCe7UsBcXhU/I5hRZ0B7fzOOzzGsYzm1+qSvxn1SRaWQ53TNfWJJKpmamodHDI0IWHld6MI+2IB5bSXobNjrV1W147m34fE3KZZ4Kx9wwQ89UnUzqREIPDHnTLozHOE36AxGh6pREFawMjxJJjzd6d3xC9PM9bQ3KaY80agGY44N1vO6c+Turfkpyre3fyITudEqPlrCibJF9eikXgFhHNtrrWVAII6LUKU89LNfXKKYfOmXvB+T+ZYODkXqPR5GPCz4IIuGd5fxpfAmnTvm+Sz3Dp5APVSmveEx9ivtRVsb5lqlYoXJT1vL+D9dQKFY7HI8/FttOSduQNLfrv [email protected]
复制密钥,到web页面进行添加密钥

验证远程登录是否成功
[root@localhost .ssh]# ssh -T [email protected]
The authenticity of host 'gitlab.bdqn.cn (192.168.1.21)' can't be established.
ECDSA key fingerprint is SHA256:88Ixrb6xHdt9SVsQ3n78nQbfzPplW8kZNKQLuldud6w.
ECDSA key fingerprint is MD5:3e:34:68:db:3a:f6:5c:a5:de:18:9b:1c:cc:ef:f9:ff.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'gitlab.bdqn.cn,192.168.1.21' (ECDSA) to the list of known hosts.
Welcome to GitLab, @root!

프로젝트를 복제하고 업로드


[root@localhost ~]# yum install -y git   //下载git
声明谁操作,全局配置,为用户和用户邮箱(用户必须有才行)
[root@localhost ~]# git config --global user.name "zhangsan"
[root@localhost ~]# git config --global user.email "[email protected]"
[root@localhost ~]# git clone [email protected]:ios/ios.git   //克隆项目库
正克隆到 'ios'...
warning: 您似乎克隆了一个空版本库。
[root@localhost ~]# ls                  //生成一个目录,就是克隆的代码
anaconda-ks.cfg       ios   模板  图片  下载  桌面
initial-setup-ks.cfg  公共  视频  文档  音乐
[root@localhost ~]# cd ios/             //首先进入到克隆的库中
[root@localhost ~]# touch README.md          //创建一个文件
[root@localhost ~]# echo 111 > README.md        //输入内容
[root@localhost ios]# git add README.md       //git中添加内容
[root@localhost ios]# git commit -m "test111"   //进行提交,打一个标签
[master(根提交) ad3c913] test111
 1 file changed, 1 insertion(+)
 create mode 100644 README.md
[root@localhost ios]# git push origin master  //上传,原来的,向主干添加
Counting objects: 3, done.
Writing objects: 100% (3/3), 209 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To [email protected]:ios/ios.git
 * [new branch]      master -> master
进入web页面就可以看到项目了
克隆项目
[root@localhost ~]# mkdir test
[root@localhost ~]# cd test/
[root@localhost test]# git clone [email protected]:ios/ios.git
正克隆到 'ios'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
接收对象中: 100% (3/3), done.
[root@localhost test]# ls
ios
[root@localhost test]# cd ios/
[root@localhost ios]# ls
README.md

추천

출처blog.51cto.com/15067236/2607566