阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

如何在Ubuntu Server 14.04下安装Gitlab中文版

110次阅读
没有评论

共计 6764 个字符,预计需要花费 17 分钟才能阅读完成。

Gitlab 是基于 Ruby on Rails 的,安装和配置非常麻烦,不过有傻瓜安装包,https://about.gitlab.com/downloads/,或者,https://bitnami.com/stack/gitlab/installer。但是这两个包都是英文界面的,gitlab 把界面提示写在每一个 rb 文件里了,所以,要用中文版的不能像 redmine 那样设定一下就行了。

幸好,还是有无私的大侠把 gitlab 给汉化了:https://larryli.cn/gitlab,代码地址:https://gitlab.com/larryli/gitlab。

所以本文要做的事情是,不安装傻瓜包,从源码安装 gitlab。

gitlab 官方有一个说明文档:http://doc.gitlab.com/ce/install/installation.html,本文基本按照这个文档来的。所不同的是,本文用的是 apache,不是 nginx。

安装步骤有:

1. 依赖包
2. ruby
3. 用户创建
4. 数据库初始化
5. redis
6. gitlab 源码
7. apache

本文可能会用到 VPN 连接,在命令行下创建 VPN 连接的方法如下:

sudo apt-get install pptp-linux
sudo pptpsetup –create VPN 名称 –server 服务器地址 –username 用户名 –password 密码 [–encrypt] –start

以上命令会创建一个设备,如果没有其他的拨号设备,这个设备会是 ppp0,用 ifconfig 可以看到,“–encrypt”选项可选,因为有的服务器不支持,会提示 MPPE required but peer negotiation failed,创建时带上“–start”选项可以看到连接的情况。
pptpsetup 创建的 VPN 连接重启后会失效,如果想在不重启的情况下删除 VPN 连接:

sudo pptpsetup –delete VPN 名称

创建 VPN 连接后还需要使能,并且添加到路由列表:

sudo pon VPN 名称
sudo route add default dev ppp0

禁用 VPN 连接的方法是:

sudo poff VPN 名称

下面开始正文:

1. 依赖包

我装的是 Ubuntu server 14.04,安装的时候可以选是否安装 LAMP(Linux+Apache+MySQL+PHP),如果没装,可以用下面的命令装:

sudo tasksel install lamp-server

安装的时候会提示输入 MySQL 的 root 密码,下面要用。
接下来是依赖关系:

sudo apt-get install flex bison ruby 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 libkrb5-dev nodejs git-core

注意:这里面装了 ruby,应该是 1.9.1 版本的,gitlab 需要 2.0 以上的 ruby,但是安装 2.0 以上的 ruby 需要低版本的 ruby,所以我们先装上,一会儿卸掉。另外,ubuntu 14.04 的软件库里有 ruby 2.0,但是实测不能用,所以还是从源码装 ruby 吧。

2. ruby

下载,编译,安装(安装前删掉 ruby 1.9.1):

curl -L –progress http://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.5.tar.gz | tar xz
cd ruby-2.1.5
./configure –prefix=/usr –disable-install-rdoc
make
sudo apt-get autoremove ruby
sudo make install

然后安装 bundler:

sudo gem install bundler –no-ri –no-rdoc

3. 用户创建

为 gitlab 创建一个 git 用户:

sudo adduser –disabled-login –gecos ‘GitLab’ git

4. 数据库初始化

官方指南用的是 PostgreSQL,不过官方也有 MySQL 的说明:
http://doc.gitlab.com/ce/install/database_mysql.html

sudo apt-get install -y mysql-server mysql-client libmysqlclient-dev
mysql -u root -p

输入 MySQL 的 root 密码登陆,然后:

mysql> CREATE USER ‘git’@’localhost’ IDENTIFIED BY ‘$password’;

记得把上面这句的 ”$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

5. Redis

Redis 貌似是用来存 key 的数据库吧,不知道,反正按步骤安装:

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
sudo service redis-server restart
sudo usermod -aG redis git

6. gitlab 源码

gitlab 源码默认是安装在 /home/git/gitlab,如果要更改,请参照官方手册。获取中文版源码的过程如下:

cd /home/git
sudo -u git -H git clone https://gitlab.com/larryli/gitlab.git

不知道是因为 GFW 还是什么,git clone 这个版本库可慢可慢了,我用了 VPN,速度会快点。
git clone 完以后可以 checkout 你想要的版本,在本文编写的时间(2015 年 4 月 22 日),可以:

sudo -u git -H git checkout 7-7-zh

然后配置源码

cd /home/git/gitlab
sudo -u git -H cp config/gitlab.yml.example 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
sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb
sudo -u git -H git config –global user.name “GitLab”
sudo -u git -H git config –global user.email “example@example.com”
sudo -u git -H git config –global core.autocrlf input
sudo -u git -H cp config/resque.yml.example config/resque.yml

当然,你可以把 example@example.com 改成你的 email;上面的那些 yml 文件里面的配置基本都不用更改;然后,配置数据库用户名和密码:

sudo -u git cp config/database.yml.mysql config/database.yml
sudo -u git -H editor config/database.yml
sudo -u git -H chmod o-rwx config/database.yml

然后,安装 gems:

sudo -u git -H bundle install –deployment –without development test postgres aws

这一步必须使用 VPN,因为万恶的 GFW 屏蔽了 rubygems.org,所以会提示 connection reset by peer 之类的,这部时间也会比较久,如果你的机器是多核的,也可以加上和 make 相同 -jN 参数,N 等于核数。

(2015 年 5 月 2 日追加)
发现淘宝做了个 rubygrems.org 的国内镜像,http://ruby.taobao.org/,可以参照上面的内容设置,加快 gems 安装速度。

再接下来安装 gitlab shell:

sudo -u git -H bundle exec rake gitlab:shell:install[v2.6.0] REDIS_URL=unix:/var/run/redis/redis.sock RAILS_ENV=production
sudo -u git -H editor /home/git/gitlab-shell/config.yml

把 gitlab 的 url 改成 http://localhost/ 或者你的域名。
在接下来初始化数据库:

sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production

加入启动项:

sudo cp lib/support/init.d/gitlab /etc/init.d/gitlab
sudo update-rc.d gitlab defaults 21

初始化日志:

sudo cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab

检查应用状态:

sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production

编译附件:

sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production

启动 gitlab 服务:

sudo service gitlab start

7. apache

下载 apache 的配置文件:https://gitlab.com/gitlab-org/gitlab-recipes/blob/master/web-server/apache/gitlab-apache2.4.conf
将其中的“ProxyPassReverse http://gitlab.example.com/”改成“ProxyPassReverse http://localhost/”或者你的域名,将其中的“/var/log/httpd/logs/”改为“/var/log/apache2/”。
用命令来说:

wget https://gitlab.com/gitlab-org/gitlab-recipes/raw/master/web-server/apache/gitlab-apache2.4.conf
mv gitlab-apache2.4.conf 001-gitlab.conf
editor 001-gitlab.conf(进行上述修改)
sudo cp 001-gitlab.conf /etc/apache2/sites-available
cd /etc/apache2/sites-enabled
sudo rm 000-default.conf
sudo ln -s ../sites-available/001-gitlab.conf 001-gitlab.conf

另外,还需要使能代理模块以实现反向代理功能,不然会提示“ProxyPassReverse”无效之类的。

cd /etc/apache2/mods-enabled
sudo ln -s ../mods-available/proxy.conf proxy.conf
sudo ln -s ../mods-available/proxy.load proxy.load
sudo ln -s ../mods-available/proxy_connect.load proxy_connect.load
sudo ln -s ../mods-available/proxy_http.load proxy_http.load
sudo ln -s ../mods-available/rewrite.load rewrite.load

重启 apache:

sudo service apache2 restart

然后,检查下配置是否正确:

sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production

如果都是绿色的结果,那就可以访问了。登陆用户名:root,初始密码:5iveL!fe

最后配置一下邮件,修改 /home/git/gitlab/config/gitlab.yml,里面的“email_from:”为一个有效的 email 地址;修改 /home/git/gitlab/config/environments/production.rb,里面的“config.action_mailer.delivery_method=”为“:smtp”;最后:

cd /home/git/gitlab/config/initializers
sudo -u git -H cp smtp_settings.rb.sample smtp_settings.rb

然后把文件的里的内容修改正确了,再重启一下 gitlab 服务就行了:

sudo service gitlab restart

最后看看我的部署结果:

如何在 Ubuntu Server 14.04 下安装 Gitlab 中文版

如何在 Ubuntu Server 14.04 下安装 Gitlab 中文版

CentOS 源码安装 GitLab 汉化版  http://www.linuxidc.com/Linux/2015-10/124648.htm

在 Ubuntu 12.04 上安装 GitLab http://www.linuxidc.com/Linux/2012-12/75249.htm

GitLab 5.3 升级注意事项 http://www.linuxidc.com/Linux/2013-06/86473.htm

在 CentOS 上部署 GitLab (自托管的 Git 项目仓库) http://www.linuxidc.com/Linux/2013-06/85754.htm

在 RHEL6/CentOS6/ScientificLinux6 上安装 GitLab 6.0.2 http://www.linuxidc.com/Linux/2014-03/97831.htm

CentOS 6.5 安装 GitLab 教程及相关问题解决 http://www.linuxidc.com/Linux/2014-05/101526.htm

GitLab 的详细介绍 :请点这里
GitLab 的下载地址 :请点这里

更多 Ubuntu 相关信息见 Ubuntu 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=2

本文永久更新链接地址 :http://www.linuxidc.com/Linux/2015-12/126875.htm

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-21发表,共计6764字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中