[很遗憾,这个教程没有真正实现安装成功]
1.安装依赖包:
1.1设置apt-get源
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak sudo vim /etc/apt/sources.list ==================================================== deb http://mirrors.ustc.edu.cn/ubuntu/ precise-updates main restricted deb-src http://mirrors.ustc.edu.cn/ubuntu/ precise-updates main restricted deb http://mirrors.ustc.edu.cn/ubuntu/ precise universe deb-src http://mirrors.ustc.edu.cn/ubuntu/ precise universe deb http://mirrors.ustc.edu.cn/ubuntu/ precise-updates universe deb-src http://mirrors.ustc.edu.cn/ubuntu/ precise-updates universe deb http://mirrors.ustc.edu.cn/ubuntu/ precise multiverse deb-src http://mirrors.ustc.edu.cn/ubuntu/ precise multiverse deb http://mirrors.ustc.edu.cn/ubuntu/ precise-updates multiverse deb-src http://mirrors.ustc.edu.cn/ubuntu/ precise-updates multiverse deb http://mirrors.ustc.edu.cn/ubuntu/ precise-backports main restricted universe multiverse deb-src http://mirrors.ustc.edu.cn/ubuntu/ precise-backports main restricted universe multiverse ======================================================
1.2更新源并升级已安装的软件到最新版:
sudo apt-get update && apt-get upgrade
1.3安装依赖包
sudo apt-get install -y wget curl gcc checkinstall libxml2-dev libxslt-dev libcurl4-openssl-dev libreadline6-dev libc6-dev libkrb5-dev libssl-dev libmysql++-dev make cmake build-essential zlib1g-dev libicu-dev redis-server openssh-server git-core python-dev python-pip libyaml-dev postfix libpq-dev
1.4.安装数据库:
SQLite sudo apt-get install -y sqlite3 libsqlite3-dev MySQL sudo apt-get install -y mysql-server mysql-client libmysqlclient-dev # Login to MySQL $ mysql -u root -p # Create the GitLab production database mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`; # Create the MySQL User change $password to a real password mysql> CREATE USER 'gitlab'@'localhost' IDENTIFIED BY 'test123'; # Grant proper permissions to the MySQL User mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'localhost'; PostgreSQL sudo apt-get install -y postgresql-9.2 postgresql-server-dev-9.2 # Connect to database server sudo -u postgres psql -d template1 # Add a user called gitlab. Change $password to a real password template1=# CREATE USER gitlab WITH PASSWORD '$password'; # Create the GitLab production database template1=# CREATE DATABASE IF NOT EXISTS gitlabhq_production; # Grant all privileges on database template1=# GRANT ALL PRIVILEGES ON DATABASE gitlabhq_production to gitlab; # Quit from PostgreSQL server template1=# \q # Try connect to new database $ su - gitlab $ psql -d gitlabhq_production -U gitlab
2.安装Ruby:
sudo wget http://ftp.ruby-lang.org/pub/ruby/2.3/ruby-2.3.0.tar.gz tar xfvz ruby-2.3.0.tar.gz cd ruby-2.3.0 sudo ./configure sudo make sudo make install
3.安装 Gitolite
3.1 为 Git 创建用户:
sudo adduser \ --system \ --shell /bin/sh \ --gecos 'git version control' \ --group \ --disabled-password \ --home /home/git \ git
3.2 为 GitLab 创建用户:
# ubuntu/debian sudo adduser --disabled-login --gecos 'gitlab system' gitlab
3.3 将 gitlab 用户添加到 git 用户组:
sudo usermod -a -G git gitlab
3.4 将 git 用户添加到 gitlab 用户组:
sudo usermod -a -G gitlab git
3.5 生成密钥:(gitlab用户生成密钥)
sudo -H -u gitlab ssh-keygen -q -N '' -t rsa -f /home/gitlab/.ssh/id_rsa
3.6 git用户导入gitlab用户的公钥,完成免密钥访问的配置
sudo cat /home/gitlab/.ssh/id_rsa.pub >> /home/git/.ssh/authorized_keys sudo chmod 644 /home/git/.ssh/authorized_keys
3.7 克隆 GitLab 的 Gitolite 分支源代码:
sudo -H -u git git clone -b gl-v304 https://github.com/gitlabhq/gitolite.git /home/git/gitolite
3.8 安装:
cd /home/git sudo -u git -H mkdir bin sudo -u git sh -c 'echo -e "PATH=\$PATH:/home/git/bin\nexport PATH" >> /home/git/.profile' sudo -u git sh -c 'gitolite/install -ln /home/git/bin' sudo cp /home/gitlab/.ssh/id_rsa.pub /home/git/gitlab.pub sudo chmod 0444 /home/git/gitlab.pub sudo -u git -H sh -c "PATH=/home/git/bin:$PATH; gitolite setup -pk /home/git/gitlab.pub"
3.9 权限:
sudo chmod -R g+rwX /home/git/repositories/ sudo chown -R git:git /home/git/repositories/
3.10 检查:退出并重新登录以使 git 用户组生效
# 克隆 admin 资源库以将 localhost 添加到 known_hosts # 并且确认 gitlab 用户有权访问 gitolite sudo -u gitlab -H git clone git@localhost:repositories/gitolite-admin.git /tmp/gitolite-admin # 如果执行成功,你可以将其删除 sudo rm -rf /tmp/gitolite-admin
备注:重要!如果你不能克隆gitolite-admin资源库,请不要继续本次安装,请根据 Trouble Shooting Guide 并且确认你已经小心的完成上文的全部步骤。
4 克隆 GitLab 源代码并安装先决条件
4.1 更改gem源
# sudo gem update --system 更新gem版本 sudo gem -v 查看版本 $ sudo gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/ $ sudo gem sources -l https://gems.ruby-china.org # 确保只有 gems.ruby-china.org #sudo find / -name Gemfile #将搜索出来的三个Gemfile文件修改 source 'https://rubygems.org' -->source 'https://gems.ruby-china.org'
4.2 安装先决条件
sudo gem install charlock_holmes --version '0.6.8' sudo pip install pygments sudo gem install bundler cd /home/gitlab
4.3 下载代码
# Get gitlab code. Use this for stable setup #sudo -H -u gitlab git clone -b stable https://github.com/gitlabhq/gitlabhq.git gitlab # Skip this for stable setup. # Master branch (recent changes, less stable) #sudo -H -u gitlab git clone -b master https://github.com/gitlabhq/gitlabhq.git gitlab #我这里使用gitlab中文版的代码 sudo -H -u gitlab git clone -b master https://gitlab.com/larryli/gitlab.git gitlab
4.4 更改配置文件
cd gitlab # Rename config files sudo -u gitlab cp config/gitlab.yml.example config/gitlab.yml
4.5 安装数据库 gems
sudo vim /home/gitlab/gitlab/Gemfile --> source "https://gems.ruby-china.org" # mysql sudo -u gitlab -H bundle install --without development test sqlite postgres --deployment # 或者 postgres sudo -u gitlab -H bundle install --without development test sqlite mysql --deployment # 或者 sqlite sudo -u gitlab -H bundle install --without development test mysql postgres --deployment
4.6 选择你希望使用的数据库
# SQLite sudo -u gitlab cp config/database.yml.sqlite config/database.yml # Mysql sudo -u gitlab cp config/database.yml.mysql config/database.yml # PostgreSQL sudo -u gitlab cp config/database.yml.postgres config/database.yml # 修改 config/database.yml 确认输入了正确的用户名/密码
4.7 初始化数据库(这里要保证上面的数据库配置文件用户名和密码对数据库可写)
sudo -u gitlab bundle exec rake gitlab:setup RAILS_ENV=production (这里会遇到各种坑,错误见后面。大部分缺少的东西都在过程中安装了)
4.8 设置 GitLab hooks
sudo cp ./lib/hooks/post-receive /home/git/.gitolite/hooks/common/post-receive sudo chown git:git /home/git/.gitolite/hooks/common/post-receive
4.9 确认应用程序状态:
sudo -u gitlab bundle exec rake gitlab:app:status RAILS_ENV=production # OUTPUT EXAMPLE Starting diagnostic config/database.yml............exists config/gitlab.yml............exists /home/git/repositories/............exists /home/git/repositories/ is writable?............YES remote: Counting objects: 603, done. remote: Compressing objects: 100% (466/466), done. remote: Total 603 (delta 174), reused 0 (delta 0) Receiving objects: 100% (603/603), 53.29 KiB, done. Resolving deltas: 100% (174/174), done. Can clone gitolite-admin?............YES UMASK for .gitolite.rc is 0007? ............YES /home/git/share/gitolite/hooks/common/post-receive exists? ............YES 提醒:如果所有结果都是 YES,恭喜!你可以继续进行下一步了。
5. 设置 web server
5.1 应用可以用下一个命令行动:
# 用于测试目的 sudo -u gitlab bundle exec rails s -e production # 用于守护进程 sudo -u gitlab bundle exec rails s -e production -d
5.2 默认登录用户名及密码:
admin@local.host 5iveL!fe
6. 运行 Resque 进程(用于处理工作队列)
# 手动启动 sudo -u gitlab bundle exec rake environment resque:work QUEUE=* RAILS_ENV=production BACKGROUND=yes # GitLab 启动脚本 sudo -u gitlab ./resque.sh # 如果你使用 root 运行此脚本,会导致 /home/gitlab/gitlab/tmp/pids/resque_worker.pid 文件的拥有者为 root # 将导致 resque 在下一次系统初始化中无法启动
6.1 自定义 Resque 使用的 Redis 连接
如果你希望 Resque 连接到一个非标准端口号或另一台服务器上的 Redis,你可以在config/resque.yml 文件修改连接信息: production: redis.example.com:6379
7. 我们已经拥有了一个工作正常的GitLab了,但请继续下去,有一些事情是必须完成的。
7.1 Unicorn
cd /home/gitlab/gitlab sudo -u gitlab cp config/unicorn.rb.example config/unicorn.rb sudo -u gitlab bundle exec unicorn_rails -c config/unicorn.rb -E production -D
7.2 Nginx
# 初次安装 Nginx sudo apt-get install nginx # 添加GitLab 到 nginx sites sudo wget https://raw.github.com/gitlabhq/gitlab-recipes/master/nginx/gitlab -P /etc/nginx/sites-available/ sudo ln -s /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab # 修改 **YOUR_SERVER_IP** 与 **YOUR_SERVER_FQDN** # 为起初的 IP 地址与准备让 GitLab 服务的域名 sudo vim /etc/nginx/sites-enabled/gitlab # 重启 nginx: sudo /etc/init.d/nginx restart
7.3 Init 脚本
在 /etc/init.d/gitlab 创建 init 脚本: sudo update-rc.d gitlab defaults 21 现在你可以用这种方式启动/重启/停止 GitLab 服务: sudo /etc/init.d/gitlab restart
错误集锦:
1.运行sudo -u git -H bundle install --deployment --without development test postgres aws 的时候报错 参考链接:http://stackoverflow.com/questions/27472234/an-error-occurred-while-installing-rugged
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/usr/local/bin/ruby extconf.rb checking for cmake... no ERROR: CMake is required to build Rugged. *** extconf.rb failed *** Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check the mkmf.log file for more details. You may need configuration options. Provided configuration options: --with-opt-dir --without-opt-dir --with-opt-include --without-opt-include=${opt-dir}/include --with-opt-lib --without-opt-lib=${opt-dir}/lib --with-make-prog --without-make-prog --srcdir=. --curdir --ruby=/usr/local/bin/ruby Gem files will remain installed in /home/git/gitlab/vendor/bundle/ruby/2.0.0/gems/rugged-0.21.2 for inspection. Results logged to /home/git/gitlab/vendor/bundle/ruby/2.0.0/gems/rugged-0.21.2/ext/rugged/gem_make.out An error occurred while installing rugged (0.21.2), and Bundler cannot continue. Make sure that `gem install rugged -v '0.21.2'` succeeds before bundling.
解决办法:
sudo apt-get install cmake
2. Cannot find krb5 library (RuntimeError)
Gem::Ext::BuildError: ERROR: Failed to build gem native extension. current directory: /home/gitlab/gitlab/vendor/bundle/ruby/2.3.0/gems/timfel-krb5-auth-0.8.3/ext /usr/local/bin/ruby -r ./siteconf20160603-78699-1od19wx.rb extconf.rb checking for main() in -lc... yes checking for krb5_init_context() in -lkrb5... no *** extconf.rb failed *** Could not create Makefile due to some reason, probably lack of necessary libraries and/or headers. Check the mkmf.log file for more details. You may need configuration options. Provided configuration options: --with-opt-dir --without-opt-dir --with-opt-include --without-opt-include=${opt-dir}/include --with-opt-lib --without-opt-lib=${opt-dir}/lib --with-make-prog --without-make-prog --srcdir=. --curdir --ruby=/usr/local/bin/$(RUBY_BASE_NAME) --with-krb5_auth-dir --without-krb5_auth-dir --with-krb5_auth-include --without-krb5_auth-include=${krb5_auth-dir}/include --with-krb5_auth-lib --without-krb5_auth-lib=${krb5_auth-dir}/lib --with-clib --without-clib --with-krb5lib --without-krb5lib extconf.rb:7:in `': Cannot find krb5 library (RuntimeError) To see why this extension failed to compile, please check the mkmf.log which can be found here: /home/gitlab/gitlab/vendor/bundle/ruby/2.3.0/extensions/x86_64-linux/2.3.0-static/timfel-krb5-auth-0.8.3/mkmf.log extconf failed, exit code 1 Gem files will remain installed in /home/gitlab/gitlab/vendor/bundle/ruby/2.3.0/gems/timfel-krb5-auth-0.8.3 for inspection. Results logged to /home/gitlab/gitlab/vendor/bundle/ruby/2.3.0/extensions/x86_64-linux/2.3.0-static/timfel-krb5-auth-0.8.3/gem_make.out An error occurred while installing timfel-krb5-auth (0.8.3), and Bundler cannot continue. Make sure that `gem install timfel-krb5-auth -v '0.8.3'` succeeds before bundling.
解决办法:
参考:https://github.com/gitlabhq/gitlabhq/issues/8478 sudo apt-get install libkrb5-dev
3. Gem::LoadError: You have already activated rake 10.4.2, but your Gemfile requires rake 10.5.0. Prepe
解决办法:
sudo gem uninstall rake
sudo gem install rake -v 10