参考文章
GitLab下载安装_GitLab最新中文基础版下载安装-极狐GitLab
CentOS上完全卸载gitlab_51CTO博客_centos 卸载
简单易行!CentOS 7上安装GitLab社区版的教程_正义的卓别林的博客-CSDN博客
MobaXterm连接远程服务器,使用Linux命令行上传下载文件_mobaxerm连接服务器-CSDN博客Gitlab初始化卡住不动_ruby_block[wait for redis service socket] action r-CSDN博客
Linux初装gitlab初始默认密码_linux gitlab配置初始化密码-CSDN博客
本文主要记录2023/11/8在Centos7上部署Gitlab私有仓库的操作过程,以及过程中问题的处理。
[root@gitlab ~]# hostnamectl
Static hostname: gitlab
Icon name: computer-vm
Chassis: vm
Machine ID: df82112c37d742c8a559f34d1de7fe71
Boot ID: b4c33ccad67c4d8e9fd06cc71bf7e3b6
Virtualization: vmware
Operating System: CentOS Linux 7 (Core)
CPE OS Name: cpe:/o:centos:centos:7
Kernel: Linux 3.10.0-1160.el7.x86_64
Architecture: x86-64
1.从清华大学开源软件镜像站下载gitlab CE包,再上传到Linux上,这里使用Centos7
说明 下载过程中看到不同包EL6、EL7、EL8
EL是Red Hat Enterprise L inux(EL)的缩写。
- EL6是Red Hat 6.x,CentOS 6.x和CloudLinux 6.x的下载。
- EL5是Red Hat 5.x,CentOS 5.x和CloudLinux 5.x的下载。
- EL7是Red Hat 7.x,CentOS 7.x和CloudLinux 7.x的下载。
在本机进入到需要复制的文件(夹)的目录下,右键点击"open MobaXterm terminal here"
在MobaXterm终端输入命令
08/11/2023 15:25.23 /drives/c/Users/joy/Downloads scp gitlab-ce-16.5.1-ce.0.el7.x86_64.rpm root@192.168.4.107:/root
gitlab-ce-16.5.1-ce.0.el7.x86_64.rpm 100% 1232MB 11.3MB/s 01:49
在服务器上查看上传的文件
[root@gitlab ~]# ll
总用量 2519352
-rw-------. 1 root root 1259 10月 20 13:50 anaconda-ks.cfg
-rwx------. 1 root root 1288441378 11月 7 13:04 gitlab-ce-16.3.6-ce.0.el7.x86_64.rpm
-rwx------. 1 root root 1291368668 11月 8 15:27 gitlab-ce-16.5.1-ce.0.el7.x86_64.rpm
2.安装相关依赖,在系统防火墙中打开 HTTP、HTTPS 和 SSH 访问
sudo yum install -y curl policycoreutils-python openssh-server perl
sudo systemctl enable sshd
sudo systemctl start sshd
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo systemctl reload firewalld
3.(可选)下一步,安装 Postfix 以发送电子邮件通知。如果您想使用其他解决方案发送电子邮件,请跳过此步骤并在安装极狐GitLab 后配置外部 SMTP 服务器。
sudo yum install postfix
sudo systemctl enable postfix
sudo systemctl start postfix
4.安装,这里连装了3次才成功,前2次跳出警告信息后就结束了
[root@gitlab ~]# rpm -i gitlab-ce-16.5.1-ce.0.el7.x86_64.rpm
警告:gitlab-ce-16.5.1-ce.0.el7.x86_64.rpm: 头V4 RSA/SHA1 Signature, 密钥 ID f27eab47: NOKEY
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-5
5. 修改gitlab配置
vi /etc/gitlab/gitlab.rb
修改gitlab访问地址为服务器的ip
external_url 'http://192.168.4.107:90'
端口:nginx[‘listen_port’] 默认为80,我们改为90
nginx['listen_port'] = 90
6. 重载配置及启动 这里会卡死
gitlab-ctl reconfigure // 这里执行会卡死
如果在下面这个地方卡死(前一次装过卸载不全的情况)
ruby_block[wait for redis service socket] action run
解放方法:重开一个端口,并执行以下命令
/opt/gitlab/embedded/bin/runsvdir-start
执行后,原窗口继续往下走,直到显示如下信息时,该步骤成功完成。
gitlab Configured!
7.查看 gitlab 的状态
[root@gitlab ~]# gitlab-ctl status
run: alertmanager: (pid 26208) 98s; run: log: (pid 25929) 115s
run: gitaly: (pid 26031) 109s; run: log: (pid 24248) 258s
run: gitlab-exporter: (pid 26170) 100s; run: log: (pid 25629) 136s
run: gitlab-kas: (pid 24555) 244s; run: log: (pid 24580) 243s
run: gitlab-workhorse: (pid 26018) 110s; run: log: (pid 25366) 153s
run: logrotate: (pid 23437) 309s; run: log: (pid 23457) 307s
run: nginx: (pid 25434) 149s; run: log: (pid 25451) 148s
run: node-exporter: (pid 26154) 100s; run: log: (pid 25581) 140s
run: postgres-exporter: (pid 26219) 98s; run: log: (pid 26026) 110s
run: postgresql: (pid 24361) 250s; run: log: (pid 24395) 249s
run: prometheus: (pid 26185) 99s; run: log: (pid 25839) 122s
run: puma: (pid 25162) 167s; run: log: (pid 25207) 164s
run: redis: (pid 24114) 268s; run: log: (pid 24145) 264s
run: redis-exporter: (pid 26172) 100s; run: log: (pid 25763) 128s
run: sidekiq: (pid 25231) 161s; run: log: (pid 25249) 160s
8.把端口添加到防火墙
[root@gitlab ~]# firewall-cmd --zone=public --add-port=90/tcp --permanent
success
[root@gitlab ~]# firewall-cmd --reload
success
[root@gitlab ~]#
9.查看gitlab默认初始密码,这个文件将在首次执行reconfigure后24小时自动删除
vim /etc/gitlab/initial_root_password
10. 浏览器访问:http://192.168.4.107:90,用root账号及默认密码登录
登录后第一件事,修改登录密码。路径:点击头像-编辑个人资料-密码。
(可选)自定义语言改为中文。路径:偏好设置-本地化-语言。
11.登录gitlab并新建空白项目,根据新建空白项目首页命令行指引,在本地IDE配置git并推送项目代码到gitlab仓库。
Git 全局设置
git config --global user.name "Administrator" git config --global user.email "admin@example.com"
创建一个新仓库
git clone http://192.168.4.107:90/root/ruoyi-vue.git cd ruoyi-vue git switch --create main touch README.md git add README.md git commit -m "add README" git push --set-upstream origin main
推送现有文件夹
cd existing_folder git init --initial-branch=main git remote add origin http://192.168.4.107:90/root/ruoyi-vue.git git add . git commit -m "Initial commit" git push --set-upstream origin main
推送现有的 Git 仓库
cd existing_repo git remote rename origin old-origin git remote add origin http://192.168.4.107:90/root/ruoyi-vue.git git push --set-upstream origin --all git push --set-upstream origin --tags
12.在IDEA中打开终端,首次执行以下命令
D:\workspace\RuoYi-Vue> git config --global user.name "571934457"
D:\workspace\RuoYi-Vue> git config --global user.email "571934457@qq.com"
D:\workspace\RuoYi-Vue> git init --initial-branch=main
Initialized empty Git repository in D:/workspace/RuoYi-Vue/.git/
PS D:\workspace\RuoYi-Vue> git remote add origin http://192.168.4.107:90/root/ruoyi-vue.git
PS D:\workspace\RuoYi-Vue> git add .
warning: in the working copy of '.idea/workspace.xml', LF will be replaced by CRLF the next time Git touches it
...
PS D:\workspace\RuoYi-Vue> git commit -m "Initial commit"
[main (root-commit) 67356c4] Initial commit
921 files changed, 70578 insertions(+)
...
D:\workspace\RuoYi-Vue> git push --set-upstream origin main
Enumerating objects: 1216, done.
Counting objects: 100% (1216/1216), done.
Delta compression using up to 8 threads
Compressing objects: 100% (1086/1086), done.
Writing objects: 100% (1216/1216), 2.26 MiB | 4.62 MiB/s, done.
Total 1216 (delta 118), reused 0 (delta 0), pack-reused 0
remote: Resolving deltas: 100% (118/118), done.
To http://192.168.4.107:90/root/ruoyi-vue.git
* [new branch] main -> main
branch 'main' set up to track 'origin/main'.
13.项目代码已上传到gitlab仓库
14.gitlab启停相关操作
gitlab-ctl status
使用控制台实时查看日志
# 查看所有的logs; 按 Ctrl-C 退出
gitlab-ctl tail
# 拉取/var/log/gitlab下子目录的日志
gitlab-ctl tail gitlab-rails
# 拉取某个指定的日志文件
gitlab-ctl tail nginx/gitlab_error.log
#启动关闭gitlab
gitlab-ctl start
gitlab-ctl stop #停止
gitlab-ctl status #查看状态
gitlab-ctl restart #重启
gitlab-ctl reconfigure #更新配置文件,使配置生效
gitlab-ctl help #帮助
gitlab-rake gitlab:check SANITIZE=true --trace #检查gitlab
#gitlab 默认的日志文件存放在/var/log/gitlab 目录下
gitlab-ctl tail #查看所有日志
#禁止 Gitlab 开机自启动
systemctl disable gitlab-runsvdir.service
#启用 Gitlab 开机自启动
systemctl enable gitlab-runsvdir.service
15.启动gitlab失败,执行 systemctl start gitlab-runsvdir ,用于启动gitlab运行服务目录(runsvdir)
fail: alertmanager: runsv not running
fail: gitaly: runsv not running
fail: gitlab-monitor: runsv not running
fail: gitlab-workhorse: runsv not running
fail: logrotate: runsv not running
fail: node-exporter: runsv not running
fail: postgres-exporter: runsv not running
fail: postgresql: runsv not running
fail: prometheus: runsv not running
fail: redis: runsv not running
fail: redis-exporter: runsv not running
fail: sidekiq: runsv not running
fail: unicorn: runsv not running
16.gitlab占内存太高处理,执行vim /etc/gitlab/gitlab.rb,修改gitlab配置文件
如果希望内存占用相对较少则,旧版本使用 /unicorn 找到 worker_processes 设置为工作的人数即可;
unicorn['worker_processes'] = 2
新版则全部替换成puma,使用 /puma 找到对应地方,取消注释或者直接新增行
puma[‘enable’] = true
puma[‘worker_timeout’] = 60
puma[‘worker_processes’] = 2 # 基于使用人数
puma[‘max_threads’] = 4
puma[‘per_worker_max_memory_mb’] = 1024
sidekiq[‘max_concurrency’] = 16
postgresql[‘shared_buffers’] = “256MB”
postgresql[‘max_worker_processes’] = 8
优化前
优化后(待补充)