安装gitlab+rsync增量同步代码库(CentOS7)

Install a GitLab CE Omnibus package on CentOS 7

Install and configure the necessary dependencies

sudo yum install curl policycoreutils openssh-server openssh-clients
sudo systemctl enable sshd
sudo systemctl start sshd
sudo yum install postfix
sudo systemctl enable postfix
sudo systemctl start postfix
sudo firewall-cmd --permanent --add-service=http
sudo systemctl reload firewalld

Add the GitLab package server and install the package

curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
sudo yum install gitlab-ce
或者
curl -LJO https://packages.gitlab.com/gitlab/gitlab-ce/packages/el/7/gitlab-ce-XXX.rpm/download
rpm -i gitlab-ce-XXX.rpm

人在中国可以使用清华源
https://mirror.tuna.tsinghua.edu.cn/help/gitlab-ce/:
CentOS/RHEL

vim /etc/yum.repos.d/gitlab-ce.repo
[gitlab-ce]
name=gitlab-ce
baseurl=http://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7
repo_gpgcheck=0
gpgcheck=0
enabled=1
gpgkey=https://packages.gitlab.com/gpg.key

sudo yum makecache
sudo yum install gitlab-ce

Configure and start GitLab

sudo gitlab-ctl reconfigure

Browse to the hostname and login

登陆地址:http://ip/users/sign_in
官方文档:http://doc.gitlab.com/omnibus/

gitlab本地备份

修改备份设置:
vim /opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml
备份命令
/usr/bin/gitlab-rake gitlab:backup:create RAILS_ENV=production
需要注意的:
备份产生的文件root用户只有只读权限
而且产生的备份文件是带时间戳的,没找到替换模式
所以后面可以修改rsync的用户为git,然后新建一个定时任务把老的文件移动到old_bak中,这样增量备份才能生效
需要赋予git用户SSH权限,默认只有root用户有
vim /etc/ssh/sshd_config 
AllowUsers:git
生产环境改不了,我擦
还是老老实实建两个crontab 把:1.每天把老的备份移出去2.对新的备份改权限
15 0 * * * mv /var/opt/gitlab/backups/* /var/opt/gitlab/old_bak
30 1 * * * chmod 777 /var/opt/gitlab/backups/*

默认备份目录:
/var/opt/gitlab/backups

crontab  -e #编辑crontab服务文件
0 2 * * * /usr/bin/gitlab-rake gitlab:backup:create RAILS_ENV=production #每天两点自动备份一次

查询已有的定时任务:crontab -l

安装rsync实现自动增量同步到远端

两个非常好的rpm包下载网站:
http://rpmfind.net/
http://rpm.pbone.net/

将服务器:10.20.13.133 的文件每天增量的备份到备份机:10.20.13.132
两台机器均需要安装rsync:

yum install rsync

服务器:

vim /etc/rsyncd.conf #创建主配置文件
port = 873
pid file = /var/run/rsyncd.pid
motd file=/var/rsync/welcome.msg
lock file = /var/rsync/rsync.lock
log file = /var/rsync/rsyncd.log
timeout = 900
dont compress   = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2 #配置某些格式不压缩
[backup]
path = /var/opt/gitlab/backups
comment = gitlab backup path
use chroot = no
max connections = 5
list = yes
uid = nobody
gid = nobody
secrets file = /etc/rsyncd.secrets
hosts allow = 10.20.13.132
hosts deny = *
ignore errors = yes
transfer logging = yes
log format = "%t %a %m %f %b"
auth users = root

vim /etc/rsyncd.secrets
root:Paic1234
chmod 600 /etc/rsyncd.secrets
rsync --daemon #启动服务
kill `cat /var/rsync/rsyncd.pid` #停止服务

客户端:

vim /etc/rsyncd.secrets
Paic1234 #只保留密码,带上用户名会报错
vim /etc/rc.d/init.d/rsync.sh
#!/bin/sh
rsync -vzrtopg --progress --delete -e ssh [email protected]::backup /var/opt/gitlab/backups --password-file=/etc/rsyncd.secrets
0 3 * * * /etc/rc.d/init.d/rsync.sh

你可能感兴趣的:(安装gitlab+rsync增量同步代码库(CentOS7))