Centos7下gitlab的安装步骤详解

GitLab 是一个用于仓库管理系统的开源项目,使用Git作为代码管理工具,并在此基础上搭建起来的web服务。

1. 安装Gitlab

1.1. 新建tsinghua.repo

vim /etc/yum.repos.d/tsinghua.repo

输入以下内容

[gitlab-ce]
name=Gitlab CE Repository
baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/
gpgcheck=0
enabled=1

1.2. 缓存相关包

yum makecache

1.3. 安装相关依赖

yum install -y curl policycoreutils-python openssh-server

1.4. 安装gitlab-ce

yum install -y gitlab-ce

出现如下画面证明安装成功

It looks like GitLab has not been configured yet; skipping the upgrade script.

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


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

Thank you for installing GitLab!
GitLab was unable to detect a valid hostname for your instance.
Please configure a URL for your GitLab instance by setting `external_url`
configuration in /etc/gitlab/gitlab.rb file.
Then, you can start your GitLab instance by running the following command:
 sudo gitlab-ctl reconfigure

For a comprehensive list of configuration options please see the Omnibus GitLab readme
https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md

Verifying : gitlab-ce-12.2.5-ce.0.el6.x86_64                                                                                                                                                               1/1

已安装:
gitlab-ce.x86_64 0:12.2.5-ce.0.el6                                                                                                                                               完毕!

2. 配置Gitlab

打开gitlab配置文件

vim /etc/gitlab/gitlab.rb

修改如下内容

# 改域名,修改成自己的域名,如果用的https,改成https://gitlab.xxxxxx.com
external_url 'http://gitlab.suyuening.com'
# CPU使用核数,默认好像是24核,用不了那么多,改成2
unicorn['worker_processes'] = 2
# 时域
gitlab_rails['time_zone'] = 'Asia/Shanghai'

修改完后,执行下面命令,使配置重新加载

gitlab-ctl reconfigure

3. gitlab后台界面

访问 http://gitlab.suyuening.com,第一次进入后台,会提示修改root密码(gitlab123456),修改后重新登录。

4. gitlab 相关操作命令

start 启动所有服务 这个重启也会继续开启 相当systemctl enable stop 关闭所有服务 restart 重启所有服务 status 查看所有服务状态 tail 查看日志信息 service-list 列举所有启动服务 graceful-kill 平稳停止一个服务 help 帮助 reconfigure 修改配置文件之后,需要重新加载下 show-config 查看所有服务配置文件信息 uninstall 卸载这个软件 cleanse 删除gitlab数据,重新白手起家

gitlab 包含的服务

Restarting previously running GitLab services ok: run: alertmanager: (pid 6798) 0s ok: run: gitaly: (pid 13241) 147348s ok: run: gitlab-monitor: (pid 6813) 1s ok: run: gitlab-workhorse: (pid 6816) 0s ok: run: logrotate: (pid 6825) 1s ok: run: nginx: (pid 6831) 0s ok: run: node-exporter: (pid 6833) 0s ok: run: postgres-exporter: (pid 6839) 1s ok: run: postgresql: (pid 12349) 147445s ok: run: prometheus: (pid 6849) 0s ok: run: redis: (pid 12289) 147452s ok: run: redis-exporter: (pid 6866) 1s ok: run: sidekiq: (pid 6874) 0s ok: run: unicorn: (pid 6882) 1s

5. Centos配置

5.1. 设置hostname

vim /etc/sysconfig/network

添加以下内容

#使用网络
NETWORKING=yes
#设置主机名称
HOSTNAME=gitlab.suyuening.com

立即生效

hostname gitlab.suyuening.com

5.2. 修改hosts

vim /etc/hosts

添加如下一行到文件末尾

192.168.10.10 gitlab.suyuening.com

6. windows设置

6.1. 修改host

修改C:\Windows\System32\drivers\etc

添加如下一行到文件末尾。参考文章:Win10修改编辑hosts文件无法保存怎么办

192.168.10.10 gitlab.suyuening.com

6.2. 设置不使用代理服务器

http://gitlab.suyuening.com

7. 完全卸载删除gitlab

7.1. 停止gitlab

gitlab-ctl stop

7.2. 卸载gitlab(注意这里写的是gitlab-ce)

rpm -e gitlab-ce

7.3. 查看gitlab进程

ps aux | grep gitlab

7.4. 杀掉git进程

改成实际的PID

kill -9 18777

杀掉后,在ps aux | grep gitlab确认一遍,还有没有gitlab的进程

7.5. 删除所有包含gitlab文件

find / -name gitlab | xargs rm -rf

8. 参考链接

centos7下gitlab的安装步骤

完全卸载删除gitlab