RHEL(redhat 5.x,6.x)和CentOS上Gitlab安装全过程

RHEL和CentOS 上Gitlab安装全过程

这两天一直在折腾gitlab的安装,由于官方建议ubuntu系统上安装,所以在RHEL颇经周折。从一开始在RHEL 5.8上安装,后来又换了服务器,又在RHEL 6.5上安装。不过经过倒腾,大概明白了Gitlab在RHEL和CentOS上的安装思路,虽然实际安装使用的是RHEL6.5版本,但相信本文档针对其他版本的RHEL和CentOS安装Gitlab也是很具有参考意义的。

本文主要参考:

(1)  官方文档:https://gitlab.com/gitlab-org/gitlab-ce/tree/master/doc/install,基于Ubuntu

installation.md安装步骤

requirements.md系统环境要求

(2)  https://github.com/lubia/gitlab-recipes/tree/master/install/centos

本文结合以上两个参考资料,尤其是(2),进行了翻译整理,并把自己再实际安装过程中遇到的问题记录了下来。

 

一、预安装

  • ruby 1.9.3+
  • git 1.7.10+
  • redis 2.0+
  • MySQL or PostgreSQL
  • python 2.5以上

首先执行:

su -
yum -y update
yum -y groupinstall 'Development Tools'
yum -y install vim-enhanced readline readline-devel ncurses-develgdbm-devel glibc-devel tcl-devel openssl-devel curl-devel expat-devel db4-develbyacc sqlite-devel gcc-c++ libyaml libyaml-devel libffi libffi-devel libxml2libxml2-devel libxslt libxslt-devel libicu libicu-develsystem-config-firewall-tui python-devel redis sudo wget crontabs logwatchlogrotate perl-Time-HiRes

我理解的整个安装过程就是确保上面的软件能全部安装,并确保ruby、git、redis、python的版本。

 

执行完了么?

  • Python太低了?

系统的python可不能卸载,依赖它的包太多了,千万不能用yum –y remove来卸载,系统会崩的。一个系统可以安装多个版本的python,可以参考文章

http://blog.haohtml.com/archives/13959来安装新版本的python。

  • Git版本太低了?

这个可以yum remove git来卸载系统的git。登陆https://github.com/git/git/releases ,选择新一点稳定的git(1.8.x以上)版本,源码安装即可。

./configure不需要指定安装路径,默认安装就行。

  • yum提示找不到package?

好吧,莫慌,是redhat/centos 6.x系列么?

如果是。参考“二、系统添加EPEL、PUIAS、Rpmforge源”,给yum添加这三个源以后,再执行一开始的yum install一大串试试。、

如果还是提醒找不到某些package?参考下面的地址,看看能不能找到安装包。

 

这里有一个网址,http://rpmfind.net/linux/rpm2html/search.php?query=&submit=Search+...&system=&arch=,可以搜到很多系统的rpm安装包,下载到一个目录,执行rpm –ivh *.rpm --force –nodeps

但是有一点,要求搜索的软件包一定要适合系统的类型、版本,要不然会造成系统不稳定。

 

如果经过上述一些步骤,yum install一大串试试,还是提示一些包找不到,那就得自己动手去其他地方试试了。但是RHEL、CentOS 6.5系列绝对没有问题。

  • 至此,准备工作做完了,可继续3。如果做不完,要不考虑换换系统?

 

二、系统添加EPEL、PUIAS源(RHEL、CentOS 6.x)

2.1 添加EPEL源

sudo wget-O /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 https://www.fedoraproject.org/static/0608B895.txt
sudo rpm--import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6

验证一下key是否成功安装:

sudo rpm-qa gpg*
gpg-pubkey-0608b895-4bd22942

现在安装epel-release-6-8.noarch包,用来给系统启用EPEL源:

sudo rpm-Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm


Note: Don'tmind the x86_64, if you install on a i686 system you can use the samecommands.

 

2.2 添加PUIASComputational源

(1)Create/etc/yum.repos.d/PUIAS_6_computational.repo and add the following lines:


[PUIAS_6_computational]
name=PUIAScomputational Base $releasever - $basearch
mirrorlist=http://puias.math.ias.edu/data/puias/computational/$releasever/$basearch/mirrorlist
#baseurl=http://puias.math.ias.edu/data/puias/computational/$releasever/$basearch
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-puias


(2)Next download and install the gpg key.

sudo wget-O /etc/pki/rpm-gpg/RPM-GPG-KEY-puiashttp://springdale.math.ias.edu/data/puias/6/x86_64/os/RPM-GPG-KEY-puias
sudo rpm--import /etc/pki/rpm-gpg/RPM-GPG-KEY-puias

3)Verify that the key got installedsuccessfully:

sudo rpm-qa gpg*
gpg-pubkey-41a40948-4ce19266

(4)Verify that the EPEL and PUIASComputational repositories are enabled as shown below:

sudo yumrepolist
repoid                 repo name                                               status
PUIAS_6_computational   PUIAS computational Base 6 - x86_64                      2,018
base                    CentOS-6 - Base                                          4,802
epel                    Extra Packages forEnterprise Linux 6 - x86_64          7,879
extras                  CentOS-6 - Extras                                           12
updates                 CentOS-6 - Updates                                         814
repolist:15,525

(5)If you can't see them listed, use thefolowing command (from yum-utils package) to enable them:

sudoyum-config-manager --enable epel --enable PUIAS_6_computational

 

三、Ruby、mysql、redis等软件安装

    Gitlab、redis、nginx等将来都配置成开机启动,且会是用sendmail发送邮件。

3.1 配置redis开机启动

Make sure redis is started on boot:

sudochkconfig redis on
sudoservice redis start

3.2 配置sendmail

如果你是用smtp方式发送邮件,可直接跳过。

参考https://github.com/lubia/gitlab-recipes/tree/master/install/centos#configure-sendmail

3.3 安装ruby

下载并编译:

su -
mkdir/tmp/ruby && cd /tmp/ruby
curl--progress ftp://ftp.ruby-lang.org/pub/ruby/2.1/ruby-2.1.0.tar.gz | tar xz
cdruby-2.1.0
./configuremake&& make install

验证:

ruby -v
# ruby2.1.0p0 (2013-12-25 revision 44422) [x86_64-linux]

安装the Bundler Gem:

 sudo gem install bundler --no-ri --no-rdoc
sudo geminstall charlock_holmes -v '0.6.9.4'

改为应用淘宝的源:

sudo gem sources --remove https://rubygems.org/
sudo gem sources -a http://ruby.taobao.org/
sudo gem install bundler

添加以下软连接,否则可能提示找不到:

ln -s /usr/local/bin/ruby /usr/bin/ruby
ln -s /usr/local/bin/gem /usr/bin/gem
ln -s /usr/local/bin/bundle /usr/bin/bundle


3.4 安装mysql


http://mirrors.sohu.com/mysql/MySQL-5.0/选好mysql版本,下载

  • MySQL-client-5.5.36-1.el6.x86_64.rpm
  • MySQL-devel-5.5.36-1.el6.x86_64.rpm
  • MySQL-server-5.5.36-1.el6.x86_64.rpm
  • MySQL-shared-5.5.36-1.el6.x86_64.rpm
  • MySQL-shared-compat-5.5.36-1.el6.x86_64.rpm

不同的机器选用不同的下载包,本人是redhat 6.5,64位,所以选择如上。

下载完毕,

rpm –ivh *.rpm --force –nodeps。

启动起来并设置成开机启动。

 

四、开始正式安装

4.1 账户配置


4.1.1创建Git用户

su -
adduser--system --shell /bin/bash --comment 'GitLab' --create-home --home-dir/home/git/ git

设置为git用户不能登录.


4.1.2转发所有邮件:(如用smtp方式,可跳过)


Now we want all logging of the system to be forwarded toa central email address:

su -
echoadminlogs@example.com > /root/.forward
chown root/root/.forward
chmod 600/root/.forward
restorecon/root/.forward
 
echoadminlogs@example.com > /home/git/.forward
chown git/home/git/.forward
chmod 600/home/git/.forward
restorecon/home/git/.forward



4.2 安装GitLab shell


GitLab Shell is a ssh access and repository managementsoftware developed specially for GitLab.

# Firstlogin as root
su -
 
# Login asgit
su - git
 
# Clonegitlab shell
git clonehttps://github.com/gitlabhq/gitlab-shell.git
cdgitlab-shell
 
# Switchto right version
gitcheckout v1.8.0
cpconfig.yml.example config.yml
 
# Editconfig and replace gitlab_url with something like 'http://domain.com/'
#
# Note,'gitlab_url' is used by gitlab-shell to access GitLab API. Since 
#     1. the whole communication is locally
#     2. next steps will explain how to exposeGitLab over HTTPS with custom cert
# it's agood solution is to set gitlab_url as "http://localhost:8080/"
 
# Do setup
./bin/install



4.3 选择数据库


4.3.1 MySQL(建议)

Create a new user and database for GitLab:

# Login toMySQL
mysql -uroot -p
# Type thedatabase root password
# Create auser for GitLab. (change supersecret to a real password)
CREATEUSER 'gitlab'@'localhost' IDENTIFIED BY 'supersecret';
 
# Createthe GitLab production database
CREATEDATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8`COLLATE `utf8_unicode_ci`;
 
# Grantthe GitLab user necessary permissopns on the table.
GRANTSELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON`gitlabhq_production`.* TO 'gitlab'@'localhost';
 
# Quit thedatabase session
\q
Try connecting to the new database with the new user:
mysql -ugitlab -p -D gitlabhq_production
# Type thepassword you replaced supersecret with earlier
# Quit thedatabase session
\q


4.3.2 PostgreSQL

    参考https://github.com/lubia/gitlab-recipes/tree/master/install/centos#52-postgresql



4.4 安装GitLab


参考https://github.com/lubia/gitlab-recipes/tree/master/install/centos#6-gitlab

确认是否安装成功完成:

su - git
cd gitlab/
bundleexec rake gitlab:check RAILS_ENV=production


Do not care about it if you are sure that you have downloaded the up-to-date filefrom https://raw.github.com/gitlabhq/gitlab-recipes/master/init/sysvinit/centos/gitlab-unicorn andsaved it to /etc/init.d/gitlab.
If all other items are green, then congratulations on successfully installingGitLab! However there are still a few steps left.


4.4.1 Unicorn.rb, gitlab.yml, config.yml配置文件

    gitlab的配置依赖于三个文件

/home/git/gitlab/config/unicorn.rb:配置ruby提供的服务端口,ip

   

/home/git/gitlab/config/gitlab.yml:配置gitlab服务的端口,ip

   

/home/git/gitlab-shell/config.yml:配置gitlab-shell要调用的API接口

       

    修改host转发,Vi/etc/hosts

   

4.5 配置SMTP发送邮件


    可选。如果选用sendmail方式,可跳过此步。

   

修改gitb.yml, vi gitlab/config/gitlab.yml


    确保上面三处填写邮件的地方邮箱一致,Service gitlab restart即可。

 

4.6 安装配置nginx


su -
yum -yinstall nginx
chkconfignginx on
mkdir/etc/nginx/sites-{available,enabled}
wget -O/etc/nginx/sites-available/gitlab https://raw.github.com/gitlabhq/gitlab-recipes/master/web-server/nginx/gitlab-ssl
ln -sf/etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab

Edit /etc/nginx/nginx.conf and replace include /etc/nginx/conf.d/*.conf; with include /etc/nginx/sites-enabled/*;
Edit /etc/nginx/sites-available/gitlab and replace git.example.com with your FQDN.
Add nginx user to git group.

usermod -a-G git nginx
chmod g+rx/home/git/


Note: Don't forget to add a SSL certificate or generate aSelf Signed Certificate

cd/etc/nginx
opensslreq -new -x509 -nodes -days 3560 -out gitlab.crt -keyout gitlab.key

vi/etc/nginx/site-available/gitlab


让nginx监听80端口,root目录是gitlab的网站,这样可以通过机器ip:80来访问。

service nginx restart


五、安装完毕


假设你的电脑的IP是192.168.1.2,如果你的my.ubuntu.com域名指向192.168.1.2的话可以直接用

Http://192.168.1.2后台http://my.ubuntu.com,用以下账号登陆。

admin@local.host

5iveL!fe

参与评论 您还未登录,请先 登录 后发表或查看评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:大白 设计师:CSDN官方博客 返回首页

打赏作者

倾木忘忧草

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值