电脑疯子技术论坛|电脑极客社区

微信扫一扫 分享朋友圈

已有 1694 人浏览分享

CentOS部署Gitlab代码管理平台

[复制链接]
1694 0
本帖最后由 zhaorong 于 2017-3-13 13:49 编辑

部署环境准备

Gitlab需要以下系统与软件环境:
Ruby (MRI) 2.1
Git 1.7.10+
Redis 2.4+
MySQL
由于系统的git,ruby环境一般版本比较低,因此需考虑升级。
1.升级git。
删除原系统的git:

  1. #rpm -eperl-Git-1.7.1-3.el6_4.1.noarch git-1.7.1-3.el6_4.1.x86_64
复制代码


源码包编译安装git:

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

  6.   2.升级ruby。
  7.   删除原系统的ruby:
  8. 1
  9. #rpm -e ruby-1.8.7.374-4.el6_6.x86_64ruby-libs-1.8.7.374-4.el6_6.x86
复制代码

源码包编译安装ruby:

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


3.安装,启动redis:

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


修改配置文件,如下:

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


启动redis:
         
  1. /opt/apps/redis/bin/redis-server /opt/conf/redis/redis.conf
  2.   4.安装,配置mysql(不详解)
  3.   登录mysql,创建gitlab用户与库:
  4. sql>create user 'gitlab'@'localhost' identified by '123456';
  5. sql>create database gitlabhq_production;
  6. sql>grant all privileges on gitlabhq_production.* to'gitlab'@'%';
  7. sql>flush privileges;
复制代码


5.安装bundler:
  修改gem源:(速度更快)

  1. gem sources --remove https://rubygems.org/
  2. gem sources -a https://ruby.taobao.org/
  3. 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
  2.   
复制代码


创建git用户:

  1. #adduser --system --shell /bin/bash--comment 'Gitlab' --create-home --home-dir /home/git/ git
  2. #chmod 775 /home/git
复制代码


上传gitlab项目源码包至/home/git,解压:
  1. #su - git
  2. $tar -zxvf gitlabhq-7.12.2.tar.gz
  3. $mv  gitlabhq-7.12.2 gitlab
复制代码


安装gitlab所需的组件:

  1. $cd gitlab
  2. $bundle install --deployment --without development test postgres awsKerberos
复制代码



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

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


数据库连接配置:

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



redis连接配置:

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


其他文件:

  1. $cp config/unicorn.rb.example config/unicorn.rb
  2. $cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb
  3. $cp config/initializers/smtp_settings.rb.sample config/initializers/smtp_settings.rb
复制代码

配置相关文件权限:

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


安装gitlab相关组件
  安装Gitlab-shell:
  1. $bundle exec rake gitlab:shell:installREDIS_URL=unix:/var/run/redis/redis.sock RAILS_ENV=production
  2. $cd /home/git/gitlab-shell
  3. $vi config.yml
  4. ---
  5. user: git
  6. gitlab_url: https://192.168.1.236/
  7. http_settings:
  8.   self_signed_cert:true
  9. repos_path:"/home/git/repositories/"
  10. auth_file:"/home/git/.ssh/authorized_keys"
  11. redis:
  12.   bin: "/opt/apps/redis//bin/redis-cli"
  13.   namespace: resque:gitlab
  14.   socket: "/opt/apps/redis/var/redis.sock"
  15. log_level:INFO
  16. audit_usernames:false
  17.   创建gitlab-satellites:
  18.          
  19. $mkdir -p /home/git/gitlab-satellites
复制代码


初始化gitlab

  初始化gitlab,创建mysql库表与仓库目录:
         
  1. $bundle exec rake gitlab:setup RAILS_ENV=production
  2.   若运行没有报错,则会生成初始root用户如下:
  3.   login.........root
  4.   password......5iveL!fe
复制代码


配置系统服务

  配置gitlab系统服务:(root用户下)
  1. #cd /home/git/gitlab   
  2. #cp lib/support/init.d/gitlab /etc/init.d/   
  3. #chmod +x /etc/init.d/gitlab
  4. #chkconfig --add gitlab

  5.   配置lograte:
  6.          
  7. cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab
复制代码


安装nginx web服务

安装nginx:
  1. #yum -y install yum -y install pcre*
  2. #tar -zxvfnginx-1.8.0.tar.gz
  3. #cd nginx-1.8.0
  4. #./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
  5. #make&& make install
复制代码


配置gitlab web服务(https模式),修改如下配置:
  1. #vi /opt/conf/nginx/nginx.conf
  2. includevhost/*.conf;
  3. #cp /home/git/gitlab/lib/support/nginx/gitlab-ssl/opt/conf/nginx/vhost/gitlab.conf
  4. #vi /opt/conf/nginx/vhost/gitlab.conf(修改相关端口的servername)
  5. server_name 192.168.1.236;
复制代码



开启服务与测试

  1. 开启nginx和gitlab服务:
  2. #/opt/apps/nginx/sbin/nginx -c /opt/conf/nginx/nginx.conf
  3. #servicegitlab start
  4.   使用命令检测gitlab的项目:
  5. #su - git
  6. $cd gitlab
  7. $bundle exec rake gitlab:checkRAILS_ENV=production
复制代码


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


itlab的备份与恢复

  备份:bundle exec rakegitlab:backup:create RAILS_ENV=production
  恢复:bundle exec rakegitlab:backup:restore RAILS_ENV=production
  以上是gitlab自带的备份工具命令,可备份mysql库表,gitlab仓库,ssh验证文件等一系列gitlab所需的文件。
  这里提供备份脚本给大家参考:

  1. #!/bin/bash
  2. # Author: chenminghui
  3. # Email: chenminghui@qq.com
  4. # Date: 2015-12-09
  5. ###set ENV###
  6. GITLAB_HOME=/home/git/gitlab
  7. BAK_DIR=/opt/backups/gitlab
  8. RAILS_ENV=production

  9. backup_gitlab ()
  10. {
  11. su - git -c "cd${GITLAB_HOME} && bundle exec rake gitlab:backup:createRAILS_ENV=${RAILS_ENV}"
  12. sleep 3
  13. RETVAL=$?
  14. if [ $RETVAL == 0 ];then
  15.         echo "The GitLab backupedsuccess.."
  16. else
  17.         echo "Backuk failure!!"
  18. fi
  19. }

  20. backup_gitlab

  21. #Delete backup files beforesysdate-30 days.
  22. find ${BAK_DIR} -type f-mtime +30 -exec rm -rf {} \;

  23. ##restore command if youneed..
  24. ##bundle exec rakegitlab:backup:restore RAILS_ENV=production BACKUP=timestamp_of_backup
复制代码





您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

关注

0

粉丝

9021

主题
精彩推荐
热门资讯
网友晒图
图文推荐

Powered by Pcgho! X3.4

© 2008-2022 Pcgho Inc.