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

说明

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

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 的服务安装配置就完成了。

  • 13
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: 下面是CentOS 7搭建GitLab服务器的大致步骤: 1. 安装必要的依赖包:sudo yum install curl policycoreutils-python openssh-server 2. 安装Postfix以支持发送邮件:sudo yum install postfix 3. 添加GitLab仓库:curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash 4. 安装GitLab:sudo yum install gitlab-ce 5. 配置并启动GitLab:sudo gitlab-ctl reconfigure 注意:以上步骤仅提供参考,具体安装过程请参考GitLab官方文档。 ### 回答2: GitLab是一款基于Git的Web平台,用于管理Git仓库、代码审查、问题跟踪以及自动构建等。CentOS 7上安装GitLab服务器需要经过如下步骤: 1. 更新系统 首先,你要更新CentOS 7操作系统,以确保安装过程中使用最新版本的软件包。可以使用以下命令完成系统升级: ``` sudo yum update -y ``` 2. 安装必要软件 在安装GitLab之前,需要确保系统上安装了一些必要软件,包括curl,policycoreutils和Postfix等。可以使用以下命令安装这些软件: ``` sudo yum install -y curl policycoreutils openssh-server openssh-clients postfix ``` 在安装Postfix时,你需要选择“Internet Site”选项。 3. 安装GitLab 接下来,你可以使用官方的GitLab安装脚本安装GitLab。可以使用以下命令下载和运行脚本: ``` curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash sudo yum install -y gitlab-ce ``` 该脚本将会添加GitLab官方的yum存储库,以便自动安装最新版本的GitLab。 4. 配置GitLab 安装GitLab后,你需要对其进行一些配置以使其正常运行。你可以使用以下命令编辑GitLab配置文件: ``` sudo vi /etc/gitlab/gitlab.rb ``` 你需要根据具体需求和安全需求在文件中设置适当的值。最重要的配置参数如下: ``` # 配置GitLab的外部URL external_url 'http://gitlab.example.com' # 配置邮件服务,用于发送通知 gitlab_rails['smtp_enable'] = true gitlab_rails['smtp_address'] = "smtp.gmail.com" gitlab_rails['smtp_port'] = 587 gitlab_rails['smtp_user_name'] = "user@example.com" gitlab_rails['smtp_password'] = "password" gitlab_rails['smtp_authentication'] = "login" gitlab_rails['smtp_enable_starttls_auto'] = true # 配置GitLab SSH监听地址 gitlab_rails['gitlab_ssh_host'] = 'ssh.example.com' gitlab_rails['gitlab_ssh_port'] = 22 # 配置LDAP身份验证(可选) gitlab_rails['ldap_enabled'] = true gitlab_rails['ldap_servers'] = YAML.load <<-EOS main: label: 'LDAP' host: 'ldap.example.com' port: 636 uid: 'sAMAccountName' bind_dn: 'CN=GitLab,OU=Service Accounts,DC=example,DC=com' password: 'password' encryption: 'simple_tls' verify_certificates: false active_directory: true allow_username_or_email_login: true block_auto_created_users: false base: 'DC=example,DC=com' EOS ``` 5. 重新配置GitLab 完成配置文件的编辑后,你需要重新配置GitLab以应用新的设置: ``` sudo gitlab-ctl reconfigure ``` 这会执行所有必要的配置更改,以确保GitLab可以正常运行。 6. 访问GitLab 在完成GitLab安装配置后,你可以通过浏览器访问GitLab,登录并创建仓库、添加用户等操作。GitLab默认使用HTTP协议,可以在配置文件中配置为HTTPS。 GitLab是一款功能强大的版本控制平台,可以用于开发和团队协作。CentOS 7上的安装配置也非常简单,只需要按照以上步骤进行即可。 ### 回答3: CentOS 7 搭建 GitLab 服务器 Git是一个版本控制系统,可用于共享和管理源代码、文本文件、电子文档等等。GitLab是一个源代码管理器,提供自托管 Git repos、代码评审、CI/CD、问题跟踪等功能。在本文中,我们将介绍在 CentOS 7 上搭建 GitLab 服务器的过程。 准备工作: 准备一台安装了 CentOS 7 操作系统的主机。 确保主机的防火墙开放了HTTP/HTTPS端口。 确保主机已连接到互联网。 安装必要的软件包: 在开始之前,我们需要确保在服务器上安装了常见的软件包: sudo yum install -y curl policycoreutils-python openssh-server sudo systemctl enable sshd sudo systemctl start sshd sudo firewall-cmd --permanent --add-service=http --add-service=https sudo systemctl reload firewalld 安装 GitLab CE: GitLab有两个版本:CE和EE。CE是社区版,免费使用;EE是企业版,需要付费才能使用。在我们的例子中,我们将使用GitLab CE搭建我们的源代码管理器。 sudo yum install -y postfix sudo systemctl enable postfix sudo systemctl start postfix curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash sudo yum install -y gitlab-ce sudo gitlab-ctl reconfigure 我们现在可以通过浏览器访问GitLab web UI。在浏览器中键入服务器IP地址,然后会显示GitLab设置向导。根据您的要求来自定义您的GitLab实例。 初始登陆到GitLab: 在第一次登录 GitLab 时,您将被要求输入初始管理员密码。此密码随后需要更改。此外,还要求您更改登记用户的密码。 首先,用IP访问和端口号(默认为80)打开网站,然后选择更改密码: 输入初始管理员密码。 创建新密码以继续。 创建新用户: 现在我们需要创建用于GitLab的新用户。登陆到GitLab并点击右上角的"Add user"。 ``` 输入用户名和用户密码。 为新用户分配一个角色("reporter" 或 "developer"),并单击"Create user"。 ``` 我们已经安装配置GitLab服务器。这是一个初始过程,并且需要根据您的项目需要进行自定义。现在你可以开始创建和管理Git仓库,共享代码并管理您的项目。 总结: 在CentOS 7上搭建GitLab服务器非常简单,只需要几个步骤。首先,您需要确保服务器上安装了必要的软件包,例如SSH,firewalld,以打开HTTP和HTTPS端口。然后,您需要使用GitLab安装脚本安装GitLab。一旦安装成功了,您可以使用Web页面登录到GitLab,并开始上传和共享代码库。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值