安装步骤总览 - 基础操作系统(CentOS 6.5 x86_64)
- Ruby (版本: 2.0.0p353)
- 创建项目运行用户(创建git账号,方便权限管理)
- GitLab Shell(版本:2.6.3)
- 数据库(可以支持mysql和PostgreSQL,这里使用mysql,版本:5.1.17)
- GitLab(版本:7.10.1)
- Web服务器(可支持nginx和apache,这里使用tengine,版本:2.1.0)
- 防火墙(iptables)
1、安装操作系统 这个比较简单,安装完成之后记的配置下网络,使其可以在启动时自动连接。而后需要升级系统和安装一些相应的软件和依赖包,以下逐一说明。 Tips:如果不能连接国外的网络,经常出现网络错误或者couldn’t not resolve host这样的错误,建议修改dns服务器为8.8.8.8和8.8.4.4。 a、增加EPEL安装源 EPEL,即Extra Packages for Enterprise Linux,这个软件仓库里有很多非常常用的软件,而且是专门针对RHEL设计的,对RHEL标准yum源是一个很好的补充,完全免费使用,由 Fedora项目维护,所以如果你使用的是RHEL,或者CentOS,Scientific等RHEL系的linux,可以非常放心的使用EPEL的 yum源。 下载并安装GPG key $ 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检验下是否安装成功 $ sudo rpm -qa gpg*安装epel-release-6-8.noarch包 $ sudo rpm -Uvh http://dl.fedoraproject.org/pub/ ... ease-6-8.noarch.rpm提示:不要在意x86_64,在i686的机器上一样能使用。 b、安装GitLab的所需依赖包和工具
# yum -y groupinstall "Development Tools"c、配置redis 配置redis使其在开机时启动: # yum -y install redis# chkconfig redis on# service redis startd、配置邮件服务器 笔者注:这个过程笔者没有配置,请参考英文文档。 2、安装Ruby 下载并编译: # mkdir /tmp/ruby && cd /tmp/ruby# curl --progress ftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p353.tar.gz | tar xz# cd ruby-2.0.0-p353# ./configure --prefix=/usr/local/# make && make install安装完成后,重新登录终端确保$PATH生效,检测ruby的安装成功与否: # which ruby/usr/local/bin/ruby# ruby -vruby 2.0.0p353 (2013-11-22 revision 43784) [x86_64-linux]安装bundle: $ # gem install bundler --no-ri --no-rdoc如果提示sudo: gem: command not found,使用root账号登录执行该命令即可。 3、系统用户 创建用户git # adduser --system --shell /bin/bash --comment 'GitLab' --create-home --home-dir /home/git/ git因为git用户不需要登录,所以这里不需要设置git的密码。 转发所有邮件 笔者注:因为上面没有配置发送邮件,这里也省略。 4、配置GitLab shell GitLab shell是专门为GitLab开发的提供ssh访问和版本管理的软件。 先使用root登录,而后切换成git $ su - git克隆gitlab shell $ git clone https://github.com/gitlabhq/gitlab-shell.git$ cd gitlab-shell切换成2.6.3版本,并编辑配置 $ git checkout v2.6.3$ cp config.yml.example config.yml笔者注:如果gitlab是使用https访问,则需将http替换成https,配置文件中的self_signed_cert要修改成true,否则 gitlab shell在通过api和gitlab进行通信的时候就会出现错误,导致项目push出错。因为后面配置web服务器的时候是使用ssl,所以这里要按照 ssl的方式配置。 Tips: 另外如果使用的域名是测试域名,不要忘记在系统的/etc/hosts做域名映射。 安装一些需要的目录和文件 $ ./bin/install5、安装数据库 笔者这里使用的是msyql,关于PostgreSQL的安装请参考原文档。 安装mysql并设置开机启动: $ su - root# yum install -y mysql-server mysql-devel# chkconfig mysqld on# service mysqld start设置mysql root账号的密码: # /usr/bin/mysql_secure_installation创建新用户和数据库给gitlab使用 # 登录数据库$ mysql -u root -p# 输入root密码# 为gitlab创建使用用户CREATE USER 'gitlab'@'localhost' IDENTIFIED BY 'gitlab';# 创建gitlaba使用的数据库CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;# 给予gitlab用户权限GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'localhost';# 登出数据库\q6、安装GitLab 将GitLab安装在git的家目录下: $ su - gita、克隆GitLab并切换分支到7-10-stable # 克隆GitLab$ git clone https://github.com/gitlabhq/gitlabhq.git gitlab# 进入gitlab目录$ cd /home/git/gitlab# 切换到7-10-stable分支$ git checkout 7-10-stableb、配置项目 # 复制配置文件$ cp config/gitlab.yml.example config/gitlab.yml# 修改配置文件中的访问域名(your_domain_name为项目的访问域名)$ sed -i 's/localhost/your_domain_name/g' config/gitlab.yml# 设定log和tmp目录所有者和权限$ chown -R git log/$ chown -R git tmp/$ chmod -R u+rwx log/$ chmod -R u+rwx tmp/# 创建gitlab-satellites目录$ mkdir /home/git/gitlab-satellites# 创建tmp/pids/和tmp/sockets/目录,确保gitlab有相应的权限$ mkdir tmp/pids/$ mkdir tmp/sockets/$ chmod -R u+rwx tmp/pids/$ chmod -R u+rwx tmp/sockets/# 创建public/uploads目录$ mkdir public/uploads$ chmod -R u+rwx public/uploads# 复制unicorn配置$ cp config/unicorn.rb.example config/unicorn.rb# 编辑unicorn配置(修改listen和超时时间)$ vim config/unicorn.rblisten "172.16.2.2:8080"timeout 300# 配置git的用户和邮件$ git config --global user.name "GitLab"$ git config --global user.email "gitlab@51auto.com"$ git config --global core.autocrlf input这边的配置比较复杂,细心些就行了。 c、配置数据库访问文件 $ cp config/database.yml.mysql config/database.yml编辑config/database.yml,设置其中连接数据库的账号密码,笔者的配置部分如下: ## PRODUCTION#production: adapter: mysql2 encoding: utf8 reconnect: false database: gitlabhq_production pool: 10 username: gitlab password: "gitlab" # host: localhost # socket: /tmp/mysql.sock修改其中username和password就可以了,其中密码就是上面数据库步骤中创建gitlab用户的密码。 确保该文件只有git账号有权限读取。 $ chmod o-rwx config/database.ymld、安装Gems $ su -$ gem install charlock_holmes --version '0.6.9.4'$ exit安装mysql包 $ cd /home/git/gitlab/$ bundle install --deployment --without development test postgres puma awse、初始化数据和激活高级功能 $ cd /home/git/gitlab$ bundle exec rake gitlab:setup RAILS_ENV=production这步完成后,会生一个默认的管理员账号: admin@local.host5iveL!fef、安装启动脚本 $ su -$ wget -O /etc/init.d/gitlab https://raw.githubusercontent.co ... ntos/gitlab-unicorn$ chmod +x /etc/init.d/gitlab$ chkconfig --add gitlab开机时启动 $ chkconfig gitlab ong、检测应用程序状态 $ su - git$ cd gitlab/$ bundle exec rake gitlab:env:info RAILS_ENV=production$ exit可以查看到系统、Ruby、GitLab和GitLab Shell的版本和其他信息。 启动GitLab实例 $ service gitlab starth、查看应用更加详细的信息 $ su - git$ cd gitlab/$ bundle exec rake gitlab:check RAILS_ENV=production这里会提示一个Init script up-to-date的错误,如下: Init script up-to-date? ... noTry fixing it:Redownload the init scriptFor more information see:doc/install/installation.md in section "Install Init Script"Please fix the error above and rerun the checks.原文说明不用介意这个问题。 7、安装web服务器 笔者选择的是tengine,自己打好的rpm包,关于apache方面的请参考原文档 # rpm -ivh tengine-2.1.0-0.el6.x86_64.rpm# vi /opt/config/tengine/vhost/gitlab.confserver { listen 80; server_name 172.16.2.2; include proxy_opt.conf; access_log /opt/logs/tengine/gitlab_access.log; error_log /opt/logs/tengine/gitlab_error.log; location / { proxy_pass http://172.16.2.2:8080; }}启动nginx
# service rc.tengine start8、配置防火墙 配置iptables,使用户可以访问http、https和ssh的端口。 $ lokkit -s http -s https -s ssh重新启动防火墙 $ service iptables restart至此就算安装完成了。默认的账号密码: admin@local.host5iveL!fe问题记录 a、网站不能添加用户和创建项目问题? 查了下日志,发现是权限的问题: Errno::EACCES (Permission denied – /home/git/gitlab/log/application.log): 修改用户和所属用户组为git就可以了。 b、无法push? 在上面安装GitLab shell步骤时,一开始笔者是将配置中的gitlab_url设置成http://test.gitlab.com/,结果在push的时候出错了,后 来查看GitLab项目日志,才发现GitLab shell和GitLab通信的时候产生了一个301跳转。这点通过GitLab的nginx配置也能看的出来。后来将http替换成 https,self_signed_cert设置成true就OK了。 总结 安装的过程比较长,其中大部分时间花在了包的下载上。笔者以前没有接触过ruby,安装的过程中也了解了下Ruby、Gem、Bundle等软件,受益匪 浅。一般来讲,照着上面的步骤安装,如果系统,软件等版本都一致的话,应该能成功安装。如果出现问题,可以多查查日志。GitLab项目的日志在该项目的 log目录内。GitLab shell的日志在GitLab shell项目中的gitlab-shell.log
|