centos7系统GitLab服务器搭建

1、GitLab介绍

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

Gitlab 是被广泛使用的基于 git 的开源代码管理平台,基于 Ruby on Rails 构建, 主要针对软件开发过程中产生的代

码和文档进行管理,Gitlab 主要针对 group 和 project 两个维度进行代码和文档管理,其中 group 是群组,

project是工程项目,一个 group 可以管理多个 project,可以理解为一个群组中有多项软件开发任务,而一个

project 中可能包含多个 branch,意为每个项目中有多个分支,分支间相互独立,不同分支可以进行归并。

2、GitLab安装

如果某些步骤已经操作过了,则无需执行。

2.1 安装SSH依赖

yum install -y curl policycoreutils-python openssh-server

2.2 启动SSH服务

[root@VM-8-8-centos lighthouse]# systemctl enable sshd
[root@VM-8-8-centos lighthouse]# systemctl start sshd

# 查看启动状态
[root@VM-8-8-centos lighthouse]# systemctl status sshd
● sshd.service - OpenSSH server daemon
   Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2024-05-24 11:35:45 CST; 2h 36min ago
     Docs: man:sshd(8)
           man:sshd_config(5)
 Main PID: 1636 (sshd)
   CGroup: /system.slice/sshd.service
           └─1636 /usr/sbin/sshd -D

2.3 设置防火墙-启用IP转发功能

vim /etc/sysctl.conf
# 在文件末尾添加
net.ipv4.ip_forward = 1

2.4 安装并启动防火墙

yum install firewalld systemd -y
systemctl enable firewalld
systemctl start firewalld
systemctl status firewalld

#查看启动情况
[root@VM-8-8-centos lighthouse]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2024-05-24 14:20:56 CST; 35s ago
     Docs: man:firewalld(1)
 Main PID: 29060 (firewalld)
   CGroup: /system.slice/firewalld.service
           └─29060 /usr/bin/python2 -Es /usr/sbin/firewalld --nofork --nopid

2.5 添加HTTP服务到firewalld

[root@VM-8-8-centos lighthouse]# firewall-cmd --permanent --add-service=http
success
[root@VM-8-8-centos lighthouse]# systemctl reload firewalld

其中,pemmanent 表示永久生效,若不加 --permanent 系统下次启动后就会失效。

2.6 安装Postfix以发送邮件

yum install postfix
systemctl enable postfix
systemctl start postfix
systemctl status postfix

# 查看启动情况
[root@VM-8-8-centos lighthouse]# systemctl status postfix
● postfix.service - Postfix Mail Transport Agent
   Loaded: loaded (/usr/lib/systemd/system/postfix.service; enabled; vendor preset: disabled)
   Active: active (running) since Fri 2024-05-24 11:35:45 CST; 2h 50min ago
 Main PID: 1360 (master)
   CGroup: /system.slice/postfix.service
           ├─1360 /usr/libexec/postfix/master -w
           ├─1378 qmgr -l -t unix -u
           └─9367 pickup -l -t unix -u

vim /etc/postfix/main.cf
# 修改inet_protocols = all为
inet_protocols = ipv4
#重启服务
systemctl restart postfix

2.7 添加gitlab镜像

在 /etc/yum.repos.d 目录下新建 gitlab-ce.repo 文件并保存,内容如下:

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

# 重新生成缓存
yum makecache

2.8 安装GitLab

yum install -y gitlab-ce

或者是通过如下方式:

# 直接从tsinghua镜像下载安装包
wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-10.5.7-ce.0.el7.x86_64.rpm
rpm -i gitlab-ce-10.5.7-ce.0.el7.x86_64.rpm

安装信息:

[root@VM-8-8-centos yum.repos.d]# yum install -y gitlab-ce
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package gitlab-ce.x86_64 0:17.0.1-ce.0.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

====================================================================================================================================
 Package                       Arch                       Version                               Repository                     Size
====================================================================================================================================
Installing:
 gitlab-ce                     x86_64                     17.0.1-ce.0.el7                       gitlab-ce                     918 M

Transaction Summary
====================================================================================================================================
Install  1 Package

Total download size: 918 M
Installed size: 2.5 G
Downloading packages:
gitlab-ce-17.0.1-ce.0.el7.x86_64.rpm                                                                         | 918 MB  00:01:22     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : gitlab-ce-17.0.1-ce.0.el7.x86_64                                                                                 1/1 
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=17-0

  Verifying  : gitlab-ce-17.0.1-ce.0.el7.x86_64                                                                                 1/1 

Installed:
  gitlab-ce.x86_64 0:17.0.1-ce.0.el7                                                                                                

Complete!

2.9 修改gitlab配置文件

vim  /etc/gitlab/gitlab.rb
# 指定服务器ip和自定义端口
external_url 'http://192.168.164.195:8000'

# 将8000端口添加到防火墙中
firewall-cmd --zone=public --add-port=8000/tcp --permanent

# 重启防火墙
systemctl reload firewalld

2.10 重置gitlab

gitlab-ctl reconfigure

# 出现下面信息代表充值成功
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.

[2024-05-24T16:47:38+08:00] WARN: This release of Cinc Client became end of life (EOL) on May 1st 2024. Please update to a supported release to receive new features, bug fixes, and security updates.
gitlab Reconfigured!

2.11 启动gitlab

gitlab-ctl restart

[root@VM-8-8-centos yum.repos.d]# gitlab-ctl restart
ok: run: alertmanager: (pid 11174) 0s
ok: run: gitaly: (pid 11203) 0s
ok: run: gitlab-exporter: (pid 11219) 0s
ok: run: gitlab-kas: (pid 11280) 0s
ok: run: gitlab-workhorse: (pid 11289) 0s
ok: run: logrotate: (pid 11299) 1s
ok: run: nginx: (pid 11306) 0s
ok: run: node-exporter: (pid 11312) 1s
ok: run: postgres-exporter: (pid 11319) 0s
ok: run: postgresql: (pid 11332) 0s
ok: run: prometheus: (pid 11334) 0s
ok: run: puma: (pid 11352) 0s
ok: run: redis: (pid 11361) 0s
ok: run: redis-exporter: (pid 11368) 1s
ok: run: sidekiq: (pid 11383) 0s

2.12 访问Gitlab页面

通过服务器ip和指定端口进行访问:
在这里插入图片描述
查看初始化密码:

[root@VM-8-8-centos yum.repos.d]# cat /etc/gitlab/initial_root_password 
# WARNING: This value is valid only in the following conditions
#          1. If provided manually (either via `GITLAB_ROOT_PASSWORD` environment variable or via `gitlab_rails['initial_root_password']` setting in `gitlab.rb`, it was provided before database was seeded for the first time (usually, the first reconfigure run).
#          2. Password hasn't been changed manually, either via UI or via command line.
#
#          If the password shown here doesn't work, you must reset the admin password following https://docs.gitlab.com/ee/security/reset_user_password.html#reset-your-root-password.

Password: PECffl07TzWOvpTiwZ/Yf8QI7IdTLqHnEbDhvyBBQAE=

# NOTE: This file will be automatically deleted in the first reconfigure run after 24 hours.

输出用户名和密码进行登录:
在这里插入图片描述
查看登录后的效果:
在这里插入图片描述
登录之后我们可以修改密码:
在这里插入图片描述
这里将密码修改为qwer123456。

如果启动的时候出现502的情况:

第一种可能是启动端口被占用,解决方法:

# 查看端口情况
netstat -ntpl
lsof -i :port

# 修改端口
vim /etc/gitlab/gitlab.rb

# 重新启动
gitlab-ctl reconfigure
gitlab-ctl stop
gitlab-ctl start

第二种可能是 gitlab 占用内存太多,导致服务器崩溃,尤其是使用阿里云服务器最容易出现502,解决方法:

默认情况下,主机的 swap 功能是没有启用的,解决办法是启动 swap 分区。

# 新建2 GB大小的交换分区
dd if=/dev/zero of=/root/swapfile bs=1M count=2048

# 对其格式化
mkswap /root/swapfile
swapon /root/swapfile

# 添加自启用
vim /etc/fstab
# 在文件最后添加新的一行
/root/swapfile swap swap defaults 0 0

2.13 添加公钥至gitlab

为了安全性考虑,需要创建 public key:

# 在电脑上生成public key 打开cmd 运行
ssh-keygen

复制 id_rsa.pub 文件的 public key:

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDA47/Y/buiytszS3I7o6UdhOFV82vzZMnUOIa1HGJ5UPlzdpGt5NsaJDEDTE4UZ/KXQFtrxEvz6Gs9uFY/tRln4nBgyfOW9SREy2uWd2G8UzTcfCtDaPxLz6kVTH16oP59q3/tp7CMbCIi24w/QB4O0rXGkpVJHt3Q5edSphIrWqPzxjBeQEVqEmGoFPXDYolIL8e6aBMviINGtSiYhDumRKdreJw/uTMBYJUluhnwM+wO3pGfKgCLwB7QCT31smAN31nqCZDDNzwVb0hzFHn0Yue0VR1wRmC156PtmH+QCHH9RWMJBP6JzKeXfB406Ek0Vkj1hTUobGRQumF5KtYN 2420309401@qq.com

添加 public key 至 gitlab:

在这里插入图片描述
点击 Add Key:
在这里插入图片描述
在这里插入图片描述

2.14 常用的操作命令

# 启动服务
gitlab -ctl start

# 查看状态
gitlab -ctl status

# 停掉服务
gitlab -ctl stop

# 重启服务
gitlab -ctl restart

# 让配置生效
gitlab -ctl reconfigure

3 配置中文

在这里插入图片描述
在这里插入图片描述
刷新网页
在这里插入图片描述

  • 25
    点赞
  • 19
    收藏
    觉得还不错? 一键收藏
  • 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、付费专栏及课程。

余额充值