Centos7 搭建 GitLab服务 下载-安装-配置-卸载 完整版

说明


本文介绍一下 在CentOS7 上执行  GitLab 服务器的离线安装步骤。
本文介绍的步骤适用于 gitlab-ce-10.0.0 至 gitlab-ce-16.xx.xx 版本。
本文详细记录了安装的全部过程,各位读者可以直接

1.环境准备


1.安装依赖

yum install -y curl policycoreutils-python openssh-server perl

2.下载安装包

访问以下网址,选择合适的版本进行下载即可

https://packages.gitlab.com/gitlab/gitlab-ce/

例如 :下载 16.8.7 版本的
https://packages.gitlab.com/gitlab/gitlab-ce/packages/el/7/gitlab-ce-16.8.7-ce.0.el7.x86_64.rpm

3.上传安装包

将下载的 rpm 安装包上传到服务器上,常规操作,不再赘述。
本案例中,将安装包 上传到 /home/gitlabuse 目录下

4.安装


直接使用安装包进行安装
说明 : gitlab 将被安装到 /opt/gitlab 目录下。


a.进入 安装包的目录下

cd /home/gitlabuse


b. 执行安装动作

rpm -ivh gitlab-ce-16.8.7-ce.0.el7.x86_64.rpm 

执行的日志如下:
[root@localhost gitlabuse]# rpm -ivh gitlab-ce-16.8.7-ce.0.el7.x86_64.rpm 
警告:gitlab-ce-16.8.7-ce.0.el7.x86_64.rpm: 头V4 RSA/SHA1 Signature, 密钥 ID f27eab47: NOKEY
准备中...                          ################################# [100%]
正在升级/安装...
   1:gitlab-ce-16.8.7-ce.0.el7        ################################# [100%]
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

Help us improve the installation experience, let us know how we did with a 1 minute survey:
https://gitlab.fra1.qualtrics.com/jfe/form/SV_6kVqZANThUQ1bZb?installation=omnibus&release=16-8

5.配置文件修改

安装完成后,需要对默认的配置进行修改。
配置文件位置 :/etc/gitlab/gitlab.rb    

a.设置访问路径

设置gitlab 的访问地址 : http://:
记住这里的 参数,后面还会用到。

external_url 'http://192.168.1.100:9999'

b.设置时区

gitlab_rails['time_zone'] = 'Asia/Shanghai'

c.设置数据存储地址(可选)

可以自定义数据的存储地址:
default : 数据主存储路径;
alternative : 数据存储备份路径。

git_data_dirs({
 "default" => {
     "path" => "/home/gitlabuse/data"
 },
 "aterative" => {
     "path" => "/home/gitlabuse/databak"
 }
})

d.设置最大并发数(可选)

sidekiq['max_concurrency'] = 20

e.设置postgresql(可选)


以下两个参数根据自己的服务器的新能进行设置即可

缓存大小,建议内存的四分之一,不超过 14GB

postgresql['shared_buffers'] = "1024MB"

最大工作线程

postgresql['max_worker_processes'] = 10

f.设置nginx端口号

与【a】 中的 保持一致

nginx['listen_port'] = 9999

g.关闭prometheus监控

作用不大,且较为消耗资源

prometheus_monitoring['enable'] = false

h.修改备份目录(可选)

数据 备份/还原 时的默认目录,可以根据自己的要求进行修改
作用:
1.数据备份时,备份的数据默认保存在这个文件中;
2.数据还原时,数据默认从这个目录中读取出来。

gitlab_rails['backup_path'] = "/var/opt/gitlab/backups"

6.重新加载配置

配置修改完成后,需要重新加载一下。
这个过程时间较长,等待完成即可。

gitlab-ctl reconfigure

执行完成后,会提示 默认root 用户的密码的保存位置。
【gitlab-ce 10.0.0 的版本不会提示,会在登录时直接重置密码】
Notes:
Default admin account has been configured with following details:
Username: root
Password: You didn't opt-in to print initial root password to STDOUT.
Password stored to /etc/gitlab/initial_root_password. This file will be cleaned up in first reconfigure run after 24 hours.NOTE: Because these credentials might be present in your log files in plain text, it is highly recommended to reset the password following https://docs.gitlab.com/ee/security/reset_user_password.html#reset-your-root-password.

7.重启

gitlab-ctl restart
启动日志输出如下 : 
[root@localhost gitlab]# gitlab-ctl restart
ok: run: gitaly: (pid 149047) 0s
ok: run: gitlab-kas: (pid 149067) 1s
ok: run: gitlab-workhorse: (pid 149077) 0s
ok: run: logrotate: (pid 149092) 1s
ok: run: nginx: (pid 149098) 0s
ok: run: postgresql: (pid 149108) 0s
ok: run: puma: (pid 149119) 0s
ok: run: redis: (pid 149124) 0s
ok: run: sidekiq: (pid 149131) 0s

8.查看服务状态

gitlab-ctl status
状态信息输出如下 :
[root@localhost gitlab]# gitlab-ctl status
run: gitaly: (pid 149047) 67s; run: log: (pid 148242) 438s
run: gitlab-kas: (pid 149067) 56s; run: log: (pid 148505) 412s
run: gitlab-workhorse: (pid 149077) 55s; run: log: (pid 148679) 274s
run: logrotate: (pid 149092) 55s; run: log: (pid 148140) 452s
run: nginx: (pid 149098) 54s; run: log: (pid 148738) 268s
run: postgresql: (pid 149108) 50s; run: log: (pid 148321) 422s
run: puma: (pid 149119) 49s; run: log: (pid 148599) 286s
run: redis: (pid 149124) 49s; run: log: (pid 148182) 446s
run: sidekiq: (pid 149131) 43s; run: log: (pid 148627) 280s

至此,gitlab 的服务已经启动成功.

9.自动启动配置

配置 gitlab 服务随着系统的启动而自动启动,这样就不怕服务器重启了.

systemctl enable gitlab-runsvdir.service

10.开放端口

此处的端口号仍然是 [5.a] 章节中的 <port>

firewall-cmd --zone=public --add-port=9999/tcp --permanent
firewall-cmd --reload

11.查看日志

可以通过如下命令查看gitlab 的日志信息

gitlab-ctl tail

12.访问服务

浏览器访问 http://192.168.1.100:9999 即可.
这个地址,就是 [5.a] 章节中的访问路径.


13.密码设置
a.获取默认密码

默认密码存放在 /etc/gitlab/initial_root_password 文件中.
可以使用此文件中的密码进行首次登录.

more /etc/gitlab/initial_root_password 
Password: 004uv7ip6+CuJ6IOJdcKS8/RwXwk44/QcH+4Lh5mvFY=

b.重置密码

1.使用默认密码进行登录
2.在用户设置中进行密码修改

14.关闭服务

gitlab-ctl stop

15.卸载服务

a.停止服务

gitlab-ctl stop

b.卸载 rpm 软件

rpm -e gitlab-ce 

c.查看进程

ps -ef | grep gitlab
干掉第一个 runsvdir  -P /opt/gitlab/service log 进程

d.删除 gitlab 残余的文件

find / -name *gitlab* | xargs rm -rf

16.补充操作

查看gitlab-ce 的版本

 cat /opt/gitlab/version-manifest.txt

gitlab-ce 10.0.0

安装错误处理

错误信息如下 =============================================
    Error executing action `run` on resource 'execute[semodule -i /opt/gitlab/embedded/selinux/rhel/7/gitlab-7.2.0-ssh-keygen.pp]'
 =============================================

解决方案如下:

步骤一 :安装依赖
yum install libsemanage-static libsemanage-devel

步骤二 : 修改 selinux.rb 文件
cd /opt/gitlab/embedded/cookbooks/gitlab/recipes

vim selinux.rb
// 把下面的内容注释掉
if RedhatHelper.system_is_rhel7?
  ssh_keygen_module = 'gitlab-7.2.0-ssh-keygen'
  execute "semodule -i /opt/gitlab/embedded/selinux/rhel/7/#{ssh_keygen_module}.pp" do
    not_if "getenforce | grep Disabled"
    not_if "semodule -l | grep '^#{ssh_keygen_module}\\s'"
  end
end

步骤三 :重新执行配置
gitlab-ctl reconfigure

至此,gitlab 的服务安装配置就完成了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值