Linux安装gitlab(yum方式、rpm方式)

目录

一、概述

二、安装

0、前置条件

1、配置yum源

2、更新本地yum缓存

3、安装gitlab社区版

 4、更改配置文件参数

1)更改默认端口

2)配置邮箱

3)修改root管理员密码

4)性能优化

5、重新启动

6、其他命令 

三、使用

 1、更改语言

 2、更改用户注册设置


一、概述

Gitlab 是一个开源分布式的版本控制系统。 Ruby语言开发完成。
Gitlab 主要实现的功能:
1.管理项目源代码。
2.对源代码进行版本控制。
Gitlab 的优势:
1.开源免费,搭建简单、维护成本较低、适合中小型公司。
2.权限管理,能实现代码对部分人可见,确保项目的安全性
3.离线同步,保证我们不在实时依赖网络环境进行代码提交

二、安装

0、前置条件

关闭防火墙,查看防火墙状态,如果开启就stop关闭一下

systemctl status firewalld.service

1、配置yum源

vim /etc/yum.repos.d/gitlab-ce.repo

复制以下内容,然后 :wq! 保存退出 

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

2、更新本地yum缓存

yum makecache

3、安装gitlab社区版

#自动安装最新版本并安装相关依赖
yum install gitlab-ce 

也可以下载想要安装的gitlab版本,使用rpm命令安装

下载地址:Index of /gitlab-ce/yum/el7/ | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror

#下载最新版本
wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-15.2.0-ce.0.el7.x86_64.rpm --no-check-certificate
#使用rpm安装需要手动解决依赖问题
#前置条件依赖policycoreutils-python、openssh-server设置开机自启
yum -y install policycoreutils-python openssh-server
systemctl enable sshd
systemctl start sshd

#还缺啥安装时会有提示,缺啥安装啥就行
rpm -Uvh gitlab-ce-15.2.0-ce.0.el7.x86_64.rpm

#安装成功后启动
gitlab-ctl reconfigure

gitlab-ctl restart

 4、更改配置文件参数

默认安装完成后安装目录

gitlab组件日志路径:/var/log/gitlab
gitlab配置路径:/etc/gitlab/  路径下有gitlab.rb配置文件
应用代码和组件依赖程序:/opt/gitlab
各个组件存储路径: /var/opt/gitlab/
仓库默认存储路径   /var/opt/gitlab/git-data/repositories
版本文件备份路径:/var/opt/gitlab/backups/
nginx安装路径:/var/opt/gitlab/nginx/
redis安装路径:/var/opt/gitlab/redis

要更改配置文件我们需要修改/etc/gitlab/gitlab.rb

1)更改默认端口

#ip为你服务器ip port你想要修改的端口号
#修改如下:
external_url 'http://ip:port'
nginx['listen_https'] = false
nginx['listen_port'] = port
nignx['listen_address'] = ['*']
#同时还需要修改nginx配置文件
vim /var/opt/gitlab/nginx/conf/gitlab-http.conf

#修改如下
server {
listen *:port;
server_name ip
if ($http_host = ""){
set $http_host_with_default "ip:port";
}
}

2)配置邮箱

前置条件:需要安装postfix邮箱 

#安装
yum install -y postfix
#设置开机自启
systemctl enable postfix
#启动
systemctl start postfix
#修改以下内容
gitlab_rails['gitlab_email_enabled'] = true
gitlab_rails['gitlab_email_from'] = '发信邮箱'
gitlab_rails['gitlab_email_display_name'] = 'xxx'

gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.163.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "发信邮箱"
gitlab_rails['smtp_password'] = "smtp客户端授权码"
gitlab_rails['smtp_domain'] = "163.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true
gitlab_rails['smtp_openssl_verify_mode'] = 'none'

 以163为例

  


 修改完成后重新加载配置文件

gitlab-ctl reconfigure

如果修改了邮箱配置,测试邮箱是否生效

[root@localhost gitlab]# gitlab-rails console
--------------------------------------------------------------------------------
 Ruby:         ruby 2.7.5p203 (2021-11-24 revision f69aeb8314) [x86_64-linux]
 GitLab:       15.2.0 (a876afc5fd8) FOSS
 GitLab Shell: 14.9.0
 PostgreSQL:   13.6
------------------------------------------------------------[ booted in 14.38s ]
Loading production environment (Rails 6.1.4.7)
irb(main):001:0> Notify.test_email('[email protected]','test','gitlab').deliver_now
Delivered mail [email protected] (1078.9ms)
=> #<Mail::Message:290380, Multipart: false, Headers: <Date: Thu, 28 Jul 2022 15:27:20 +0800>, <From: lick <[email protected]>>, <Reply-To: xxx <noreply@xxx>>, <To: [email protected]>, <Message-ID: <[email protected]>>, <Subject: test>, <Mime-Version: 1.0>, <Content-Type: text/html; charset=UTF-8>, <Content-Transfer-Encoding: 7bit>, <Auto-Submitted: auto-generated>, <X-Auto-Response-Suppress: All>>

 3)修改root管理员密码

 ps:初始密码可以查看

cat /etc/gitlab/initial_root_password
#登录控制台
gitlab-rails console
#查找切换账号
u=User.where(id:1).first
#修改密码
u.password='更改后的密码'
#再次确认密码
u.password='更改后的密码'
#保存
u.save!

 4)性能优化

unicorn['worker_processes'] = 2                         #官方建议值为CPU核数+1(服务器只部署gitLab的情况下),可提高服务器响应速度,此参数最小值为2,设为1服务器可能卡死
unicorn['work_timeout'] = 60                            #设置超时时间
unicorn['worker_memory_limit_min'] = "200 * 1 << 20"    #减少最小内存
unicorn['worker_memory_limit_max'] = "300 * 1 << 20"    #减少最大内存
postgresql['shared_buffers'] = "128MB"                  #减少数据库缓存
postgresql['max_worker_processes'] = 6                  #减少数据库并发数
sidekiq['concurrency'] = 15                             #减少sidekiq并发数

由于 Gitlab 核心功能是代码托管,所以有些额外的组件比较浪费资源,所以可以考虑关闭。 

prometheus['enable'] = false
prometheus['monitor_kubernetes'] = false
alertmanager['enable'] = false  
node_exporter['enable'] = false 
redis_exporter['enable'] = false 
postgres_exporter['enable'] = false
gitlab_exporter['probe_sidekiq'] = false
prometheus_monitoring['enable'] = false
grafana['enable'] = false  

 以上就是修改配置文件!

5、重新启动

sudo gitlab-ctl reconfigure

sudo gitlab-ctl restart

6、其他命令 

gitlab-ctl start #启动全部服务
gitlab-ctl restart#重启全部服务
gitlab-ctl stop #停止全部服务
gitlab-ctl restart nginx #重启单个服务,如重启nginx
gitlab-ctl status #查看服务状态
gitlab-ctl reconfigure #使配置文件生效
gitlab-ctl show-config #验证配置文件
gitlab-ctl uninstall #删除gitlab(保留数据)
gitlab-ctl cleanse #删除所有数据,从新开始
gitlab-ctl tail <service name>查看服务的日志
gitlab-ctl tail nginx  #如查看gitlab下nginx日志
gitlab-rails console  #进入控制台
gitlab-ctl help                  #查看gitlab帮助信息

三、使用

安装完成后输入服务器地址和端口号就可以进行访问

 1、更改语言

root登陆后点击preferences,进入偏好设置。在这里可以设置主题颜色、语言等选项,下滑找到localization,选择中文,保存后,重新刷新页面即可

 

更改后界面:

 2、更改用户注册设置

默认勾选前两个,如果是公司内网团队开发,可以设置为勾选1,3即可

 以上就是本文的全部内容了,感谢您的观看,希望对您有所帮助!

猜你喜欢

转载自blog.csdn.net/weixin_38489509/article/details/126034654