设为首页 收藏本站
查看: 1378|回复: 0

[经验分享] [转]安装GitLab的艰辛过程

[复制链接]
发表于 2018-1-10 17:39:23 | 显示全部楼层 |阅读模式
  原文地址:http://www.pwhack.me/archives/installation_of_gitlab.html
  GitLab简单来说就是开源的GitHub,是用ruby写的,基于rails框架的web应用。由于最近一个想法比较需要一个自己的版本管理系统,因此开始了我的艰辛之旅。安装过程遇到了很多问题,期间还在segmentfault和gitlhub的gitlab专页提了问题,但没人回复啊哈哈。最后自己解决,期间felix给了我很大的帮助。
  GitLab的安装过程非常复杂,不过官方安装文档还算详细。先说下我成功的详细安装过程吧,大部分与官网的步骤相同,但完全相同的话我是没有成功的。稍微有一点出入:

安装环境:纯净ubuntu server 11.04
  


1.先安装必要的包和依赖
  

1  
2
  
3
  
4
  

  

  

sudo apt-get update;  
sudo apt-get upgrade;
  
sudo apt-get install -y wget curl gcc checkinstall libxml2-dev libxslt-dev libcurl4-openssl-dev libreadline6-dev libc6-dev libssl-dev libmysql++-dev make build-essential zlib1g-dev libicu-dev redis-server openssh-server git-core python-dev python-pip libyaml-dev postfix libpq-dev;
  
sudo pip install pygments;
  


2.安装ruby
  

1  
2
  
3
  
4
  
5
  
6
  

  

  

wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p194.tar.gz;  
tar xfvz ruby-1.9.3-p194.tar.gz;
  
cd ruby-1.9.3-p194;
  
./configure;
  
make;
  
sudo make install;
  


3.创建用户

创建git用户
  

1  
2
  
3
  
4
  
5
  
6
  
7
  
8
  

  

  

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


创建gitlab用户
  

1  

  

  

sudo adduser --disabled-login --gecos 'gitlab system' gitlab  


将用户加入用户组
  

1  
2
  

  

  

sudo usermod -a -G git gitlab  
sudo usermod -a -G gitlab git
  


生成公玥
  

1  

  

  

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


4.安装Gitolite

git clone 经过GitLab fork的gitolite源码
  

1  

  

  

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


安装
  

1  
2
  
3
  
4
  
5
  
6
  
7
  
8
  
9
  

  

  

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";
  


赋予权限
  

1  
2
  
3
  
4
  
5
  
6
  

  

  

sudo chmod -R g+rwX /home/git/repositories/;  
sudo chown -R git:git /home/git/repositories/;
  

  
sudo -u gitlab -H git clone git@localhost:gitolite-admin.git /tmp/gitolite-admin;
  

  
sudo rm -rf /tmp/gitolite-admin;
  


5.安装并设置mysql
  

1  
2
  
3
  
4
  
5
  
6
  
7
  
8
  
9
  
10
  
11
  
12
  
13
  

  

  

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'>  

  
# Grant proper permissions to the MySQL User

  
mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX,>  


6.安装GitLab
  

1  

  

  

cd /home/gitlab  


获取源码
  

1  
2
  
3
  
4
  
5
  
6
  

  

  

# 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
  


复制配置文件
  

1  
2
  
3
  
4
  
5
  
6
  
7
  
8
  
9
  
10
  
11
  
12
  
13
  
14
  
15
  

  

  

d gitlab  

  
# Rename config files
  
#
  
sudo -u gitlab cp config/gitlab.yml.example config/gitlab.yml
  

  
# Copy mysql db config
  
#
  
# 这里之后要vim config/database.yml将里面前两个root的密码填上。
  
#
  
sudo -u gitlab cp config/database.yml.mysql config/database.yml
  

  
# Copy unicorn config
  
#
  
sudo -u gitlab cp config/unicorn.rb.example config/unicorn.rb
  


安装gems
  

1  
2
  
3
  
4
  
5
  

  

  

cd /home/gitlab/gitlab  

  
sudo gem install charlock_holmes --version '0.6.9'
  
sudo gem install bundler
  
sudo -u gitlab -H bundle install --without development test sqlite postgres  --deployment
  


配置git客户端
  

1  
2
  

  

  

sudo -u gitlab -H git config --global user.email "gitlab@localhost"  
sudo -u gitlab -H git config --global user.name "Gitlab"
  


安装GitLab应用
  

1  
2
  

  

  

bundle install --without development test --deployment  
sudo -u gitlab bundle exec rake gitlab:app:setup RAILS_ENV=production
  


安装GitLab Hooks
  

1  
2
  

  

  

sudo cp lib/hooks/post-receive /home/git/.gitolite/hooks/common/post-receive  
sudo chown git:git /home/git/.gitolite/hooks/common/post-receive
  


检查应用是否正确安装
  

1  

  

  

sudo -u gitlab bundle exec rake gitlab:app:status RAILS_ENV=production  

  如果返回的都是绿色的yes或exists,那就说明安装基本正确。

初始化脚本

在/etc/init.d/中创建初始化脚本
  

1  
2
  

  

  

sudo wget https://raw.github.com/gitlabhq/gitlab-recipes/master/init.d/gitlab -P /etc/init.d/  
sudo chmod +x /etc/init.d/gitlab
  


设置gitlab的自动启动
  

1  

  

  

sudo update-rc.d gitlab defaults 21  


7.安装并配置Nginx

运行gitlab后台处理服务
  

1  
2
  

  

  

cp config/unicorn.rb.example config/unicorn.rb  
bundle exec unicorn_rails -c config/unicorn.rb -E production -D
  


安装nginx,然后将gitlab的nginx代理配置文件拷贝到nginx代理目录下
  

1  
2
  
3
  
4
  
5
  
6
  
7
  
8
  
9
  
10
  
11
  
12
  
13
  
14
  

  

  

# Install first  
sudo apt-get install nginx
  

  
# Add GitLab to nginx sites & change with your host specific settings
  
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
  

  
# Change **YOUR_SERVER_IP** and **YOUR_SERVER_FQDN**
  
# to the IP address and fully-qualified domain name
  
# of the host serving GitLab.
  
sudo vim /etc/nginx/sites-enabled/gitlab
  

  
# Restart nginx:
  
sudo /etc/init.d/nginx restart
  

  默认账号密码:
  admin@local.host
  5iveL!fe

我遇到的问题

sudo执行不成功
  这个问题是因为我这个vps的特性导致的。我登上ssh后,本机地址显示的不是localhost,而是我的账号名,xxxxx。这也导致了每次执行sudo的时候,会提示无法解析主机名xxxxx。
  解决办法:修改/etc/hosts,加上127.0.0.1 xxxxx
  

1  

  

  

vim /etc/hosts  


Nginx 502 Bad Gateway
  按照官网的步骤一步一步装完之后,访问出现502。先查看日志:
  

1  
2
  
3
  

  

  

cat /var/log/nginx/gitlat_error.log  

  
2012/12/21 10:42:17 [crit] 32573#0: 30 connect() to unix:/home/gitlab/gitlab/tmp/sockets/gitlab.socket failed (2: No such file or directory) while connecting to upstream, client: **********, server: **********, request: "GET / HTTP/1.1", upstream: "http://unix:/home/gitlab/gitlab/tmp/sockets/gitlab.socket:/", host: "*******"
  

  可以看到502的原因是因为gitlab.socket不存在,这说明gitlab没有正常运行。而我是执行了service gitlab start的,这很奇怪。
  我猜测可能是脚本出了点问题,先stop掉。先提示找不到pid,然后再提示已经结束了。
  stop之后,我再start一次,然后执行一次service gitlab status,这次成功返回了gitlab的运行状态和它的pid。
  或者直接执行init.d/gitlab中的原始start脚本。
  

  现在再通过浏览器访问一次,发现url被跳到了/user/sign_in。
  但还是502。

第二次Nginx 502 Bad GateWay
  这一次502,查看log发现是正常的。说明gitlab正常运行着,但脚本有问题。
  几经搜索,执行了如下语句,问题得到解决(已在以上步骤中列出)。
  

1  
2
  

  

  

cp config/unicorn.rb.example config/unicorn.rb  
bundle exec unicorn_rails -c config/unicorn.rb -E production -D
  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-433631-1-1.html 上篇帖子: 一花一世界一叶一菩提 下篇帖子: 无止境的学习
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表