在CentOS 7上部署GitLab的正确姿势

0

写在前面

本文主要内容参照https://gitlab.com/gitlab-org/gitlab-recipes/tree/master/install/centos,但由于原文使用的是CentOS 6.5,而CentOS 7相对于6.5做了“大刀阔斧”的改变,于是留下了一堆坑需要自己填。故本文针对CentOS 7在原文的基础上进行了一定的修改和补充,以飨读者。

Content / 目录

1.Install the base operating system (CentOS 7) and Packages / Dependencies / 安装基础操作系统(CentOS 7)以及包/依赖
2.Ruby
3.System Users / 系统用户
4.Database / 数据库
5.GitLab
6.GitLab shell
7.Web server / Web服务器
8.Firewall / 防火墙

1. Installing the operating system and Packages / Dependencies / 安装基础操作系统以及包/依赖

Updating and adding basic software and services / 更新并添加基础软件和服务

Install the required tools for GitLab

Note: During this installation some files will need to be edited manually. If you are familiar with vim set it as default editor with the commands below. If you are not familiar with vim please skip this and keep using the default editor.
提示:在安装过程中某些文件需要被手动编辑。如果你熟悉VIM,使用下面的命令行把它设置为默认编辑器。如果你不熟悉VIM请跳过这一步保持使用默认的编辑器。

Install Redis / 安装Redis

Go to http://www.redis.io/download to download the source code for Redis, and follow the instruction on the download page.
访问http://www.redis.io/download下载Redis的源代码,并根据下载页面上的指示进行操作。

Note: If some errors occur during compilation, execute the command below.
提示:如果在编译过程中出错,执行下面的命令。

After finishing compilation, install Redis.
编译完成后,安装Redis.

Configure Redis / 配置Redis

Create /etc/init.d/redis and use the following code as an init script.
创建/etc/init.d/redis并使用下面的代码作为启动脚本。

Save and grant execution.
保存并设置执行权限。

Make Redis start when system boot.
确保Redis在系统启动时自动运行。

Add this line to the end and save.
在文件末尾添加这行并保存。

Also use the command above to start redis (use sudo if required).
同样使用上述命令启动Redis(可能需要root权限)。

Install mail server / 安装邮件服务器

Install Git / 安装Git

Make sure Git is version 1.7.10 or higher, for example 1.7.12 or 1.8.4.
确保Git的版本为1.7.10或更高,例如1.7.12或1.8.4。

If not, install it from source. Remove the system Git, install the pre-requisite files for Git compilation.
Note: Only do this when your Git version is lowere than 1.7.10.
如果不是,从源代码安装。移除系统中的Git,安装Git编译需要的前置文件。
提示:只在你的Git的版本低于1.7.10时才从源代码安装。

Download, extract, compile and install it.
下载、提取、编译并安装。

Make sure Git is in your $PATH.
确保Git在你的$PATH环境变量中。

You might have to logout and login again for the $PATH to take effect.
Note: When editing config/gitlab.yml (step 6), change the git bin_path to /usr/local/bin/git.
你可能需要登出再登入使得$PATH生效。
提示:当修改config/gitlab.yml(第五步)时,改变git的bin_path为/usr/local/bin/git。

2. Ruby

Check your Ruby version. GitLab only supports the Ruby 2.0+ release series.
检查你的Ruby版本。GitLab仅支持Ruby 2.0+系列。

Note: The following steps for installing Ruby from source are optional, only do this when your Ruby version is lower than 2.0.
Remove the old Ruby 1.8 package if present.
提示:以下关于从源代码安装Ruby的步骤是可选的,只有当你的Ruby版本低于2.0的时候才这么做。
如果旧的Ruby 1.8包出现的话,移除它。

Remove any other Ruby build if it is still present.
移除其他Ruby编译如果它们仍然存在。

Download Ruby and compile it.
下载Ruby并编译。

Install the Bundler Gem
安装Gem Bundler

Logout and login again for the $PATH to take effect. Check that ruby is properly installed with.
登出再登入使$PATH生效,检查Ruby是否正确安装

3. System Users / 系统用户

Create a git user for Gitlab:
为GitLab创建一个git用户:

Important: In order to include /usr/local/bin to git user’s $PATH, one way is to edit the sudoers file. As root run:
重要:为了包含/usr/local/bin到git用户的$PATH,一个方法是编辑超级用户文件。以管理员身份运行:

Then search for this line:
然后搜索这行:

and append /usr/local/bin like so:
像这样附加/user/local/bin:

Save and exit.
保存并退出。

4. Database / 数据库

MySQL

Because of some obvious reasons, MySQL is nolonger included in the repos in CentOS 7 and MariaDB cannot work together with MySQL. So remove MariaDB and then install MySQL.
Check all the installed mariadb packages.
因为某些众所周知的原因,MySQL已经不再包含在CenOS 7的软件源中了,并且MariaDB不能与MySQL同时运行。因此先移除MariaDB然后安装MySQL。
检查所有已安装的的mariadb包

Remove them all.
全都卸载了。

Download and install MySQL
下载并安装MySQL

Copy the configuration file and MySQL files, grant privileges
复制配置文件和MySQL文件并赋予权限

Start MySQL service
启动MySQL服务

Set password for root:
为root用户设置密码:

Login to MySQL (type the database root password):
登陆MySQL:

Create a user for GitLab (change $password in the command below to a real password you pick):
创建一个用于GitLab的用户(更改以下命令中的$password为一个你设定的真实密码):

Ensure you can use the InnoDB engine which is necessary to support long indexes. If this fails, check your MySQL config files (e.g. /etc/mysql/*.cnf, /etc/mysql/conf.d/*) for the setting “innodb = off”.
确保你可以使用InnoDB引擎用于支持长索引。如果失败了,检查你的MySQL配置文件(例如:/etc/mysql/*.cnf, /etc/mysql/conf.d/*)是否存在”innodb = off”。

Create the GitLab production database:
创建GitLab生产数据库:

Grant the GitLab user necessary permissions on the table:
授予GitLab用户必需的权限:

Quit the database session:
退出数据库会话:

Try connecting to the new database with the new user:
尝试使用新的用户连接新的数据库:

Type the password you replaced $password with earlier. Quit the database session:
输入你之前设定的密码,退出数据库会话:

5. GitLab

Clone the source / 复制源

Install GitLab into the home directory of user git:
把GitLab安装到git用户的home目录中:

Configure it / 配置

Important Note: Make sure to edit both gitlab.yml and unicorn.rb to match your setup.
重要事项:确保修改gitlab.yml和unicorn.rb符合你的设置。

Configure GitLab DB settings / 配置GitLab数据库设置

Install Gems / 安装Gems

6. GitLab Shell

Install GitLab shell / 安装GitLab Shell

GitLab Shell is an ssh access and repository management software developed specially for GitLab.
GitLab Shell是一个专门为GitLab开发的SSH访问和源管理软件。

Initialize Database and Activate Advanced Features / 初始化数据库和激活高级功能

Note:
You can set the Administrator password by supplying it in environmental variable GITLAB_ROOT_PASSWORD, eg.:
提示:你可以设置管理员密码通过在环境变量GITLAB_ROOT_PASSWORD中提供,例如:

Install Init Script / 安装初始化脚本

Download the init script (will be /etc/init.d/gitlab):
下载初始化脚本(将放在/etc/init.d/gitlab):

Make GitLab start on boot:
设置GitLab开机启动:

Set up logrotate
设置日志翻转

Check Application Status / 检查应用状态

Check if GitLab and its environment are configured correctly:
检查GitLab和它的运行环境是否已经正确配置:

Compile assets
编译静态文件

Start your GitLab instance
启动你的GitLab实例

7. Web Server / Web服务器

Installation / 安装

Add nginx yum repository, create a file named /etc/yum.repos.d/nginx.repo and paste the configurations below:
添加Nginx的yum源,创建一个文件命名为/etc/yum.repos.d/nginx.repo并粘贴以下配置信息:

Install and configure it.
安装并配置

Make sure to edit the config file to match your setup:
确保修改的配置文件符合你的设置:

Add nginx user to git group:
添加nginx用户到git用户组:

Test Configuration / 测试配置信息

Validate your gitlab or gitlab-ssl Nginx config file with the following command:
使用下列命令验证你的gitlab或者gitlab-ssl Nginx配置文件:

You should receive syntax is okay and test is successful messages. If you receive errors check your gitlab or gitlab-ssl Nginx config file for typos, etc. as indicated in the error message given.
你应该收到消息提示称语法正确以及测试成功。如果你收到错误,请根据错误消息中给出的指示检查你的gitlab或者gitlab-ssl Nginx配置文件。

Restart / 重启

8. Firewall / 防火墙

Configure Firewall / 配置防火墙

By default, CentOS 7 use firewall as firewall, turn back to use iptables firewall.
CentOS 7默认使用的是firewall作为防火墙,这里改为iptables防火墙。
Turn off firewall
关闭firewall

Install iptables firewall
安装iptables防火墙

Turn off SELINUX (OPTIONAL) / 关闭SELINUX(可选)

Done! / 完成!

Double-check Application Status / 双重检验应用状态

To make sure you didn’t miss anything run a more thorough check with:
再一次运行检验程序确保你没有错过任何东西:

If all items are green, then congratulations on successfully installing GitLab!
NOTE: Supply SANITIZE=true environment variable to gitlab:check to omit project names from the output of the check command.
如果所有项目都通过了,说明安装GitLab配置成功!
提示:提供环境变量SANITIZE=true给gitlab:check以忽略检验命令的项目名称输出。

Initial Login / 初始化登陆

Visit YOUR_SERVER in your web browser for your first GitLab login. The setup has created an admin account for you. You can use it to log in:
在浏览器中访问你的服务器的FQDN进行GitLab的首次登陆。安装过程已经为你创建了管理员账号。你可以使用这些信息进行登录:

Important Note: Please go over to your profile page and immediately change the password, so nobody can access your GitLab by using this login information later on.
Enjoy!
重要提示:请转到你的个人资料页并立即修改密码,确保之后没有人可以使用上述登录信息访问你的GitLab。
享受!

Comments

您的电子邮箱地址不会被公开。 必填项已用*标注