centos7下的gitlab安装部署

转载  https://www.cnblogs.com/river2005/p/6757670.html

1、gitlab的搭建

安装基础包

yum -y install curl policycoreutils openssh-server openssh-clients


启动sshd

systemctl enable sshd

systemctl start sshd


安装postfix

yum -y install postfix

systemctl enable postfix

systemctl start postfix


添加防火墙规则

firewall-cmd --permanent --add-service=http

systemctl reload firewalld

or

yum install firewalld

systemctl unmask firewalld

下载并安装软件包

这是官网资源,下载较慢

curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bashyum install gitlab-ce

添加国内的镜像源

执行上面的命令,会一直 time out ,所以我们要换成国内的源.

以下操作针对CentOS 7 ,其他的请戳https://mirror.tuna.tsinghua.edu.cn/help/gitlab-ce/

编辑配置yum源

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

[gitlab-ce]

name=gitlab-ce

baseurl=http://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7repo_gpgcheck=0gpgcheck=0enabled=1

gpgkey=https://packages.gitlab.com/gpg.key

然后安装:

sudo yum makecache

sudo yum install gitlab-ce

默认安装的是最新的gitlab-ce的包,如果需要特定的版本可以在官网去下载特定的版本 地址:

https://packages.gitlab.com/gitlab/gitlab-ce/


配置并启动gitlab:

gitlab-ctl reconfigure


默认账户密码是:

Username: root

Password: 5iveL!fe

测试地址(默认80端口):

http://127.0.0.1/

2、gitlab的备份

备份命令

gitlab-rake gitlab:backup:create


默然的备份目录为:    /var/opt/gitlab/backups 备份文件名类似:      1393513186_gitlab_backup.tar

备份目录的修改

vi /etc/gitlab/gitlab.rb

gitlab_rails['backup_path'] = '/mnt/gitlab_backups'

3、gitlab数据的恢复或还原

提示:gitlab数据的恢复或者迁移成功的前提——两台服务器的gitlab的版本必须相同,若不相同则可能迁移或者恢复失败

将备份文件放在gitlab的默认备份目录

比如/var/opt/gitlab/backups下的1458217074_gitlab_backup.tar

设置自动备份:

0 2 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create


恢复或者还原

停服务

gitlab-ctl stop unicorn

gitlab-ctl stop sidekiq

恢复数据

gitlab-rake gitlab:backup:restore BACKUP=1458213020


BACKUP后面跟的是备份文件的时间戳,比如恢复备份文件1458217074_gitlab_backup.tar

gitlab-rake gitlab:backup:restore BACKUP=1458217074


恢复完启动服务

gitlab-ctl start

gitlab nginx修改

配置文件 /var/opt/gitlab/nginx/conf/gitlab-http.conf。这个文件是gitlab内置的nginx的配置文件,里面可以影响到nginx真实监听端口号。

server {

  listen *:82;

  server_name gitlab.123.123.cn;

  server_tokens off; ## Don't show the nginx version number, a security best practice

修改完成后,重启下,就可以放82端口的gitlab了。

gitlab-ctl restart

gitlab redis 启用

默认情况下gitlab是没有启用自带的redis的(虽然redis已经和gitlab一起启动):

ok: run: gitlab-workhorse: (pid 14263) 1s

ok: run: logrotate: (pid 14271) 0s

ok: run: nginx: (pid 14278) 1s

ok: run: node-exporter: (pid 14284) 0s

ok: run: postgres-exporter: (pid 14288) 1s

ok: run: postgresql: (pid 14303) 0s

ok: run: prometheus: (pid 14312) 1s

ok: run: redis: (pid 14317) 0s

ok: run: redis-exporter: (pid 14320) 0s3

ok: run: sidekiq: (pid 14330) 1s

ok: run: unicorn: (pid 14336) 0s

启用自带的redis,修改/etc/gitlab/gitlab.rb:

redis['port'] = 6379redis['bind'] = '127.0.0.1'

[root@localhost ~]# gitlab-ctl reconfigure

可以看到redis-server和端口6379,redis已经开始工作了:

Running handlers:

Running handlers complete

Chef Client finished, 15/397 resources updated in 25 seconds

gitlab Reconfigured!

[root@localhost ~]# gitlab-ctl restart

[root@localhost ~]# ps -ef|grep redis

root      639  632  0 14:54 ?        00:00:00 runsv redis

root      649  632  0 14:54 ?        00:00:00 runsv redis-exporter

root      653  639  0 14:54 ?        00:00:00 svlogd -tt /var/log/gitlab/redis

root      668  649  0 14:54 ?        00:00:00 svlogd -tt /var/log/gitlab/redis-exporter

gitlab-+ 14317  639  0 16:36 ?        00:00:00 /opt/gitlab/embedded/bin/redis-server 127.0.0.1:6379

gitlab-+ 14320  649  0 16:36 ?        00:00:00 /opt/gitlab/embedded/bin/redis_exporter -web.listen-address=localhost:9121 -redis.addr=unix:///var/opt/gitlab/redis/redis.socket

root    14376  8935  0 16:36 pts/2    00:00:00 grep --color=auto redis

访问一下gitlab主页和各页面,然后查看redis里的缓存清况,已经出现缓存内容了:

[root@localhost ~]# /opt/gitlab/embedded/bin/redis-cli 127.0.0.1:6379> keys *  1) "resque:gitlab:cron_job:admin_email_worker"  2) "resque:gitlab:cron_job:repository_archive_cache_worker"  3) "resque:gitlab:limit_fetch:probed:repository_import"  4) "cache:gitlab:last_commit_id_for_path:2af1c3ff162bb2...................

详细文档:https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/doc/settings/redis.md

你可能感兴趣的:(centos7下的gitlab安装部署)