GitLab是利用Ruby on Rails一个开源的版本管理系统,实现一个自托管的Git项目仓库,可通过Web界面进行访问公开的或者私人项目。与Github类似,GitLab能够浏览源代码,管理缺陷和注释。可以管理团队对仓库的访问,它非常易于浏览提交过的版本并提供一个文件历史库。团队成员可以利用内置的简单聊天程序(Wall)进行交流。它还提供一个代码片段收集功能可以轻松实现代码复用,便于日后有需要的时候进行查找。
Gitlab的服务构成
Nginx:静态web服务器。
gitlab-shell:用于处理Git命令和修改authorized keys列表。
gitlab-workhorse: 轻量级的反向代理服务器。
logrotate:日志文件管理工具。
postgresql:数据库。
redis:缓存数据库。
sidekiq:用于在后台执行队列任务(异步执行)。
unicorn:An HTTP server for Rack applications,GitLab Rails应用是托管在这个服务器上面的。
因为服务器资源限制,目前只有两台机器,所有 gitlab redis pg 都安装在这两台服务器上(资源充足的话建议分开),nfs 是在云平台购买的一块nas 盘
Gitlab Rail Server |
192.168.1.205(主) 192.168.1.207(主) |
Redis |
192.168.1.205(从) 192.168.1.207(主) |
PostgreSQL |
192.168.1.205(主) 192.168.1.207(从) |
NFS |
192.168.100.4:/csp_vol1001_prd |
master 192.168.1.205
slave 192.168.1.207
#postgres 安装
yum -y install readline readline-devel zlib-devel
tar -xvf postgresql-10.3.tar.gz
cd postgresql-10.3
./configure
make && make install
PostgreSQL默认安装目录为 /usr/local/pgsql/
#创建用户:
groupadd -g 1004 postgres
useradd postgres -u 1004 -g postgres
pass@pg
#建议数据及日志目录
mkdir -p /data/pgsql/5432
mkdir -p /data/logs/pgsql
mkdir /data/pgsql/5432/arch
mkdir /data/pgsql/5432/arch_master
更改文件夹所有者为用户postgres
chown postgres.postgres -R /data/pgsql/
chown postgres.postgres -R /data/logs/pgsql
chown postgres.postgres -R /usr/local/pgsql
export PGHOME="/usr/local/pgsql/"
export PGDATA="/data/pgsql/5432/"
PATH=$PATH:$HOME/.local/bin:$HOME/bin:$PGHOME/bin
export PATH
su "postgres"
/usr/local/pgsql/bin/initdb -D /data/pgsql/5432
cd /data/xjk/software/mysql/postgresql-10.3/contrib/start-scripts
cp linux /etc/init.d/postgresql
chkconfig --add postgresql
chkconfig postgresql on
上面安装步骤需要在主备库都安装
#在主库操作:
su postgres
cd /usr/local/pgsql/bin
./psql
--创建replication 用户 同步数据库
CREATE ROLE repl login replication password 'repl123';
创建 gitlab 用户设置
ALTER ROLE gitlab CREATEROLE CREATEDB
CREATE USER gitlab WITH PASSWORD 'password@gitlab';
CREATE DATABASE gitlabhq_production OWNER gitlab;
GRANT ALL PRIVILEGES ON DATABASE gitlabhq_production TO gitlab;
ALTER ROLE gitlab CREATEROLE SUPERUSER;
--修改Master库的pg_hba.conf,把Master库和Standby库的IP地址添加进Master库网络策略白名单中,使Standby库可以连上Master库,同时便于主备切换。
host all all 192.168.1.205/32 trust
host all all 192.168.1.207/32 trust
host replication repl 192.168.1.205/32 md5
host replication repl 192.168.1.207/32 md5
--修改参数文件
vi postgresql.conf
************************************
wal_level= logical
max_wal_senders = 10 # at least the number of standby
archive_mode = on
archive_command = 'test ! -f /data/pgsql/5432/arch/%f && cp %p /data/pgsql/5432/arch/%f'
synchronous_standby_names = '' #standby application name, in recover.conf
hot_standby=on
$ vi recovery.done
******************************************
standby_mode=on
restore_command = 'cp /data/pgsql/5432/arch_master/%f %p'
primary_conninfo='application_name=pg2 host=192.168.1.207 port=5432 user=repl password=repl123'
archive_cleanup_command ='pg_archivecleanup /data/pgsql/5432/arch_master %r'
recovery_target_timeline = 'latest'
*********************************************
重启数据库
/usr/local/pgsql/bin/pg_ctl -D /data/pgsql/5432 -l /data/logs/pgsql/postgres.log restart
查看服务是否启动成功
ps -ef | grep postgres
在备库操作:
同步pg到 备库
scp -r [email protected]: /data/pgsql/5432 /data/pgsql/5432
/usr/local/pgsql/bin/pg_basebackup -h 192.168.1.205 -U repl -D /data/pgsql/5432 -X stream –P
psql -h 192.168.1.205 -U gitlab -d gitlabhq_production -p 5432
wget http://download.redis.io/releases/redis-4.0.11.tar.gz
yum -y install gcc
tar zxvf redis-4.0.11.tar.gz
mv redis-4.0.11 /usr/local/redis
cd /usr/local/redis
make && make install
vim /usr/local/redis/redis.conf
#修改如下几行信息
bind 0.0.0.0#不限制访问ip和远程连接
protected-mode no#保护模式
daemonize yes#后台运行线程
dir /usr/local/redis/
requirepass password
/usr/local/redis/src/redis-server /usr/local/redis/redis.conf
开机启动:
(1)编辑redis.service文件
cd /usr/lib/systemd/system #进入service文件目录
vim ./redis.service
[Unit]
Description=redis
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/usr/local/redis/src/redis-server /usr/local/redis/redis.conf
ExecReload=/usr/local/redis/src/redis-cli -p 6379 shutdown | /usr/local/redis/src/redis-server /usr/local/redis/redis.conf
ExecStop=/usr/local/redis/src/redis-cli -p 6379 shutdown
[Install]
WantedBy=multi-user.target
(2) 生效
systemctl daemon-reload
(3)改变文件权限
chmod 777 ./redis.service
(4)建立软连接
ln -s /usr/lib/systemd/system/redis.service /etc/systemd/system/multi-user.target.wants/redis.service
(5)systemctl开机启动redis
systemctl enable redis.service
主从设置
略
redis 安装:
https://www.cnblogs.com/zwcry/p/9505949.html
在nas创建相关目录
mount –t nfs 192.168.100.4:/csp_vol1001_prd /mnt
cd /mnt
mkdir git-data
mkdir .ssh
mkdir –p gitlab-rails/uploads
mkdir –p gitlab-rails/shared
mkdir –p gitlab-ci/builds
在 /etc/rc.local 把nfs上面 目录 挂载在 /var/opt/gitlab 下的相关目录下
chmod a+x /etc/rc.local
卸载
gitlab-ctl stop
rpm -e gitlab-ee
ps aux | grep gitlab
systemctl stop gitlab-runsvdir
kill -9 18777
find / -name gitlab | xargs rm -rf
安装
export http_proxy=http://192.168.1.197:80
export https_proxy=http://192.168.1.197:80
yum install -y curl policycoreutils-python openssh-server
getenforce 0
systemctl status firewall
systemctl disabled firewalld
systemctl stop firewalld
yum install postfix
systemctl status postfix
systemctl enable postfix
systemctl start postfix
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh | bash
EXTERNAL_URL="http://test.datafile.cn" yum install -y gitlab-ee-11.4.3
安装完成以后把文件同步到 另外一台 gitlab 服务器,启动
/opt/gitlab
/var/opt/gitlab (nfs 文件不需要)
【需要在 192.168.1.205 192.168.1.207 都修改】
gitlab 配置文件:
常用操作命令
#初始化gitlab
gitlab-rake gitlab:setup
如果驱动安装成功后,执行gitlab-rake gitlab:check,如果是表不存在,可以执行上面代码,来创建表。
# 重新加载配置文件:
systemctl restart gitlab-runsvdir
gitlab-ctl reconfigure
gitlab-ctl start
gitlab-rake gitlab:check
gitlab-rake gitlab:ldap:check
#恢复备份:
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
gitlab-rake gitlab:backup:restore
#定时备份
gitlab-rake gitlab:backup:create
操作步骤
修改 /etc/gitlab/gitlab.rb
gitlab_rails['backup_path'] = "/data/backups"
# 保存30 天
gitlab_rails['backup_keep_time'] = 2592000
gitlab-ctl reconfigure
0 1 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create CRON=1
#恢复备份:
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
gitlab-rake gitlab:backup:restore
或者
gitlab-rake gitlab:backup:restore BACKUP=1558492132_2019_05_22_11.4.3-ee
部署遇到的问题:
Error executing action `create` on resource 'ruby_block[restart redis svlogd configuration]'
https://gitlab.com/gitlab-org/omnibus-gitlab/issues/160
systemctl restart gitlab-runsvdir
gitlab-ctl reconfigure
https://svolence.github.io/gitlab/ha/
http://www.cnblogs.com/topicjie/p/7106960.html
https://www.cnblogs.com/tangqiwen/p/8342918.html
https://svolence.github.io/gitlab/ha/