1、 GitLab 官网地址

官网地址:https://about.gitlab.com/
安装说明:https://about.gitlab.com/installation/

2、 服务器准备

准备一个系统为 CentOS7 以上版本的服务器,要求内存 4G,磁盘 50G。 关闭防火墙,并且配置好主机名和 IP,保证服务器可以上网。

3、 安装包准备

清华同方下载镜像:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/?C=M&O=D
Yum 在线安装 gitlab- ce 时,需要下载几百 M 的安装文件,非常耗时,所以最好提前把 所需 RPM 包下载到本地,然后使用离线 rpm 的方式安装。
下载地址:

  1. https://packages.gitlab.com/gitlab/gitlabce/packages/el/7/gitlab-ce-13.10.2-ce.0.el7.x86_64.rpm

4、 执行安装脚本

  1. #1、执行rpm安装脚本
  2. sudo rpm -Uvh gitlab-jh-14.7.3-jh.0.el7.x86_64.rpm
  3. #2、修改gitlab配置文件
  4. vim /etc/gitlab/gitlab.rb
  5. # root⽤户初始化密码
  6. gitlab_rails['initial_root_password'] = ''
  7. # 浏览器访问的ip+端⼝,ip就是安装gitlab机器的ip
  8. #注意点 如果是ip地址 要加上访问协议http://
  9. external_url 'http://gitlab.example.com'
  10. # 设置端⼝ gitlab默认端口80
  11. nginx['listen_port'] = nil

5、 初始化 GitLab 服务

  1. #执行以下命令初始化 GitLab 服务,过程大概需要几分钟,耐心等待…
  2. #修改完gitlab配置文件也需要执行该命令才能使修改的配置文件生效
  3. gitlab-ctl reconfigure
  4. #初始化成功输出
  5. Running handlers:
  6. Running handlers complete
  7. Chef Client finished, 425/608 resources updated in 03 minutes 08
  8. seconds
  9. gitlab Reconfigured!

6、 启动 GitLab 服务

执行以下命令启动 GitLab 服务,如需停止,执行 gitlab-ctl stop

  1. gitlab-ctl start
  2. ok: run: alertmanager: (pid 6812) 134s
  3. ok: run: gitaly: (pid 6740) 135s
  4. ok: run: gitlab-monitor: (pid 6765) 135s
  5. ok: run: gitlab-workhorse: (pid 6722) 136s
  6. ok: run: logrotate: (pid 5994) 197s
  7. ok: run: nginx: (pid 5930) 203s
  8. ok: run: node-exporter: (pid 6234) 185s
  9. ok: run: postgres-exporter: (pid 6834) 133s
  10. ok: run: postgresql: (pid 5456) 257s
  11. ok: run: prometheus: (pid 6777) 134s
  12. ok: run: redis: (pid 5327) 263s
  13. ok: run: redis-exporter: (pid 6391) 173s
  14. ok: run: sidekiq: (pid 5797) 215s
  15. ok: run: unicorn: (pid 5728) 221s

7、 使用浏览器访问 GitLab

gitlab默认使用80端口,如需访问直接访问服务器地址+80端口 80端口是特殊端口可以不带
首次登陆之前,需要修改下 GitLab 提供的 root 账户的密码,要求 8 位以上,包含大小 写子母和特殊符号。因此我们修改密码为 Atguigu.123456 然后使用修改后的密码登录 GitLab。

8、GitLab常用命令

  1. # 启动所有 gitlab 组件:
  2. gitlab-ctl start
  3. # 停止所有 gitlab 组件:
  4. gitlab-ctl stop
  5. # 停止 postgresql 组件:
  6. gitlab-ctl stop postgresql
  7. # 停止相关数据连接服务
  8. gitlab-ctl stop unicorn
  9. gitlab-ctl stop sidekiq
  10. # 重启所有 gitlab 组件:
  11. gitlab-ctl restart
  12. # 重启 gitlab-workhorse 组件:
  13. gitlab-ctl restart gitlab-workhorse
  14. # 查看服务状态
  15. gitlab-ctl status

如果更改了主配置文件 [:/etc/gitlab/gitlab.rb 文件],需要用这个命令,使配置文件生效 但是会初始化除了gitlab.rb 之外的所有文件
sudo gitlab-ctl reconfigure

执行完上面那个命令 重启所有 gitlab 组件
gitlab-ctl restart

针对某个服务重启 例如重启nginx
gitlab-ctl restart nginx

针对某个服务启动 例如启动nginx
gitlab-ctl start nginx

针对某个服务关闭 例如关闭nginx
gitlab-ctl stop nginx

查看日志 (查看gitlab整个所有的日志)
sudo gitlab-ctl tail

具体的日志文件路径:

  1. [root@ci-node1 src]# ll /var/log/gitlab/
  2. total 12
  3. drwx------ 2 git root 95 Mar 23 23:27 gitaly
  4. drwx------ 2 git root 95 Mar 23 23:27 gitlab-monitor
  5. drwx------ 2 git root 4096 Mar 28 00:39 gitlab-rails
  6. drwx------ 2 git root 204 Mar 28 00:39 gitlab-shell
  7. drwx------ 2 git root 95 Mar 23 23:27 gitlab-workhorse
  8. drwx------ 2 root root 95 Mar 23 23:27 logrotate
  9. drwxr-x--- 2 root gitlab-www 4096 Mar 28 00:39 nginx
  10. drwx------ 2 gitlab-prometheus root 95 Mar 23 23:27 node-exporter
  11. drwx------ 2 gitlab-psql root 95 Mar 23 23:27 postgres-exporter
  12. drwx------ 2 gitlab-psql root 95 Mar 23 23:27 postgresql
  13. drwx------ 2 gitlab-prometheus root 235 Mar 27 23:27 prometheus
  14. drwxr-xr-x 2 root root 28 Mar 22 23:25 reconfigure
  15. drwx------ 2 gitlab-redis root 235 Mar 27 23:27 redis
  16. drwx------ 2 gitlab-redis root 95 Mar 23 23:27 redis-exporter
  17. drwx------ 2 git root 235 Mar 27 23:27 sidekiq
  18. drwx------ 2 git root 4096 Mar 28 00:39 unicorn

一般有问题 有报错时候 可以看 所有输出 gitlab-ctl tail
# 检查 redis 的日志
sudo gitlab-ctl tail redis