介绍一下在Ubuntu16.04系统下源码安装GitLab10.04且以MySQL作为数据库、SSL加密传输的步骤:
开始
Dependencies
安装依赖:
1 | $ sudo apt-get install -y build-essential zlib1g-dev libyaml-dev libssl-dev libgdbm-dev libre2-dev libreadline-dev libncurses5-dev libffi-dev curl openssh-server checkinstall libxml2-dev libxslt-dev libcurl4-openssl-dev libicu-dev logrotate rsync python-docutils pkg-config cmake |
为GitLab创建一个系统用户git:
1 | $ sudo adduser --disabled-login --gecos 'GitLab' git |
$ sudo apt-get install -y postfix
Git
安装最新版Git:
1 | $ sudo add-apt-repository ppa:git-core/ppa |
Ruby
安装最新版Ruby:
1 | $ sudo apt-add-repository ppa:brightbox/ruby-ng |
安装Bundler:
1 | $ sudo gem install bundler --no-ri --no-rdoc |
Go
安装Go1.9.2:
1 | $ curl --remote-name --progress https://dl.google.com/go/go1.9.2.linux-amd64.tar.gz |
Node
安装NodeJS8.x:
1 | $ curl --location https://deb.nodesource.com/setup_8.x | sudo bash - |
安装yarn:
1 | $ curl --silent --show-error https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - |
MySQL
安装MySQL5.7,先从MySQL官网下载APT配置器(mysql-apt-config_0.8.9-1_all.deb)[https://dev.mysql.com/downloads/file/?id=474129],然后:
1 | $ sudo dpkg -i mysql-apt-config_0.8.9-1_all.deb |
MySQL安全配置:
1 | $ |
创建GitLab用户和数据库:
1 | $ mysql -u root -p |
测试用户是否可以访问数据库:
1 | $ sudo -u git -H mysql -u git -p -D gitlabhq_production |
Redis
安装Redis3.0.6:
1 | $ sudo apt-get install redis |
GitLab
克隆GitLab源码
克隆GitLab源码,并配置GitLab(修改域名等等):
1 | $ cd /home/git |
配置GitLab
配置密钥文件:
1 | $ sudo -u git -H cp config/secrets.yml.example config/secrets.yml |
配置Unicorn(修改监听端口等等):
1 | $ sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb |
设置目录权限:
1 | $ sudo chown -R git log/ |
配置Rack Attack:
1 | $ sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb |
配置Resque(修改Redis链接等等):
1 | $ sudo -u git -H cp config/resque.yml.example config/resque.yml |
配置Git用户:
1 | # Configure Git global settings for git user |
数据库设置
配置MySQL(修改账户密码等等):
1 | $ sudo -u git cp config/database.yml.mysql config/database.yml |
安装Gems
安装Gems:
1 | # If you use MySQL (note, the option says "without ... postgres") |
安装GitLab Shell
安装GitLab Shell,并配置(修改GitLab链接等等):
1 | # Run the installation task for gitlab-shell (replace `REDIS_URL` if needed): |
安装Gitlab Workhorse
安装Gitlab Workhorse:
1 | $ sudo -u git -H bundle exec rake "gitlab:workhorse:install[/home/git/gitlab-workhorse]" RAILS_ENV=production |
secrets.yml
/home/git/gitlab/config/secrets.yml
文件存储着各类数据加密的钥匙,应备份在一个安全的地方。
安装启动脚本
安装在系统中启动GitLab服务的脚步:
1 | $ sudo cp lib/support/init.d/gitlab /etc/init.d/gitlab |
安装Gitaly
安装Gitaly,并配置:
1 | $ sudo -u git -H bundle exec rake "gitlab:gitaly:install[/home/git/gitaly]" RAILS_ENV=production |
设置Logrotate
1 | $ sudo cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab |
编译GetText PO
1 | $ sudo -u git -H bundle exec rake gettext:compile RAILS_ENV=production |
MySQL字符串限制
1 | $ sudo -u git -H bundle exec rake add_limits_mysql RAILS_ENV=production |
编译前端资源
1 | $ sudo -u git -H yarn install --production --pure-lockfile |
启动GitLab服务
启动或重启GitLab服务:
1 | $ sudo service gitlab start |
获取服务配置
1 | $ sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production |
检测服务状态
1 | $ sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production |
Nginx
安装最新版NginX:
1 | $ sudo add-apt-repository ppa:nginx/stable |
配置NginX代理(修改域名等等):
1 | $ sudo cp lib/support/nginx/gitlab /etc/nginx/sites-available/gitlab |
重启NginX服务:
1 | $ sudo service nginx start |
*Letsencrypt
安装Letsencrypt:
1 | $ sudo apt-get install letsencrypt |
申请密钥和证书:
1 | $ sudo letsencrypt sudo letsencrypt certonly --webroot -w /home/git/gitlab/public -d '$domainname' |
配置NginX代理(修改域名、密钥位置、证书位置等等):
1 | sudo cp lib/support/nginx/gitlab-ssl /etc/nginx/sites-available/gitlab |
重启NginX服务:
1 | $ sudo service nginx start |