Gitlab代码管理平台部署(CentOS6.7—gitlab7.2.12)

本文涉及的产品
云数据库 Redis 版,社区版 2GB
推荐场景:
搭建游戏排行榜
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介:

部署环境准备

Gitlab需要以下系统与软件环境:

Ruby (MRI) 2.1

Git 1.7.10+

Redis 2.4+

MySQL

由于系统的git,ruby环境一般版本比较低,因此需考虑升级。

1.升级git

删除原系统的git

1
#rpm -e perl-Git-1.7.1-3.el6_4.1.noarch git-1.7.1-3.el6_4.1.x86_64

  源码包编译安装git

1
2
3
4
5
#tar -zxvf git-2.6.3.tar.gz
#cd git-2.6.3
#autoconf
#./configure
#make && make install

  2.升级ruby。

  删除原系统的ruby

1
#rpm -e ruby-1.8.7.374-4.el6_6.x86_64 ruby-libs-1.8.7.374-4.el6_6.x86_64

  源码包编译安装ruby

1
2
3
4
#tar -zxvf ruby-2.1.7.tar.gz
#cd ruby-2.1.7
#./configure
#make && make install

  3.安装,启动redis:

1
2
3
4
5
6
7
8
9
#tar zxvf redis-3.0.5.tar.gz
#cd redis-3.0.5
#make install
#mkdir  -p /opt/apps/redis/bin
#mkdir  -p /opt/apps/redis/var
#mkdir  -p/opt/apps/redis/data
#mkdir  -p /opt/conf/redis
#cp  redis.conf  /opt/conf/redis
#cp /opt/src/redis-3.0.5/src/redis-* /opt/apps/redis/bin

修改配置文件,如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#grep -v ^# /opt/conf/redis/redis.conf | grep -v ^$
daemonize  yes
pidfile  /opt/apps/redis/var/redis .pid
port 6379
tcp-backlog 511
bind 192.168.1.236
unixsocket  /opt/apps/redis/var/redis .sock
unixsocketperm 777
timeout 0
tcp-keepalive 0
loglevel notice
logfile  "/opt/logs/redis/redis.log"
databases 16
stop-writes-on-bgsave-error  yes
rdbcompression  yes
rdbchecksum  yes
dbfilename dump.rdb
dir  /opt/apps/redis/var
slave-serve-stale-data  yes
slave- read -only  yes
repl-diskless- sync  no
repl-diskless- sync -delay 5
repl-disable-tcp-nodelay no
slave-priority 100
appendonly no
appendfilename  "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated  yes
lua- time -limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events  ""
hash -max-ziplist-entries 512
hash -max-ziplist-value 64
list-max-ziplist-entries 512
list-max-ziplist-value 64
set -max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing  yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync  yes

  启动redis:

1
/opt/apps/redis/bin/redis-server  /opt/conf/redis/redis .conf

  4.安装,配置mysql(不详解)

  登录mysql,创建gitlab用户与库:

1
2
3
4
sql>create user  'gitlab' @ 'localhost'  identified by  '123456' ;
sql>create database gitlabhq_production;
sql>grant all privileges on gitlabhq_production.* to 'gitlab' @ '%' ;
sql>flush privileges;

  5.安装bundler:

  修改gem源:(速度更快)

 

1
2
3
gem sources --remove https: //rubygems .org/
gem sources -a https: //ruby .taobao.org/
gem  install  bundler --no-ri --no-rdoc


安装与配置gitlab

  安装相关依赖包:

1
#yum -y install readline readline-develncurses-devel gdbm-devel glibc-devel tcl-devel openssl-devel curl-develexpat-devel db4-devel byacc sqlite-devel libyaml libyaml-devel libffilibffi-devel libxml2 libxml2-devel libxslt libxslt-devel libicu libicu-develsystem-config-firewall-tui redis sudo wget crontabs logwatch logrotateperl-Time-HiRes git cmake libcom_err-devel libcom_err-devel mysql-devel libicu-devel.x86_64 patch

  创建git用户:

1
2
#adduser --system --shell /bin/bash --comment 'Gitlab' --create-home --home-dir /home/git/ git
#chmod 775 /home/git

  上传gitlab项目源码包至/home/git,解压:

1
2
3
#su - git
$ tar  -zxvf gitlabhq-7.12.2. tar .gz
$ mv   gitlabhq-7.12.2 gitlab

  安装gitlab所需的组件:

1
2
$ cd  gitlab
$bundle  install  --deployment --without development  test  postgres awsKerberos

  创建gitlab配置文件,并修改如下配置:

1
2
3
4
5
6
7
8
$ cp  config /gitlab .yml.example config /gitlab .yml
$ vi  config /gitlabyml
gitlab:
host: 192.168.1.236
port: 443
https:  true
backup:
     path:  "/opt/backups/gitlab"

  数据库连接配置:

1
2
3
4
5
6
7
8
9
10
11
12
13
$ cp  config /database .yml.mysql config /database .yml
$ vi  config /database .yml
production:
   adapter: mysql2
   encoding: utf8
   collation: utf8_general_ci
   reconnect:  false
   database:gitlabhq_production
   pool: 10
   username: gitlab
   password:  "123456"
   host: localhost
   socket:  /tmp/mysql .sock

  redis连接配置:

1
2
3
$ cp  config /resque .yml.example config /resque .yml
$ vi  config /resque .yml
production: unix: /opt/apps/redis/var/redis .sock

  其他文件:

1
2
3
$ cp  config /unicorn .rb.example config /unicorn .rb
$ cp  config /initializers/rack_attack .rb.example config /initializers/rack_attack .rb
$ cp  config /initializers/smtp_settings .rb.sample config /initializers/smtp_settings .rb

  配置相关文件权限:

1
2
3
4
5
6
7
8
$ chmod  -R u+rwX,go-w log/
$ chmod  -R u+rwX tmp/
$ chmod  -R u+rwX tmp /pids/
$ chmod  -R u+rwX tmp /sockets/
$ mkdir  public /uploads
$ chmod  -R u+rwX public /uploads
$ chmod  -R u+rwX builds/
$ chmod  -R u+rwX shared /artifacts/


安装gitlab相关组件

  安装Gitlab-shell:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$bundle  exec  rake gitlab:shell: install  REDIS_URL=unix: /var/run/redis/redis .sock RAILS_ENV=production
$ cd  /home/git/gitlab-shell
$ vi  config.yml
---
user: git
gitlab_url: https: //192 .168.1.236/
http_settings:
   self_signed_cert: true
repos_path: "/home/git/repositories/"
auth_file: "/home/git/.ssh/authorized_keys"
redis:
   bin:  "/opt/apps/redis//bin/redis-cli"
   namespace: resque:gitlab
   socket:  "/opt/apps/redis/var/redis.sock"
log_level:INFO
audit_usernames: false

  创建gitlab-satellites:

1
$ mkdir  -p  /home/git/gitlab-satellites


初始化gitlab

  初始化gitlab,创建mysql库表与仓库目录:

1
$bundle  exec  rake gitlab:setup RAILS_ENV=production

  若运行没有报错,则会生成初始root用户如下:

  login.........root

  password......5iveL!fe

 安装gitlab网页样式:

1
$bundle  exec  rake assets:precompile RAILS_ENV=production RAILS_RELATIVE_URL_ROOT= /gitlab


配置系统服务

  配置gitlab系统服务:(root用户下)

1
2
3
4
#cd /home/git/gitlab   
#cp lib/support/init.d/gitlab /etc/init.d/   
#chmod +x /etc/init.d/gitlab
#chkconfig --add gitlab

  配置lograte:

1
cp  lib /support/logrotate/gitlab  /etc/logrotate .d /gitlab


安装nginx web服务

 安装nginx:

1
2
3
4
5
#yum -y install yum -y install pcre*
#tar -zxvfnginx-1.8.0.tar.gz
#cd nginx-1.8.0
#./configure--prefix=/opt/apps/nginx --conf-path=/opt/conf/nginx/nginx.conf--error-log-path=/opt/logs/nginx/error.log--http-log-path=/opt/logs/nginx/access.log --with-http_stub_status_module--with-http_gzip_static_module --with-http_flv_module --with-http_ssl_module--with-http_realip_module--http-client-body-temp-path=/opt/apps/nginx/client_body_temp--http-fastcgi-temp-path=/opt/apps/nginx/fastcgi_temp--http-proxy-temp-path=/opt/apps/nginx/proxy_temp--http-uwsgi-temp-path=/opt/apps/nginx/uwsgi_temp--http-scgi-temp-path=/opt/apps/nginx/scgi_temp
#make&& make install


  配置gitlab web服务(https模式),修改如下配置:

1
2
3
4
5
#vi /opt/conf/nginx/nginx.conf
includevhost/*.conf;
#cp /home/git/gitlab/lib/support/nginx/gitlab-ssl/opt/conf/nginx/vhost/gitlab.conf
#vi /opt/conf/nginx/vhost/gitlab.conf(修改相关端口的servername)
server_name 192.168.1.236;


开启服务与测试

  开启nginx和gitlab服务:

1
2
#/opt/apps/nginx/sbin/nginx -c /opt/conf/nginx/nginx.conf
#service gitlab start

  使用命令检测gitlab的项目:

1
2
3
#su - git
$ cd  gitlab
$bundle  exec  rake gitlab:check RAILS_ENV=production

  检测通过后就可以用浏览器访问gitlab了:

wKioL1Zqc3HiulO9AADq-bq8CnY626.png

wKiom1Zqc3GgWP0hAAC9PGKOiN4161.png

Gitlab的备份与恢复


  备份:bundle exec rakegitlab:backup:create RAILS_ENV=production

  恢复:bundle exec rakegitlab:backup:restore RAILS_ENV=production

  以上是gitlab自带的备份工具命令,可备份mysql库表,gitlab仓库,ssh验证文件等一系列gitlab所需的文件。

  这里提供备份脚本给大家参考:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/bin/bash
# Author: chenminghui
# Email: chenminghui@qq.com
# Date: 2015-12-09
###set ENV###
GITLAB_HOME= /home/git/gitlab
BAK_DIR= /opt/backups/gitlab
RAILS_ENV=production
  
backup_gitlab ()
{
su  - git -c  "cd${GITLAB_HOME} && bundle exec rake gitlab:backup:createRAILS_ENV=${RAILS_ENV}"
sleep  3
RETVAL=$?
if  [ $RETVAL == 0 ]; then
         echo  "The GitLab backupedsuccess.."
else
         echo  "Backuk failure!!"
fi
}
  
backup_gitlab
  
#Delete backup files beforesysdate-30 days.
find  ${BAK_DIR} - type  f-mtime +30 - exec  rm  -rf {} \;
  
##restore command if youneed..
##bundle exec rakegitlab:backup:restore RAILS_ENV=production BACKUP=timestamp_of_backup









本文转自 icenycmh 51CTO博客,原文链接:http://blog.51cto.com/icenycmh/1722029,如需转载请自行联系原作者

相关实践学习
基于Redis实现在线游戏积分排行榜
本场景将介绍如何基于Redis数据库实现在线游戏中的游戏玩家积分排行榜功能。
云数据库 Redis 版使用教程
云数据库Redis版是兼容Redis协议标准的、提供持久化的内存数据库服务,基于高可靠双机热备架构及可无缝扩展的集群架构,满足高读写性能场景及容量需弹性变配的业务需求。 产品详情:https://www.aliyun.com/product/kvstore     ------------------------------------------------------------------------- 阿里云数据库体验:数据库上云实战 开发者云会免费提供一台带自建MySQL的源数据库 ECS 实例和一台目标数据库 RDS实例。跟着指引,您可以一步步实现将ECS自建数据库迁移到目标数据库RDS。 点击下方链接,领取免费ECS&RDS资源,30分钟完成数据库上云实战!https://developer.aliyun.com/adc/scenario/51eefbd1894e42f6bb9acacadd3f9121?spm=a2c6h.13788135.J_3257954370.9.4ba85f24utseFl
目录
相关文章
|
3月前
|
Linux
CentOS7.9服务器一键脚本部署FRP内网穿透服务端与客户端
CentOS7.9服务器一键脚本部署FRP内网穿透服务端与客户端
228 0
|
4月前
|
人工智能 JavaScript Linux
Nuxt.js在centos7上的发布部署
Nuxt.js在centos7上的发布部署
Nuxt.js在centos7上的发布部署
|
2月前
|
JavaScript Java 应用服务中间件
centos部署vue项目(java,tomcat环境的搭建)
centos部署vue项目(java,tomcat环境的搭建)
45 0
|
3月前
|
监控 安全 Linux
CentOS7下部署ARL资产侦察灯塔系统
CentOS7下部署ARL资产侦察灯塔系统
172 3
|
1月前
|
分布式计算 关系型数据库 MySQL
Sqoop【部署 01】CentOS Linux release 7.5 安装配置 sqoop-1.4.7 解决警告并验证(附Sqoop1+Sqoop2最新版安装包+MySQL驱动包资源)
【2月更文挑战第8天】Sqoop CentOS Linux release 7.5 安装配置 sqoop-1.4.7 解决警告并验证(附Sqoop1+Sqoop2最新版安装包+MySQL驱动包资源)
100 1
|
2月前
|
存储 NoSQL Linux
centos7部署redis以及多实例
centos7部署redis以及多实例
60 0
|
11天前
|
JavaScript Linux 数据安全/隐私保护
如何在CentOS7部署Wiki.js知识库并实现分享好友公网远程使用【内网穿透】
如何在CentOS7部署Wiki.js知识库并实现分享好友公网远程使用【内网穿透】
|
14天前
无缝构建与部署:GitLab CI/CD首秀的实战攻略
无缝构建与部署:GitLab CI/CD首秀的实战攻略
25 0
无缝构建与部署:GitLab CI/CD首秀的实战攻略
|
17天前
|
存储 Linux Shell
centos 部署docker容器 安装 、基本使用方法(一)
centos 部署docker容器 安装 、基本使用方法(一)
32 0
|
17天前
|
分布式计算 Hadoop Java
centos 部署Hadoop-3.0-高性能集群(一)安装
centos 部署Hadoop-3.0-高性能集群(一)安装
17 0