CentOS7下安装GitLab

目录

  • 一、下载地址
  • 二、安装
    • 1.配置 yum 源
    • 2.更新本地 yum 缓存
    • 3.安装 GitLab 社区版
    • 4.初始化
    • 5.修改端口
    • 6.修改外部链接
    • 7.查看版本号
    • 8.登录
  • 三、备份和恢复
    • 1.备份
    • 2.恢复
  • 四、卸载及重装
    • 1.卸载
      • (1)停服务
      • (2)卸载
      • (3)杀进程
      • (4)删文件
    • 2.重装问题
      • (1)postgre 问题
      • (2)Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '255'
      • (3)Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'
      • (4)ruby_block[wait for redis service socket] action run


一、下载地址

Gitlab下载地址:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/

二、安装

1.配置 yum 源

vi /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

2.更新本地 yum 缓存

yum makecache

3.安装 GitLab 社区版

自动安装最新版:

yum install gitlab-ce

或下载安装包安装:

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

4.初始化

gitlab-ctl reconfigure

5.修改端口

vi /etc/gitlab/gitlab.rb
nginx['listen_port'] = 8000
vi  /var/opt/gitlab/nginx/conf/gitlab-http.conf
server {
  listen *:80;
  server_name 192.168.1.60;

修改完成后,执行:

gitlab-ctl reconfigure
gitlab-ctl restart

6.修改外部链接

vi /etc/gitlab/gitlab.rb
external_url 'http://gitlab.example.com'

改为:

external_url '192.168.1.60'

7.查看版本号

cat /opt/gitlab/embedded/service/gitlab-rails/VERSION

8.登录

打开浏览器,输入 “http:/192.168.1.60”,进入登录页面:
CentOS7下安装GitLab_第1张图片
默认账户名是 root,密码存放在配置文件:

/etc/gitlab/initial_root_password

该文件将在首次执行 reconfigure 后 24 小时自动删除,文件内容如下:

# 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: /XhuNwa6xVjEMYmPthcOFUiaub/8bAWHn2C1jOFjrwI=

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

三、备份和恢复

1.备份

修改gitlab的备份路径:

vi /etc/gitlab/gitlab.rb
gitlab_rails['backup_path'] = "/var/opt/gitlab/backups"

重启gitlab服务:

gitlab-ctl restart

备份命令:

gitlab-rake gitlab:backup:create

2.恢复

为保证数据的一致性先停止数据连接服务:

gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq

恢复(注意:不用带_gitlab_backup.tar后缀):

gitlab-rake gitlab:backup:restore BACKUP=/var/opt/gitlab/backups/1575249855

启动刚才停的服务:

gitlab-ctl start unicorn
gitlab-ctl start sidekiq

或重启gitlab服务:

gitlab-ctl restart

四、卸载及重装

1.卸载

(1)停服务

gitlab-ctl stop

(2)卸载

yum remove gitlab-ce

rpm -qa|grep gitlab
rpm -e rpm -e gitlab-ce-15.4.2-ce.0.el7.x86_64.rpm

(3)杀进程

ps -ef|grep gitlab
kill xxx

(4)删文件

rm -rf /opt/gitlab/
rm -rf /var/log/gitlab/
rm -rf /var/opt/gitlab/

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

2.重装问题

(1)postgre 问题

卸载后重装,有时会报 postgre 错误:

data directory was initialized by PostgreSQL version 13, which is not compatible with this version 14.0

解决方法:
删除 postgre 相关目录后再重新安装:

rm -rf /opt/gitlab/
rm -rf /var/log/gitlab/
rm -rf /var/opt/gitlab/

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

(2)Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received ‘255’

执行 gitlab-ctl reconfigure 还可能出现以下错误:

Running handlers:
There was an error running gitlab-ctl reconfigure:

gitlab_sysctl[kernel.shmmax] (postgresql::enable line 67) had an error: Mixlib::ShellOut::ShellCommandFailed: execute[load sysctl conf kernel.shmmax] (/opt/gitlab/embedded/cookbooks/cache/cookbooks/package/resources/gitlab_sysctl.rb line 46) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '255'
---- Begin output of sysctl -e --system ----
STDOUT: * Applying /usr/lib/sysctl.d/00-system.conf ...
* Applying /usr/lib/sysctl.d/10-default-yama-scope.conf ...
kernel.yama.ptrace_scope = 0
* Applying /usr/lib/sysctl.d/50-default.conf ...
kernel.sysrq = 16
kernel.core_uses_pid = 1
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.default.accept_source_route = 0
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.default.promote_secondaries = 1
net.ipv4.conf.all.promote_secondaries = 1
fs.protected_hardlinks = 1
fs.protected_symlinks = 1
* Applying /etc/sysctl.d/90-omnibus-gitlab-kernel.sem.conf ...
* Applying /etc/sysctl.d/90-omnibus-gitlab-kernel.shmall.conf ...
* Applying /etc/sysctl.d/90-omnibus-gitlab-kernel.shmmax.conf ...
kernel.shmmax = 17179869184
* Applying /etc/sysctl.d/90-omnibus-gitlab-net.core.somaxconn.conf ...
* Applying /etc/sysctl.d/99-sysctl.conf ...
* Applying /etc/sysctl.conf ...
STDERR: sysctl: cannot open "/etc/sysctl.d/90-omnibus-gitlab-kernel.sem.conf": No such file or directory
sysctl: cannot open "/etc/sysctl.d/90-omnibus-gitlab-kernel.shmall.conf": No such file or directory
sysctl: cannot open "/etc/sysctl.d/90-omnibus-gitlab-net.core.somaxconn.conf": No such file or directory
---- End output of sysctl -e --system ----
Ran sysctl -e --system returned 255

解决方法:

touch /opt/gitlab/embedded/etc/90-omnibus-gitlab-kernel.sem.conf
touch /opt/gitlab/embedded/etc/90-omnibus-gitlab-net.core.somaxconn.conf

(3)Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received ‘1’

继续报错:

Running handlers:
There was an error running gitlab-ctl reconfigure:

bash[migrate gitlab-rails database] (gitlab::database_migrations line 54) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '1'
---- Begin output of "bash"  "/tmp/chef-script20221013-16235-vjrh02" ----
STDOUT: rake aborted!
PG::ConnectionBad: could not connect to server: No such file or directory
	Is the server running locally and accepting
	connections on Unix domain socket "/var/opt/gitlab/postgresql/.s.PGSQL.5432"?
/opt/gitlab/embedded/service/gitlab-rails/lib/tasks/gitlab/db.rake:48:in `block (3 levels) in <top (required)>'
/opt/gitlab/embedded/bin/bundle:23:in `load'
/opt/gitlab/embedded/bin/bundle:23:in `
' Tasks: TOP => gitlab:db:configure (See full trace by running task with --trace) STDERR: ---- End output of "bash" "/tmp/chef-script20221013-16235-vjrh02" ---- Ran "bash" "/tmp/chef-script20221013-16235-vjrh02" returned 1

解决方法:

gitlab-ctl stop
chmod 0755 /var/opt/gitlab/postgresql
systemctl restart gitlab-runsvdir
#重启
gitlab-ctl reconfigure
gitlab-ctl restart

(4)ruby_block[wait for redis service socket] action run

执行 gitlab reconfigure 卡在 ruby_block[wait for redis service socket] action run。
解决方法:
执行命令:

systemctl start gitlab-runsvdir

你可能感兴趣的:(高效运维,gitlab,centos)