系统版本:Ubuntu 14.04.3 64位
安装步骤
1. 安装 GitLab 需要的包及依赖软
更新系统
apt-get update -y apt-get upgrade -y apt-getinstall sudo -y
安装vim编辑器(可选)
sudo apt-get install -y vim sudou pdate-alternatives --set editor /usr/bin/vim.basic
安装依赖包(编译 Ruby 以及 Ruby gems 的本地扩展)
sudo apt-get install -y build-essential zlib1g-dev libyaml-dev libssl-dev libgdbm-dev libreadline-dev libncurses5-dev libffi-dev curl openssh-server redis-server checkinstall libxml2-dev libxslt-dev libcurl4-openssl-dev libicu-dev logrotate python-docutils pkg-config cmake nodejs libkrb5-dev(可选)
安装 Git
sudo apt-get install -y git-core
为了正常使用邮件通知服务,需要简单配置一下postfix邮件服务器,安装的时候选择InternetSite, 配置一下hostname。
sudo apt-get install -y postfix
2,ruby安装
如果系统安装的 Ruby版本是1.8,需要先卸载一下,GitLab需要 2.0以上版本:
ruby --version sudo apt-get remove ruby1.8
下载新版本的源代码,编译安装:
mkdir /tmp/ruby && cd /tmp/ruby curl-L --progress http://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.6.tar.gz | tar xz cd ruby-2.1.6 ./configure --disable-install-rdoc make sudo make install
安装 ruby Bundle Gem:
sudo gem install bundler --no-ri --no-rdoc
bundle config mirror.https://rubygems.org https://ruby.taobao.org
3.SystemUser
sudo adduser --disabled-login --gecos'GitLab' git
4.Database(mysql)
sudo apt-get install -y mysql-server mysql-client libmysqlclient-dev
sudo mysql_secure_installation
mysql -u root -p
mysql> CREATE USER 'git'@'localhost'IDENTIFIED BY '$password';
mysql> SET storage_engine=INNODB;
mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
mysql> GRANT SELECT, INSERT, UPDATE,DELETE, CREATE, DROP, INDEX, ALTER, LOCK TABLES ON `gitlabhq_production`.* TO'git'@'localhost';
mysql> \q
sudo -u git -H mysql -u git -p -Dgitlabhq_production
mysql> \q
5.安装 Redis
sudo apt-get install redis-server
sudo cp /etc/redis/redis.conf /etc/redis/redis.conf.orig
sed 's/^port .*/port 0/'/etc/redis/redis.conf.orig | sudo tee /etc/redis/redis.conf
echo 'unixsocket/var/run/redis/redis.sock' | sudo tee -a /etc/redis/redis.conf
echo 'unixsocketperm 770' | sudo tee -a/etc/redis/redis.conf
mkdir /var/run/redis
chown redis:redis /var/run/redis
chmod 755 /var/run/redis
if [ -d /etc/tmpfiles.d ]; then
echo 'd /var/run/redis 0755 redis redis 10d -'| sudo tee -a /etc/tmpfiles.d/redis.conf
fi
sudo service redis-server restart
sudo usermod -aG redis git
6. 安装 GitLab
# We'll install GitLab into home directory ofthe user "git" cd /home/git
从 GitHub克隆一份源码:
sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 7-12-stable gitlab
配置 GitLab:
cd /home/git/gitlab
sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml
vim /home/git/gitlab/config/gitlab.yml
修改配置
sudo chown -R git log/
sudo chown -R git tmp/
sudo chmod -R u+rwX,go-w log/
sudo chmod -R u+rwX tmp/
sudo -u git -H mkdir /home/git/gitlab-satellites
sudo chmod u+rwx,g=rx,o-rwx /home/git/gitlab-satellites
sudo chmod -R u+rwX tmp/pids/
sudo chmod -R u+rwX tmp/sockets/
sudo chmod -R u+rwX public/uploads
sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb
nproc
vim /home/git/gitlab/config/unicorn.rb
注释这一行 # listen "127.0.0.1:8080", :tcp_nopush => true
sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb
sudo -u git -H git config --globalcore.autocrlf input
sudo -u git -H cp config/resque.yml.example config/resque.yml
vim /home/git/gitlab/config/resque.yml
配置数据库:
sudo -u git cp config/database.yml.mysqlconfig/database.yml
安装 Gems:
sudo -u git -H bundle install --deployment--without development test postgres aws Kerberos
安装 GitLab的命令行工具:
sudo -u git -H bundle exec rakegitlab:shell:install[v2.6.3] REDIS_URL=unix:/var/run/redis/redis.sockRAILS_ENV=production
git clone https://github.com/gitlabhq/gitlab-shell.git
vim /home/git/gitlab-shell/config.yml
初始化数据库以及激活高级功能:
sudo -u git -H bundle exec rakegitlab:setup RAILS_ENV=production
sudo -u git -H bundle exec rakegitlab:setup RAILS_ENV=production GITLAB_ROOT_PASSWORD=yourpassword(可选)
安装初始化脚本:
sudo cp lib/support/init.d/gitlab /etc/init.d/gitlab
sudo cp lib/support/init.d/gitlab.default.example /etc/default/gitlab
sudo update-rc.d gitlab defaults 21
设置 logroate:
sudo cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab
检查应用程序的状态:
sudo -u git -H bundle exec rakegitlab:env:info RAILS_ENV=production
编译资源文件:
sudo -u git -H bundle exec rakeassets:precompile RAILS_ENV=production
启动 GitLab实例:
sudo service gitlab start
/etc/init.d/gitlab restart
7.Nginx
sudo apt-get install -y nginx
复制 GitLab的虚拟主机配置文件到 nginx
sudo cp lib/support/nginx/gitlab /etc/nginx/sites-available/gitlab
sudo ln -s/etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab
vim /etc/nginx/sites-available/gitlab
server_name 10.9.210.16;
sudo nginx -t
sudo service nginx restart
sudo -u git -H bundle exec rakegitlab:check RAILS_ENV=production
启用ssl认证,加密访问:
mkdir -p /etc/nginx/ssl/
cd /etc/nginx/ssl/
sudo openssl req -newkey rsa:2048 -x509 -nodes -days 3560 -out gitlab.crt -keyout gitlab.key
sudo chmod o-r gitlab.key
vim /etc/nginx/sites-enabled/gitlab-sslserver_name 10.9.210.16;
sudo service nginx restart
登陆:
root
5iveL!fe