搭建GitLab

文章
林里克斯

Linux下用yumdocker来搭建GitLab

gitlab 版本: ce-13.1.3
系统版本:CentOS 7.5.1804



一、yum安装


1.官网下载yum

$ curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh > rpm.sh
$ chmod u+x rpm.sh
$ ./rpm.sh

2.yum安装gitlab

通过gitlab官方拉下来的repo源走的是国外,会很慢。修改repo源使用国内源
$ vim /etc/yum.repos.d/gitlab_gitlab-ce.repo

baseurl=https://packages.gitlab.com/gitlab/gitlab-ce/el/7/SRPMS

修改为

baseurl=http://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7
#使用清华大学官方repo源

$ yum -y install gitlab-ce
#安装gitlab社区版本
It looks like GitLab has not been configured yet; skipping the upgrade script.

       *.                  *.
      ***                 ***
     *****               *****
    .******             *******
    ********            ********
   ,,,,,,,,,***********,,,,,,,,,
  ,,,,,,,,,,,*********,,,,,,,,,,,
  .,,,,,,,,,,,*******,,,,,,,,,,,,
      ,,,,,,,,,*****,,,,,,,,,.
         ,,,,,,,****,,,,,,
            .,,,***,,,,
                ,*,.



     _______ __  __          __
    / ____(_) /_/ /   ____ _/ /_
   / / __/ / __/ /   / __ `/ __ \
  / /_/ / / /_/ /___/ /_/ / /_/ /
  \____/_/\__/_____/\__,_/_.___/


Thank you for installing GitLab!

3.启动

$ gitlab-ctl reconfigure

4.组件介绍

nginx: 静态web服务器
gitlab-shell: 用于处理Git命令和修改authorized keys列表
gitlab-workhorse: 轻量级的反向代理服务器
logrotate:日志文件管理工具
postgresql:数据库
redis:缓存数据库
sidekiq:用于在后台执行队列任务(异步执行)
unicorn:HTTP服务,GitLab Rails应用是托管在这个服务器上面的。

5.主要配置文件目录

主配置文件: /etc/gitlab/gitlab.rb
文档根目录: /opt/gitlab
默认存储库位置: /var/opt/gitlab/git-data/repositories
Nginx配置文件: /var/opt/gitlab/nginx/conf/gitlab-http.conf
Postgresql数据目录: /var/opt/gitlab/postgresql/data

6.重设管理员或指定用户密码

$ gitlab-rails console production
-------------------------------------------------------------------------------------
 GitLab:       13.1.3 (62c984653d2)
 GitLab Shell: 9.0.0
 PostgreSQL:   9.6.11
-------------------------------------------------------------------------------------
Loading production environment (Rails 5.0.7.2)
irb(main):001:0> user = User.where(id:1).first
=> #<User id:1 @root>
irb(main):002:0> user.password = 'Your Password'
=> "gitlab1234"
irb(main):003:0> user.password_confirmation = 'Your Password'
=> "gitlab1234"
irb(main):004:0> user.save
Enqueued ActionMailer::DeliveryJob (Job ID: 4752a4a4-4e85-4e8b-9f27-72788abfe97c) to Sidekiq(mailers) with arguments: "DeviseMailer", "password_change", "deliver_now", #<GlobalID:0x00007f519e7501d8 @uri=#<URI::GID gid://gitlab/User/1>>
=> true
irb(main):005:0> exit

7.使用smtp来发送邮件通知

$ vim /etc/gitlab/gitlab.rb

gitlab_rails['smtp_address'] = "smtp.yourdomain.com"
gitlab_rails['smtp_port'] = 25
gitlab_rails['smtp_user_name'] = "xxx"
gitlab_rails['smtp_password'] = "xxx"
gitlab_rails['smtp_domain'] = "smtp.yourdomain.com" 
gitlab_rails['smtp_authentication'] = 'plain'
gitlab_rails['smtp_enable_starttls_auto'] = true

8.配置gitlab访问方式为https

$ mkdir /etc/gitlab/ssl -p
#创建证书存放路径
$ chmod 700 /etc/gitlab/ssl
$ vim /etc/gitlab/gitlab.rb

external_url 'http://gitlab.example.com'
nginx['redirect_http_to_https'] = false
nginx['ssl_certificate'] = "/etc/gitlab/ssl/#{node['fqdn']}.crt"
nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/#{node['fqdn']}.key"

修改为

external_url 'https://gitlab.kjarbo.com'
nginx['redirect_http_to_https'] = true
nginx['ssl_certificate'] = "/etc/gitlab/ssl/gitlab.kjarbo.com.crt"
nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/gitlab.kjarbo.com.key"

二、docker安装


1.使用docker-compose

version: '3'
services:
    gitlab:
      image: 'twang2218/gitlab-ce-zh:latest'
      restart: always
      container_name: gitlab
      environment:
        TZ: 'Asia/Shanghai'
        GITLAB_OMNIBUS_CONFIG: |
          external_url 'http://0.0.0.0'
          gitlab_rails['time_zone'] = 'Asia/Shanghai'
          # 需要配置到 gitlab.rb 中的配置可以在这里配置,每个配置一行,注意缩进。
          # 比如下面的电子邮件的配置:
          # gitlab_rails['smtp_enable'] = true
          # gitlab_rails['smtp_address'] = "smtp.exmail.qq.com"
          # gitlab_rails['smtp_port'] = 465
          # gitlab_rails['smtp_user_name'] = "xxxx@xx.com"
          # gitlab_rails['smtp_password'] = "password"
          # gitlab_rails['smtp_authentication'] = "login"
          # gitlab_rails['smtp_enable_starttls_auto'] = true
          # gitlab_rails['smtp_tls'] = true
          # gitlab_rails['gitlab_email_from'] = 'xxxx@xx.com'
      ports:
        - '80:80'
        - '443:443'
      volumes:
        - ./config:/etc/gitlab
        - ./data:/var/opt/gitlab
        - ./logs:/var/log/gitlab

2.启动

$ docker-compose up -d

3.直接 docker run

$ docker run \
    --detach \
    --publish 443:443 \
    --publish 80:80 \
    --name gitlab \
    --restart always \
    -v /usr/local/gitlab/config:/etc/gitlab \
    -v /usr/local/gitlab/data:/var/opt/gitlab \
    -v /usr/local/gitlab/log:/var/log/gitlab \
    twang2218/gitlab-ce-zh:latest 

三、gitlab运维命令


$ cat /opt/gitlab/embedded/service/gitlab-rails/VERSION #查看gitlab版本号
gitlab-ctl start            #启动
gitlab-ctl stop             #停止
gitlab-ctl status           #查看状态
gitlab-ctl restart          #重启

以上均可指定组件名称

nginx
postgresql
redis
unicorn
sidekiq
logrotate

eg:
$ gitlab-ctl status nginx
run: nginx: (pid 1345) 6438s; run: log: (pid 1344) 6438s
$ gitlab-ctl status redis
run: redis: (pid 1352) 6444s; run: log: (pid 1351) 6444s

gitlab-ctl reconfigure      #修改后直接编译启动
gitlab-ctl tail             #查看实时日志
gitlab-ctl tail nginx/gitlab_access.log #查看Nginx的access访问日志
gitlab-ctl pg-upgrade       #升级PostgreSQL最新版本
gitlab-rake cache:clear     #清理redis缓存
gitlab-rake db:migrate      #数据库关系升级
gitlab-rake gitlab:backup:create    #创建一个新备份
gitlab-rake gitlab:backup:restore BACKUP=serail_number_date #恢复备份
#默认备份目录gitlab-rake gitlab:backup:create
若需要修改:
$ vim /etc/gitlab/gitlab.rb
gitlab_rails['backup_path'] = '/backups'

Over~

版权协议须知!

本篇文章来源于 Uambiguous ,如本文章侵犯到任何版权问题,请立即告知本站,本站将及时予与删除并致以最深的歉意

1324 0 2020-07-10


分享:
icon_mrgreen.gificon_neutral.gificon_twisted.gificon_arrow.gificon_eek.gificon_smile.gificon_confused.gificon_cool.gificon_evil.gificon_biggrin.gificon_idea.gificon_redface.gificon_razz.gificon_rolleyes.gificon_wink.gificon_cry.gificon_surprised.gificon_lol.gificon_mad.gificon_sad.gificon_exclaim.gificon_question.gif
博主卡片
林里克斯 博主大人
一个致力于Linux的运维平台
运维时间
搭建这个平台,只为分享及记载自己所遇之事和难题。

现在时间 2024-12-28

今日天气
站点统计
  • 文章总数:241篇
  • 分类总数:29个
  • 评论总数:12条
  • 本站总访问量 353778 次

@奥奥

@Wong arrhenius 牛比

@MakerFace 厉害了!