搭建 Linux 下 GitLab 服务器(2)

2. 安装 Ruby wget tar xfvz ruby-1.9.3-p194.tar.gz cd ruby-1.9.3-p194 ./configure make sudo make install 3. 安装 Gitolite

为 Git 创建用户:

sudo adduser --system --shell /bin/sh --gecos 'git version control' --group --disabled-password --home /home/git git

为 GitLab 创建用户:

# Ubuntu/debian sudo adduser --disabled-login --gecos 'gitlab system' gitlab

将 gitlab 用户添加到 git 用户组:

sudo usermod -a -G git gitlab

将 git 用户添加到 gitlab 用户组:

sudo usermod -a -G gitlab git

生成密钥:

sudo -H -u gitlab ssh-keygen -q -N '' -t rsa -f /home/gitlab/.ssh/id_rsa

克隆 GitLab 的 Gitolite 分支源代码:

sudo -H -u git git clone -b gl-v304 https://github.com/gitlabhq/gitolite.git /home/git/gitolite

安装:

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"

权限:

sudo chmod -R g+rwX /home/git/repositories/ sudo chown -R git:git /home/git/repositories/ 检查:退出并重新登录以使 git 用户组生效 # 克隆 admin 资源库以将 localhost 添加到 known_hosts # 并且确认 gitlab 用户有权访问 gitolite sudo -u gitlab -H git clone git@localhost:gitolite-admin.git /tmp/gitolite-admin # 如果执行成功,你可以将其删除 sudo rm -rf /tmp/gitolite-admin

重要! 如果你不能克隆 gitolite-admin 资源库,请不要继续本次安装,请根据 Trouble Shooting Guide 并且确认你已经小心的完成上文的全部步骤。

笔者注:这一步测试能否克隆成功。本人没有注意这个提示,完成后续安装后发现怎么都不能通过git@localhost:gitolite-admin.git的方式克隆工程,原因就是ssh认证失败,所以请务必确认这一点。顺便说下本人ssh认证失败的原因: /etc/ssh/sshd_config配置文件里面PubkeyAuthentication的值为no,意味着不允许公钥认证,改为yes就可以了。如果还是不能克隆,重复下第3步,并且注意每个命令是否执行成功。或者删除git和gitlab用户,重新执行第3步。

4. 克隆 GitLab 源代码并安装先决条件 sudo gem install charlock_holmes --version '0.6.8' sudo pip install pygments sudo gem install bundler cd /home/gitlab # 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 cd gitlab # Rename config files sudo -u gitlab cp config/gitlab.yml.example config/gitlab.yml 选择你希望使用的数据库

笔者注:建议选择SQLite

# 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 确认输入了正确的用户名/密码 安装数据库 gems # 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 初始化数据库 sudo -u gitlab bundle exec rake gitlab:app:setup RAILS_ENV=production 设置 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 确认应用程序状态: 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,恭喜!你可以继续进行下一步。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/fb6e6c0499981058e800d92609c80d57.html