GitLab服务构成
GitLab由以下服务构成:
 
nginx:静态Web服务器
gitlab-shell:用于处理Git命令和修改authorized keys列表
gitlab-workhorse:轻量级的反向代理服务器
logrotate:日志文件管理工具
postgresql:数据库
redis:缓存数据库
sidekiq:用于在后台执行队列任务(异步执行)
unicorn:An HTTP server for Rack applications,GitLab Rails应用是托管在这个服务器上面的。
Gitlab Shell
GitLab Shell有两个作用:为GitLab处理Git命令、修改authorized keys列表。
 
当通过SSH访问GitLab Server时,GitLab Shell会:
 
限制执行预定义好的Git命令(git push, git pull, git annex)
调用GitLab Rails API 检查权限
执行pre-receive钩子(在GitLab企业版中叫做Git钩子)
执行你请求的动作
处理GitLab的post-receive动作
处理自定义的post-receive动作
当通过http(s)访问GitLab Server时,工作流程取决于你是从Git仓库拉取(pull)代码还是向git仓库推送(push)代码。如果你是从Git仓库拉取(pull)代码,GitLab Rails应用会全权负责处理用户鉴权和执行Git命令的工作;如果你是向Git仓库推送(push)代码,GitLab Rails应用既不会进行用户鉴权也不会执行Git命令,它会把以下工作交由GitLab Shell进行处理:
 
调用GitLab Rails API 检查权限
执行pre-receive钩子(在GitLab企业版中叫做Git钩子)
执行你请求的动作
处理GitLab的post-receive动作
处理自定义的post-receive动作
也许你会奇怪在通过http(s)推送(push)代码的情况下,GitLab Rails应用为什么不在GitLab Shell之前进行鉴权。这是因为GitLab Rails应用没有解析git push命令的逻辑。好的方法是将这些解析代码放在一个地方,这个地方就是GitLab Shell,这样我们就可以在通过SSH进行访问时重用这段代码。实际上,GitLabShell在执行git push命令时根本不会进行权限检查,它是依赖于pre-receive钩子进行权限检查的。而当你执行git pull命令时,权限检查是在命令执行之前的。对git pull命令的权限检查要简单得多,因为你只需要检查一个用户是否可以访问这个仓库就可以了(不需要检查分支权限)。
 
好吧,GitLab Shell这段话都是翻译官网的。链接在这里
 
最后一段话有点拗口,我对此还是有一点问题的:既然你把git push的逻辑都放在GitLab Shell里面了,为什么不把git pull的逻辑也都放在里面提供重用呢?
猜想:git pull这段逻辑无法重用,因为通过http(s)方式访问时,要读取仓库的数据并且把这些数据封装成http包返回给客户端;而通过ssh方式访问时,仓库代码数据是通过ssh数据包返回的。两种访问方式返回数据的封装方式不一样,所以也没有必要提供重用。但是我觉得读取仓库数据这段逻辑应该还是重用了的。
GitLab Workhorse
GitLab Workhorse是一个敏捷的反向代理。它会处理一些大的HTTP请求,比如文件上传、文件下载、Git push/pull和Git包下载。其它请求会反向代理到GitLab Rails应用,即反向代理给后端的unicorn。官网对GitLab Workhorse的介绍在这里:https://gitlab.com/gitlab-org/gitlab-workhorse/
 
六、GitLab工作流程
 
GitLab工作流程图
Gitlab Shell
GitLab Shell有两个作用:为GitLab处理Git命令、修改authorized keys列表。
当通过SSH访问GitLab Server时,GitLab Shell会:
  1. 限制执行预定义好的Git命令(git push, git pull, git annex)
  2. 调用GitLab Rails API 检查权限
  3. 执行pre-receive钩子(在GitLab企业版中叫做Git钩子)
  4. 执行你请求的动作
  5. 处理GitLab的post-receive动作
  6. 处理自定义的post-receive动作
当通过http(s)访问GitLab Server时,工作流程取决于你是从Git仓库拉取(pull)代码还是向git仓库推送(push)代码。如果你是从Git仓库拉取(pull)代码,GitLab Rails应用会全权负责处理用户鉴权和执行Git命令的工作;如果你是向Git仓库推送(push)代码,GitLab Rails应用既不会进行用户鉴权也不会执行Git命令,它会把以下工作交由GitLab Shell进行处理:
  1. 调用GitLab Rails API 检查权限
  2. 执行pre-receive钩子(在GitLab企业版中叫做Git钩子)
  3. 执行你请求的动作
  4. 处理GitLab的post-receive动作
  5. 处理自定义的post-receive动作
也许你会奇怪在通过http(s)推送(push)代码的情况下,GitLab Rails应用为什么不在GitLab Shell之前进行鉴权。这是因为GitLab Rails应用没有解析git push命令的逻辑。好的方法是将这些解析代码放在一个地方,这个地方就是GitLab Shell,这样我们就可以在通过SSH进行访问时重用这段代码。实际上,GitLabShell在执行git push命令时根本不会进行权限检查,它是依赖于pre-receive钩子进行权限检查的。而当你执行git pull命令时,权限检查是在命令执行之前的。对git pull命令的权限检查要简单得多,因为你只需要检查一个用户是否可以访问这个仓库就可以了(不需要检查分支权限)。
好吧,GitLab Shell这段话都是翻译官网的。链接在这里
最后一段话有点拗口,我对此还是有一点问题的:既然你把git push的逻辑都放在GitLab Shell里面了,为什么不把git pull的逻辑也都放在里面提供重用呢?
猜想:git pull这段逻辑无法重用,因为通过http(s)方式访问时,要读取仓库的数据并且把这些数据封装成http包返回给客户端;而通过ssh方式访问时,仓库代码数据是通过ssh数据包返回的。两种访问方式返回数据的封装方式不一样,所以也没有必要提供重用。但是我觉得读取仓库数据这段逻辑应该还是重用了的。
GitLab Workhorse
GitLab Workhorse是一个敏捷的反向代理。它会处理一些大的HTTP请求,比如文件上传、文件下载、Git push/pull和Git包下载。其它请求会反向代理到GitLab Rails应用,即反向代理给后端的unicorn。官网对GitLab Workhorse的介绍在这里:https://gitlab.com/gitlab-org/gitlab-workhorse/
六、GitLab工作流程
 
 
 
#1.安装软件包及解决依赖项,升级系统
  1. yum -y update
#2.安装必须的软件
  1. yum -y install gcc autoconf cmake unzip vim libcurl-devel zlib-devel curl-devel expat-devel gettext-devel openssl-devel perl-devel nodejs libicu-devel wget curl
#安装git
  1. wget https://www.kernel.org/pub/software/scm/git/git-2.9.0.tar.gz
  2.  
  3. [root@t1 ~]# tar xf git-2.9.0.tar.gz
  4. [root@t1 ~]# cd git-2.9.0
  5. [root@t1 git-2.9.0]# ./configure
  6. [root@t1 git-2.9.0]# make prefix=/usr/local all
  7. # 安装到/usr/local/bin
  8. [root@t1 git-2.9.0]# make prefix=/usr/local install
  9. [root@t1 git-2.9.0]# source /etc/profile
  10. # 验证git版本号
  11. [root@t1 git-2.9.0]# git --version
  12. #查看git安装路径
  13. [root@t1 git-2.9.0]# which git
# 编辑 config/gitlab.yml (第7步中gitlab), 修改 git 路径为 /usr/local/bin/git !!!
#2.添加系统用户
#我们添加一个用来管理运行Gitlab的用户git
  1. [root@t1 ~]# useradd -c 'Gitlab' -s /bin/bash git

#为了包含/usr/local/bin到git用户的$PATH,一个方法是编辑超级用户文件。以管理员身份运行:

  1. $ visudo
  2.  
  3. #然后搜索:
  4. Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin
  5. #将其改成:
  6. Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin

#3.安装postfix

  1. yum -y install postfix

#4. Ruby

  1. #Note: The current supported Ruby version is 2.1.x. Ruby 2.2 and 2.3 are currently not supported.
  2.  
  3. [root@t1 ~]# yum -y remove ruby*
  4.  
  5. [root@t1 ~]# curl -O --progress https://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.8.tar.gz
  6. [root@t1 ~]# tar xf ruby-2.1.8.tar.gz
  7. [root@t1 ~]# cd ruby-2.1.8
  8. [root@t1 ~]# ./configure --disable-install-rdoc
  9. [root@t1 ~]# make
  10. [root@t1 ~]# make install
  11.  
  12. #Install the Bundler Gem:
  13. [root@t1 ~]# sudo gem install bundler --no-ri --no-rdoc

#5. Go

  1. #Since GitLab 8.0, Git HTTP requests are handled by gitlab-workhorse (formerly gitlab-git-http-server). This is a small daemon written in Go. To install gitlab-workhorse we need a Go compiler. The instructions below assume you use 64-bit Linux. You can find downloads for other platforms at the Go download page.
  2.  
  3. [root@t1 ~]# curl -O --progress https://storage.googleapis.com/golang/go1.5.3.linux-amd64.tar.gz
  4. [root@t1 ~]# tar -C /usr/local -xzf go1.5.3.linux-amd64.tar.gz
  5. [root@t1 ~]# ln -sf /usr/local/go/bin/{go,godoc,gofmt} /usr/local/bin/
  6. [root@t1 ~]# rm go1.5.3.linux-amd64.tar.gz

修改数据库

  1. #创建数据库,用户,添加权限
  2. MariaDB [(none)]> CREATE USER 'git'@'localhost' IDENTIFIED BY 'gitlab';
  3. mysql> SET storage_engine=INNODB;
  4. mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
  5. mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, CREATE TEMPORARY TABLES, DROP, INDEX, ALTER, LOCK TABLES, REFERENCES ON `gitlabhq_production`.* TO 'git'@'localhost';

#安装Redis

  1. yum install redis -y
  2. cp /etc/redis.conf /etc/redis.conf.orig
  3. #sed 's/^port .*/port 0/' /etc/redis.conf.orig |tee /etc/redis.conf #不需要执行
  4. echo 'unixsocket /var/run/redis/redis.sock' | sudo tee -a /etc/redis.conf
  5. echo 'unixsocketperm 770' | sudo tee -a /etc/redis.conf
  6. mkdir /var/run/redis
  7. chown redis:redis /var/run/redis
  8. chmod 755 /var/run/redis
  9.  
  10. # Persist the directory which contains the socket, if applicable
  11. if [ -d /etc/tmpfiles.d ]; then
  12. echo 'd /var/run/redis 0755 redis redis 10d -' | sudo tee -a /etc/tmpfiles.d/redis.conf
  13. fi
  14.  
  15. systemctl start redis
  16. chkconfig redis on
  17. usermod -aG redis git

#7. GitLab

  1. # We'll install GitLab into home directory of the user "git"
  2. cd /home/git
  3.  
  4. #Clone the Source
  5. # Clone GitLab repository
  6. sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 8-9-stable gitlab #注意gitlab的版本
  7.  
  8. #Configure It
  9. # Go to GitLab installation folder
  10. cd /home/git/gitlab
  11.  
  12. # Copy the example GitLab config
  13. sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml
  14.  
  15. # Update GitLab config file, follow the directions at top of file
  16. sudo -u git -H vim config/gitlab.yml
  17.  
  18. gitlab:
  19. ## Web server settings (note: host is the FQDN, do not include http://)
  20. host: gitlabtest.ptmind.com
  21. port: 443 # Set to 443 if using HTTPS, see installation.md#using-https for additional HTTPS configuration details
  22. https: true # Set to true if using HTTPS, see installation.md#using-https for additional HTTPS configuration details
  23.  
  24. bin_path: /usr/local/bin/git
  25.  
  26. # Copy the example secrets file #注意:如果将备份文件在异地恢复,需要将老版的secrets.yml拷贝到新版的对应目录下
  27. sudo -u git -H cp config/secrets.yml.example config/secrets.yml
  28. sudo -u git -H chmod 0600 config/secrets.yml
  29.  
  30. # Make sure GitLab can write to the log/ and tmp/ directories
  31. sudo chown -R git log/
  32. sudo chown -R git tmp/
  33. sudo chmod -R u+rwX,go-w log/
  34. sudo chmod -R u+rwX tmp/
  35.  
  36. # Make sure GitLab can write to the tmp/pids/ and tmp/sockets/ directories
  37. sudo chmod -R u+rwX tmp/pids/
  38. sudo chmod -R u+rwX tmp/sockets/
  39.  
  40. # Create the public/uploads/ directory
  41. sudo -u git -H mkdir public/uploads/
  42.  
  43. # Make sure only the GitLab user has access to the public/uploads/ directory
  44. # now that files in public/uploads are served by gitlab-workhorse
  45. sudo chmod 0700 public/uploads
  46.  
  47. # Change the permissions of the directory where CI build traces are stored
  48. sudo chmod -R u+rwX builds/
  49.  
  50. # Change the permissions of the directory where CI artifacts are stored
  51. sudo chmod -R u+rwX shared/artifacts/
  52.  
  53. # Copy the example Unicorn config
  54. sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb
  55.  
  56. # Find number of cores
  57. nproc
  58.  
  59. # Enable cluster mode if you expect to have a high load instance
  60. # Set the number of workers to at least the number of cores
  61. # Ex. change amount of workers to 3 for 2GB RAM server
  62. sudo -u git -H vim config/unicorn.rb
  63. worker_processes 10
  64. listen "127.0.0.1:8030", :tcp_nopush => true
  65.  
  66. # Copy the example Rack attack config
  67. sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb
  68.  
  69. # Configure Git global settings for git user
  70. # 'autocrlf' is needed for the web editor
  71. sudo -u git -H git config --global core.autocrlf input
  72.  
  73. # Disable 'git gc --auto' because GitLab already runs 'git gc' when needed
  74. sudo -u git -H git config --global gc.auto 0
  75.  
  76. # Configure Redis connection settings
  77. sudo -u git -H cp config/resque.yml.example config/resque.yml
  78.  
  79. # Change the Redis socket path if you are not using the default Debian / Ubuntu configuration
  80. # 修改Redis访问路径
  81. sudo -u git -H vim config/resque.yml
  82.  
  83. #Important Note: Make sure to edit both gitlab.yml and unicorn.rb to match your setup.
  84. #Note: If you want to use HTTPS, see Using HTTPS for the additional steps.
  85.  
  86. ##Configure GitLab DB Settings
  87. # MySQL only:
  88. sudo -u git cp config/database.yml.mysql config/database.yml
  89.  
  90. # Change 'secure password' with the value you have given to $password
  91. # You can keep the double quotes around the password
  92. sudo -u git -H vim config/database.yml
  93.  
  94. # MySQL:
  95. # Make config/database.yml readable to git only
  96. sudo -u git -H chmod o-rwx config/database.yml
安装 Gems
  1. cd /home/git/gitlab
  2.  
  3. # For users from China mainland only
  4. # 仅限中国大陆用户
  5. # vim /home/git/gitlab/Gemfile
  6. # source "https://ruby.taobao.org" // 原始 source "https://rubygems.org/"
  7.  
  8. # For MySQL (note, the option says "without ... postgres")
  9.  
  10. #修改ruby路径
  11. vim /usr/local/bin/bundle
  12. #!/usr/local/bin/ruby
  13.  
  14. # Or if you use MySQL (note, the option says "without ... postgres")
  15. sudo -u git -H bundle install -j5 --deployment --without development test postgres aws
  16.  
  17. 报错:
  18. Installing org-ruby 0.9.12
  19. Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
  20.  
  21. /usr/local/bin/ruby extconf.rb
  22. checking for ruby/thread.h... yes
  23. checking for rb_thread_call_without_gvl() in ruby/thread.h... yes
  24. checking for rb_thread_blocking_region()... yes
  25. checking for rb_wait_for_single_fd()... yes
  26. checking for rb_hash_dup()... yes
  27. checking for rb_intern3()... yes
  28. checking for mysql_query() in -lmysqlclient... no
  29. -----
  30. libmysqlclient is missing. Trying again with extra runtime libraries...
  31. -----
  32.  
  33. 解决:
  34. yum -y install mysql-devel
  35.  
  36. Install GitLab Shell
  37. #GitLab Shell is an SSH access and repository management software developed specially for GitLab.
  38. # Run the installation task for gitlab-shell (replace `REDIS_URL` if needed):
  39.  
  40. #如果redis在本地,可使用如下方式
  41. sudo -u git -H bundle exec rake gitlab:shell:install REDIS_URL=unix:/var/run/redis/redis.sock RAILS_ENV=production
  42.  
  43. #如果redis在其他服务器,可使用如下方式:
  44. sudo -u git -H bundle exec rake gitlab:shell:install REDIS_URL=redis://172.16.5.101:6379 RAILS_ENV=production
  45.  
  46. # By default, the gitlab-shell config is generated from your main GitLab config.
  47. # You can review (and modify) the gitlab-shell config as follows:
  48. sudo -u git -H vim /home/git/gitlab-shell/config.yml
  49. ---
  50. user: git
  51. gitlab_url: http://127.0.0.1:8030/ ######注意修改端口,修改主机名,并在hosts中添加解析!!!!
  52. http_settings:
  53. self_signed_cert: false
  54. repos_path: "/home/git/repositories/"
  55. auth_file: "/home/git/.ssh/authorized_keys"
  56. redis:
  57. bin: "/bin/redis-cli"
  58. namespace: resque:gitlab
  59. socket: "/var/run/redis/redis.sock"
  60. log_level: INFO
  61. audit_usernames: false

Install gitlab-workhorse

  1. cd /home/git
  2. sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-workhorse.git
  3. cd gitlab-workhorse
  4. sudo -u git -H git checkout v0.7.5
  5. sudo -u git -H make
  6.  
  7. 配置repositories
  8. 因为修改了repositories路径,因此使用下面的/data/repositories/
  9. sudo chmod -R ug+rwX,o-rwx /home/git/repositories/
  10. sudo chmod -R ug-s /home/git/repositories/
  11. sudo find /home/git/repositories/ -type d -print0 | sudo xargs -0 chmod g+s
  12.  
  13. sudo chmod -R ug+rwX,o-rwx /data/git/repositories/
  14. sudo chmod -R ug-s /data/git/repositories/
  15. sudo find /data/git/repositories/ -type d -print0 | sudo xargs -0 chmod g+s
  16.  
  17. Initialize Database and Activate Advanced Features
  18. # Go to GitLab installation folder
  19.  
  20. cd /home/git/gitlab
  21.  
  22. #sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production
  23. sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production GITLAB_ROOT_PASSWORD=yourpassword GITLAB_ROOT_EMAIL=youremail
  24.  
  25. # Type 'yes' to create the database tables.
  26.  
  27. # When done you see 'Administrator account created:'
  28.  
  29. #Secure secrets.yml
  30. # The secrets.yml file stores encryption keys for sessions and secure variables. Backup secrets.yml someplace safe, but don't store it in the same place as your database backups. Otherwise your secrets are exposed if one of your backups is compromised.
  31.  
  32. ls /home/git/gitlab/config/secrets.yml
  33.  
  34. # Install Init Script
  35. # Download the init script (will be /etc/init.d/gitlab):
  36.  
  37. sudo cp lib/support/init.d/gitlab /etc/init.d/gitlab
  38.  
  39. # 修改workhorse访问gitlab-shell端口
  40. vim /etc/init.d/gitlab
  41. gitlab_workhorse_options="-listenUmask 0 -listenNetwork unix -listenAddr $socket_path/gitlab-workhorse.socket -authBackend http://127.0.0.1:8030 -authSocket $rails_socket -documentRoot $app_root/public"
  42.  
  43. #And if you are installing with a non-default folder or user copy and edit the defaults file:
  44.  
  45. sudo cp lib/support/init.d/gitlab.default.example /etc/default/gitlab
  46.  
  47. # 修改workhorse访问gitlab-shell端口
  48. vim /etc/default/gitlab
  49. gitlab_workhorse_options="-listenUmask 0 -listenNetwork unix -listenAddr $socket_path/gitlab-workhorse.socket -authBackend http://127.0.0.1:8030 -authSocket $rails_socket -documentRoot $app_root/public"
#If you installed GitLab in another directory or as a user other than the default you should change these settings in /etc/default/gitlab. Do not edit /etc/init.d/gitlab as it will be changed on upgrade.
#Make GitLab start on boot:
  1. chkconfig gitlab on

#Setup Logrotate

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

#Check Application Status

#Check if GitLab and its environment are configured correctly:
  1. sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production

Compile Assets 编译静态文件

  1. sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production

# Start Your GitLab Instance

  1. sudo service gitlab start
Nginx配置
  1. yum -y install nginx
  2.  
  3. sudo cp lib/support/nginx/gitlab /etc/nginx/conf.d/gitlab.conf
  4.  
  5. vim /etc/nginx/conf.d/gitlab.conf
  6. ## GitLab
  7.  
  8. ## See installation.md#using-https for additional HTTPS configuration details.
  9.  
  10. upstream gitlab-workhorse {
  11. server unix:/home/git/gitlab/tmp/sockets/gitlab-workhorse.socket fail_timeout=0;
  12. }
  13.  
  14. ## Normal HTTP host
  15. server {
  16. ## Either remove "default_server" from the listen line below,
  17. ## or delete the /etc/nginx/sites-enabled/default file. This will cause gitlab
  18. ## to be served if you visit any address that your server responds to, eg.
  19. ## the ip address of the server (http://x.x.x.x/)n 0.0.0.0:80 default_server;
  20. # listen 0.0.0.0:80 default_server;
  21. # listen [::]:80 default_server;
  22. listen 80;
  23. server_name gitlabtest.ptmind.com; ## Replace this with something like gitlab.example.com
  24. server_tokens off; ## Don't show the nginx version number, a security best practice
  25.  
  26. ## See app/controllers/application_controller.rb for headers set
  27.  
  28. ## Individual nginx logs for this GitLab vhost
  29. access_log /var/log/nginx/gitlab_access.log;
  30. error_log /var/log/nginx/gitlab_error.log;
  31.  
  32. location / {
  33. client_max_body_size 0;
  34. gzip off;
  35.  
  36. ## https://github.com/gitlabhq/gitlabhq/issues/694
  37. ## Some requests take more than 30 seconds.
  38. proxy_read_timeout 300;
  39. proxy_connect_timeout 300;
  40. proxy_redirect off;
  41.  
  42. proxy_http_version 1.1;
  43.  
  44. proxy_set_header Host $http_host;
  45. proxy_set_header X-Real-IP $remote_addr;
  46. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  47. proxy_set_header X-Forwarded-Proto $scheme;
  48.  
  49. proxy_pass http://gitlab-workhorse;
  50. }
  51.  
  52. error_page 404 /404.html;
  53. error_page 422 /422.html;
  54. error_page 500 /500.html;
  55. error_page 502 /502.html;
  56. error_page 503 /503.html;
  57. location ~ ^/(404|422|500|502|503)\.html$ {
  58. root /home/git/gitlab/public;
  59. internal;
  60. }
  61.  
  62. }
  63.  
  64. ################Nginx ssl 配置文件####################
  65. upstream gitlab-workhorse {
  66. server unix:/home/git/gitlab/tmp/sockets/gitlab-workhorse.socket fail_timeout=0;
  67. }
  68. server {
  69. listen 0.0.0.0:80;
  70. server_name gitlab.ptengine.jp; ## Replace this with something like gitlab.example.com
  71. server_tokens off; ## Don't show the nginx version number, a security best practice
  72. return 301 https://$http_host$request_uri;
  73. access_log /var/log/nginx/gitlab_access.log;
  74. error_log /var/log/nginx/gitlab_error.log;
  75. }
  76. server {
  77. listen 0.0.0.0:443 ssl;
  78. server_name gitlab.ptengine.jp; ## Replace this with something like gitlab.example.com
  79. server_tokens off; ## Don't show the nginx version number, a security best practice
  80. ssl on;
  81. ssl_certificate /usr/local/nginx/ssl/www.ptengine.jp.pem;
  82. ssl_certificate_key /usr/local/nginx/ssl/www.ptengine.jp.key;
  83. ssl_ciphers "ECDHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-SHA384:ECDHE-RSA-AES128-SHA256:ECDHE-RSA-AES256-SHA:ECDHE-RSA-AES128-SHA:ECDHE-RSA-DES-CBC3-SHA:AES256-GCM-SHA384:AES128-GCM-SHA256:AES256-SHA256:AES128-SHA256:AES256-SHA:AES128-SHA:DES-CBC3-SHA:!aNULL:!eNULL:!EXPORT:!DES:!MD5:!PSK:!RC4";
  84. ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  85. ssl_prefer_server_ciphers on;
  86. ssl_session_cache shared:SSL:10m;
  87. ssl_session_timeout 5m;
  88. access_log /var/log/nginx/gitlab_access.log;
  89. error_log /var/log/nginx/gitlab_error.log;
  90. location / {
  91. client_max_body_size 0;
  92. gzip off;
  93. proxy_read_timeout 300;
  94. proxy_connect_timeout 300;
  95. proxy_redirect off;
  96. proxy_http_version 1.1;
  97. proxy_set_header Host $http_host;
  98. proxy_set_header X-Real-IP $remote_addr;
  99. proxy_set_header X-Forwarded-Ssl on;
  100. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  101. proxy_set_header X-Forwarded-Proto $scheme;
  102. proxy_pass http://gitlab-workhorse;
  103. }
  104. error_page 404 /404.html;
  105. error_page 422 /422.html;
  106. error_page 500 /500.html;
  107. error_page 502 /502.html;
  108. error_page 503 /503.html;
  109. location ~ ^/(404|422|500|502|503)\.html$ {
  110. root /home/git/gitlab/public;
  111. internal;
  112. }
  113. }
  114. ##############################################################

# 修改/home/git权限

  1. chmod 755 /home/git

# 检查安装

  1. cd /home/git/gitlab
  2. sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production

# 备份:

  1. ##修改默认的备份目录
  2. vim /home/git/gitlab/config/gitlab.yml
  3. backup:
  4. path: "/data/git/gitlab-backup/"
  5.  
  6. mkdir -p /data/git/gitlab-backup/
  7. chown -R git.git /data/git/gitlab-backup/
  8.  
  9. #重启 gitlab
  10. service gitlab restart
  11.  
  12. #执行备份
  13. sudo -u git -H bundle exec rake gitlab:backup:create RAILS_ENV=production
# 遇到的问题,执行备份失败,原因是读取config/database.yml文件中的password有问题,需要修改/home/git/gitlab/lib/backup/database.rb
  1. [root@nexus-5-101 gitlab]# sudo -u git -H bundle exec rake gitlab:backup:create RAILS_ENV=production
  2. Dumping database ...
  3. Dumping MySQL database gitlabhq_production ... mysqldump: Got error: 1045: "Access denied for user 'git'@'172.16.3.65' (using password: YES)" when trying to connect
  4. [FAILED]
  5. Backup failed
  6.  
  7. vim /home/git/gitlab/lib/backup/database.rb
  8. #第23行,将关于mysql的ENV['MYSQL_PWD']注销
  9. #第75行,mysql_args下面添加'password' => '--password',
  10. #########################################################################
  11. vim /home/git/gitlab/lib/backup/database.rb
  12.  
  13. require 'yaml'
  14.  
  15. module Backup
  16. class Database
  17. attr_reader :config, :db_file_name
  18.  
  19. def initialize
  20. @config = YAML.load_file(File.join(Rails.root,'config','database.yml'))[Rails.env]
  21. @db_file_name = File.join(Gitlab.config.backup.path, 'db', 'database.sql.gz')
  22. end
  23.  
  24. def dump
  25. FileUtils.mkdir_p(File.dirname(db_file_name))
  26. FileUtils.rm_f(db_file_name)
  27. compress_rd, compress_wr = IO.pipe
  28. compress_pid = spawn(*%W(gzip -1 -c), in: compress_rd, out: [db_file_name, 'w', 0600])
  29. compress_rd.close
  30.  
  31. dump_pid = case config["adapter"]
  32. when /^mysql/ then
  33. $progress.print "Dumping MySQL database #{config['database']} ... "
  34. # Workaround warnings from MySQL 5.6 about passwords on cmd line
  35. # ENV['MYSQL_PWD'] = config["password"].to_s if config["password"]
  36. spawn('mysqldump', *mysql_args, config['database'], out: compress_wr)
  37. when "postgresql" then
  38. $progress.print "Dumping PostgreSQL database #{config['database']} ... "
  39. pg_env
  40. pgsql_args = ["--clean"] # Pass '--clean' to include 'DROP TABLE' statements in the DB dump.
  41. if Gitlab.config.backup.pg_schema
  42. pgsql_args << "-n"
  43. pgsql_args << Gitlab.config.backup.pg_schema
  44. end
  45. spawn('pg_dump', *pgsql_args, config['database'], out: compress_wr)
  46. end
  47. compress_wr.close
  48.  
  49. success = [compress_pid, dump_pid].all? { |pid| Process.waitpid(pid); $?.success? }
  50.  
  51. report_success(success)
  52. abort 'Backup failed' unless success
  53. end
  54.  
  55. def restore
  56. decompress_rd, decompress_wr = IO.pipe
  57. decompress_pid = spawn(*%W(gzip -cd), out: decompress_wr, in: db_file_name)
  58. decompress_wr.close
  59.  
  60. restore_pid = case config["adapter"]
  61. when /^mysql/ then
  62. $progress.print "Restoring MySQL database #{config['database']} ... "
  63. # Workaround warnings from MySQL 5.6 about passwords on cmd line
  64. ENV['MYSQL_PWD'] = config["password"].to_s if config["password"]
  65. spawn('mysql', *mysql_args, config['database'], in: decompress_rd)
  66. when "postgresql" then
  67. $progress.print "Restoring PostgreSQL database #{config['database']} ... "
  68. pg_env
  69. spawn('psql', config['database'], in: decompress_rd)
  70. end
  71. decompress_rd.close
  72.  
  73. success = [decompress_pid, restore_pid].all? { |pid| Process.waitpid(pid); $?.success? }
  74.  
  75. report_success(success)
  76. abort 'Restore failed' unless success
  77. end
  78.  
  79. protected
  80.  
  81. def mysql_args
  82. args = {
  83. 'host' => '--host',
  84. 'port' => '--port',
  85. 'socket' => '--socket',
  86. 'username' => '--user',
  87. 'password' => '--password',
  88. 'encoding' => '--default-character-set'
  89. }
  90. args.map { |opt, arg| "#{arg}=#{config[opt]}" if config[opt] }.compact
  91. end
  92.  
  93. def pg_env
  94. ENV['PGUSER'] = config["username"] if config["username"]
  95. ENV['PGHOST'] = config["host"] if config["host"]
  96. ENV['PGPORT'] = config["port"].to_s if config["port"]
  97. ENV['PGPASSWORD'] = config["password"].to_s if config["password"]
  98. end
  99.  
  100. def report_success(success)
  101. if success
  102. $progress.puts '[DONE]'.color(:green)
  103. else
  104. $progress.puts '[FAILED]'.color(:red)
  105. end
  106. end
  107. end
  108. end
  109. #########################################################################

#再次执行备份:

  1. sudo -u git -H bundle exec rake gitlab:backup:create RAILS_ENV=production

#恢复

恢复时要确保两边的gitlab版本是一样的
  1. # Stop processes that are connected to the database
  2. sudo service gitlab stop
  3.  
  4. sudo -u git -H bundle exec rake gitlab:backup:restore RAILS_ENV=production BACKUP=1474170453
  5.  
  6. # Options:
  7. BACKUP=timestamp_of_backup (required if more than one backup exists)
  8. force=yes (do not ask if the authorized_keys file should get regenerated)

源码安装gitlab的更多相关文章

  1. ubuntu 16.04.2 源码安装gitlab并且利用runner持续集成

    参考原档:https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/install/installation.md#using-https 本章只 ...

  2. gitlab 源码安装=》rpm安装横向迁移(version 9.0)

    准备: 下载版本地址: https://packages.gitlab.com/gitlab/gitlab-ce 迁移环境: 源码安装的gitlab9.0.13 目标迁移至9.0.13 RPM安装的环 ...

  3. mono-3.4.0 源码安装时出现的问题 [do-install] Error 2 [install-pcl-targets] Error 1 解决方法

    Mono 3.4修复了很多bug,继续加强稳定性和性能(其实Mono 3.2.8 已经很稳定,性能也很好了),但是从http://download.mono-project.com/sources/m ...

  4. 搭建LNAMP环境(七)- PHP7源码安装Memcached和Memcache拓展

    上一篇:搭建LNAMP环境(六)- PHP7源码安装MongoDB和MongoDB拓展 一.安装Memcached 1.yum安装libevent事件触发管理器 yum -y install libe ...

  5. 搭建LNAMP环境(二)- 源码安装Nginx1.10

    上一篇:搭建LNAMP环境(一)- 源码安装MySQL5.6 1.yum安装编译nginx需要的包 yum -y install pcre pcre-devel zlib zlib-devel ope ...

  6. 搭建LNAMP环境(一)- 源码安装MySQL5.6

    1.yum安装编译mysql需要的包 yum -y install gcc-c++ make cmake bison-devel ncurses-devel perl 2.为mysql创建一个新的用户 ...

  7. Greenplum 源码安装教程 —— 以 CentOS 平台为例

    Greenplum 源码安装教程 作者:Arthur_Qin 禾众 Greenplum 主体以及orca ( 新一代优化器 ) 的代码以可以从 Github 上下载.如果不打算查看代码,想下载编译好的 ...

  8. salt源码安装软件和yum安装软件

    上面简单列出了源码安装的sls文件书写思路. 涉及到一些固定的思路:如, 1,拷贝 解压安装时候需要依赖tar.gz存在 如果已安装则无需再次安装. 2,启动脚本 加入chk时候需要文件存在,如果已添 ...

  9. 搭建LNAMP环境(六)- PHP7源码安装MongoDB和MongoDB拓展

    上一篇:搭建LNAMP环境(五)- PHP7源码安装Redis和Redis拓展 一.安装MongoDB 1.创建mongodb用户组和用户 groupadd mongodb useradd -r -g ...

随机推荐

  1. 【LeetCode】1417. 重新格式化字符串 Reformat The String

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 栈 日期 题目地址:https://leetcode- ...

  2. 【LeetCode】286. Walls and Gates 解题报告 (C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客:http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 BFS 日期 题目地址:https://leetcod ...

  3. 【九度OJ】题目1185:特殊排序 解题报告

    [九度OJ]题目1185:特殊排序 解题报告 标签(空格分隔): 九度OJ [LeetCode] http://ac.jobdu.com/problem.php?pid=1185 题目描述: 输入一系 ...

  4. 【剑指Offer】连续子数组的最大和 解题报告(Python)

    [剑指Offer]连续子数组的最大和 解题报告(Python) 标签(空格分隔): 剑指Offer 题目地址:https://www.nowcoder.com/ta/coding-interviews ...

  5. Fast Matrix Operations(UVA)11992

    UVA 11992 - Fast Matrix Operations 给定一个r*c(r<=20,r*c<=1e6)的矩阵,其元素都是0,现在对其子矩阵进行操作. 1 x1 y1 x2 y ...

  6. Optimal Symmetric Paths(UVA12295)

    Description   You have a grid of n rows and n columns. Each of the unit squares contains a non-zero ...

  7. MySQL中的where和having

    group by 在select 语句中可以使用group by 子句将行划分成较小的组,然后,使用聚组函数返回每一个组的汇总信息,另外,可以使用having子句限制返回的结果集.group by 子 ...

  8. 物联网大赛 - Android学习笔记(三)Android 事件处理

    学习目标: 了解事件处理概念 监听事件处理模型 事件与事件监听接口 实现事件监听方式 回调事件处理模型 常见的事件回调方法 Handler类功能与用法 Handler更新程序界面 一.监听概念 再用户 ...

  9. mysql总结笔记 -- 索引篇

    索引的作用 索引是用来高效的获取数据的 排好序 的 数据结构,如果没有索引,可能会导致查询某一条记录的时候遍历整张表:所以适当的索引可以大大的提升检索速度: 索引的数据结构 二叉树 假如说我们有一列数 ...

  10. PostgresSQL客户端pgAdmin4使用

    1.说明 pgAdmin 4是一款为PostgreSQL设计的可靠和全面的数据库设计和管理软件, 它允许您连接到特定的数据库,创建表和运行各种从简单到复杂的SQL语句. 它支持的操作系统包括Linux ...