0.添加一些必要的YUM源
EPEL啊 mariaDB啊 remi这些的
还要有RUBY版本管理器RVM
1. 依赖项
执行下面的几条命令
# run as root!
yum -y update
yum -y groupinstall 'Development Tools'
yum -y install readline readline-devel ncurses-devel gdbm-devel glibc-devel tcl-devel openssl-devel curl-devel expat-devel db4-devel byacc sqlite-devel libyaml libyaml-devel libffi libffi-devel libxml2 libxml2-devel libxslt libxslt-devel libicu libicu-devel system-config-firewall-tui redis sudo wget crontabs logwatch logrotate perl-Time-HiRes
然后把VIM作为默认的editor
# Install vim and set as default editor
yum install -y vim
sudo update-alternatives --set editor /usr/bin/vim.basic
再装一些编译用的
yum install -y 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 nodejs
唔帮徒的看一下下面的
If you want to use Kerberos for user authentication, then install libkrb5-dev:
yum install libkrb5-dev
Note: If you don't know what Kerberos is, you can assume you don't need it.
centos7的git模板版本就够(泪啊,centos的默认包终于还算行了)
# Install Git
yum install -y git
# Make sure Git is version 1.7.10 or higher, for example 1.7.12 or 2.0.0
git --version
gitlab用postfix发email的
yum install -y postfix
Then select 'Internet Site' and press enter to confirm the hostname.
2. Ruby
安装ruby
yum install ruby
yum install ruby-devel
接着安装 Bundler Gem:
sudo gem install bundler --no-ri --no-rdoc
(如果报错请看本站的添加RUBY源)
gem install rdoc-data; rdoc-data --install
3. Go
安装GO
yum install go
4. System Users
添加GITLAB用户
adduser --system --shell /bin/bash --comment
'GitLab'
--create-home --home-dir /home/git/ git
Important : Important: In order to include /usr/local/bin to git user's PATH, one way is to edit the sudoers file. As root run:
配置一下环境变量
1
2
3
4
5
6
7
8
|
# type an enter : visudo #search for the line and and append <b>/usr/local/bin</b> like so: Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin #like this -----> Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin |
save and exit
5. Database
数据库支持两种,1种mysql,1种postgresql
按以下步骤执行
# I安装
yum install -y postgresql postgresql-client postgresql-devel
# 登陆
sudo -u postgres psql -d template1
# 创建用户
# Do not type the 'template1=#', this is part of the prompt
template1=# CREATE USER git CREATEDB;
# 授权
template1=# CREATE DATABASE gitlabhq_production OWNER git;
# 退出
template1=# \q
# 测试
sudo -u git -H psql -d gitlabhq_production
# 退出
gitlabhq_production> \q
# 安装
yum install -y mysql-server mysql-client lmysql-devel
# Ensure you have MySQL version 5.5.14 or later
mysql --version
systemctl enable mysql
systemctl start mysql
# 初始化
sudo mysql_secure_installation
# 登陆
mysql -u root -p
# Type the MySQL root password
# 创建用户
# do not type the 'mysql>', this is part of the prompt
# change $password in the command below to a real password you pick
mysql> CREATE USER 'git'@'localhost' IDENTIFIED BY '$password';
# 选择储存引擎
# If this fails, check your MySQL config files (e.g. `/etc/mysql/*.cnf`, `/etc/mysql/conf.d/*`) for the setting "innodb = off"
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, CREATE TEMPORARY TABLES, DROP, INDEX, ALTER, LOCK TABLES ON `gitlabhq_production`.* TO 'git'@'localhost';
# 退出
mysql> \q
# 测试
sudo -u git -H mysql -u git -p -D gitlabhq_production
# Type the password you replaced $password with earlier
# 查看权限
'mysql>' prompt
# 退出
mysql> \q
# You are done installing the database and can go back to the rest of the installation.
6. Redis
安装REDIS
Make sure redis is started on boot:
chkconfig redis on
配置接口
Configure redis to use sockets:
cp /etc/redis.conf /etc/redis.conf.orig
进制REDIS监听TCP端口,防止黑客
Disable Redis listening on TCP by setting 'port' to 0:
sed 's/^port .*/port 0/' /etc/redis.conf.orig | tee /etc/redis.conf
Enable Redis socket for default CentOS path:
echo 'unixsocket /run/redis/redis.sock' | tee -a /etc/redis.conf
echo -e 'unixsocketperm 0770' | tee -a /etc/redis.conf
Create the directory which contains the socket
mkdir /var/run/redis
chown redis:redis /var/run/redis
chmod 755 /var/run/redis
导入接口
if [ -d /etc/tmpfiles.d ]; then
echo 'd /run/redis 0755 redis redis 10d -' | tee -a /etc/tmpfiles.d/redis.conf
fi
重启生效一下
service redis restart
# 添加 git 进 redis 组
usermod -aG redis git
7. GitLab
开始弄GIT啦
# 创建文件夹(如果没有的话)
cd /home/git
下载源代码(此处可以用screen)
# Clone GitLab repository
sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 8-0-stable gitlab
Note: You can change 8-0-stable
to master
if you want the bleeding edge version, but never install master on a production server!
你可以把stable换成master,但是在生产环境下不推荐这么做
----
配置
# Go to GitLab installation folder
cd /home/git/gitlab
# Copy the example GitLab config
sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml
# Update GitLab config file, follow the directions at top of file
sudo -u git -H editor config/gitlab.yml
# Copy the example secrets file
sudo -u git -H cp config/secrets.yml.example config/secrets.yml
sudo -u git -H chmod 0600 config/secrets.yml
# Make sure GitLab can write to the log/ and tmp/ directories
sudo chown -R git log/
sudo chown -R git tmp/
sudo chmod -R u+rwX,go-w log/
sudo chmod -R u+rwX tmp/
# Make sure GitLab can write to the tmp/pids/ and tmp/sockets/ directories
sudo chmod -R u+rwX tmp/pids/
sudo chmod -R u+rwX tmp/sockets/
# Make sure GitLab can write to the public/uploads/ directory
sudo chmod -R u+rwX public/uploads
# Change the permissions of the directory where CI build traces are stored
sudo chmod -R u+rwX builds/
# Copy the example Unicorn config
sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb
# Find number of cores
nproc
# Enable cluster mode if you expect to have a high load instance
# Ex. change amount of workers to 3 for 2GB RAM server
# Set the number of workers to at least the number of cores
sudo -u git -H editor config/unicorn.rb
# Copy the example Rack attack config
sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb
# Configure Git global settings for git user, used when editing via web editor
sudo -u git -H git config --global core.autocrlf input
# Configure Redis connection settings
sudo -u git -H cp config/resque.yml.example config/resque.yml
# Change the Redis socket path if you are not using the default Debian / Ubuntu configuration
sudo -u git -H editor config/resque.yml
Important Note: Make sure to edit both gitlab.yml
and unicorn.rb
to match your setup.
一定要确认gitlab.yml和unicorn.rb是适合你的服务器的。
Note: If you want to use HTTPS, see Using HTTPS for the additional steps.
如果你想配置HTTPS请点上面那个HTTPS的超链接
配置GITLAB和数据库
# 用postgresql数据库的看这里
#PostgreSQL only:
sudo -u git cp config/database.yml.postgresql config/database.yml
# MySQL only:用Mysql mariadb的看这里
sudo -u git cp config/database.yml.mysql config/database.yml
# MySQL and remote PostgreSQL only:数据库不在本机的看这里
# Update username/password in config/database.yml.
# You only need to adapt the production settings (first part).
# If you followed the database guide then please do as follows:
# Change 'secure password' with the value you have given to $password
# You can keep the double quotes around the password
sudo -u git -H editor config/database.yml
# PostgreSQL and MySQL:
# Make config/database.yml readable to git only
sudo -u git -H chmod o-rwx config/database.yml
安装GEM
Note: As of bundler 1.5.2, you can invoke bundle install -jN
(where N
the number of your processor cores) and enjoy the parallel gems installation with measurable difference in completion time (~60% faster). Check the number of your cores with nproc
. For more information check this post. First make sure you have bundler >= 1.5.2 (run bundle -v
) as it addresses some issues that were fixed in 1.5.2.
# For PostgreSQL (note, the option says "without ... mysql")装postgresql的看这里
sudo -u git -H bundle install --deployment --without development test mysql aws kerberos
# Or if you use MySQL (note, the option says "without ... postgres")装MYSQL的看这里
sudo -u git -H bundle install --deployment --without development test postgres aws kerberos
Note: If you want to use Kerberos for user authentication, then omit kerberos
in the --without
option above.
安装GitLab Shell
GitLab Shell is an SSH access and repository management software developed specially for GitLab.
# Run the installation task for gitlab-shell (replace `REDIS_URL` if needed):
sudo -u git -H bundle exec rake gitlab:shell:install[v2.6.5] REDIS_URL=unix:/var/run/redis/redis.sock RAILS_ENV=production
# By default, the gitlab-shell config is generated from your main GitLab config.
# You can review (and modify) the gitlab-shell config as follows:
sudo -u git -H editor /home/git/gitlab-shell/config.yml
Note: If you want to use HTTPS, see Using HTTPS for the additional steps.
Note: Make sure your hostname can be resolved on the machine itself by either a proper DNS record or an additional line in /etc/hosts ("127.0.0.1 hostname"). This might be necessary for example if you set up gitlab behind a reverse proxy. If the hostname cannot be resolved, the final installation check will fail with "Check GitLab API access: FAILED. code: 401" and pushing commits will be rejected with "[remote rejected] master -> master (hook declined)".
安装gitlab http server
cd /home/git
sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-git-http-server.git
cd gitlab-git-http-server
sudo -u git -H make
初始化数据库和激活高级特性
cd /home/git/gitlab/
sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production
# Type 'yes' to create the database tables.
# When done you see 'Administrator account created:'
Note: You can set the Administrator/root password by supplying it in environmental variable GITLAB_ROOT_PASSWORD
as seen below. If you don't set the password (and it is set to the default one) please wait with exposing GitLab to the public internet until the installation is done and you've logged into the server the first time. During the first login you'll be forced to change the default password.
sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production GITLAB_ROOT_PASSWORD=yourpassword
保护密码
Secure secrets.yml
The secrets.yml
file stores encryption keys for sessions and secure variables. Backup secrets.yml
someplace safe, but don't store it in the same place as your database backups. Otherwise your secrets are exposed if one of your backups is compromised.
安装计划表
Install schedules
# Setup schedules
sudo -u gitlab_ci -H bundle exec whenever -w RAILS_ENV=production
安装初始化脚本
Install Init Script
Download the init script (will be /etc/init.d/gitlab
):
sudo cp lib/support/init.d/gitlab /etc/init.d/gitlab
And if you are installing with a non-default folder or user copy and edit the defaults file:
sudo cp lib/support/init.d/gitlab.default.example /etc/default/gitlab
If you installed GitLab in another directory or as a user other than the default you should change these settings in /etc/default/gitlab
. Do not edit/etc/init.d/gitlab
as it will be changed on upgrade.
Make GitLab start on boot:
sudo update-rc.d gitlab defaults 21
安装 Logrotate
sudo cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab
检查应用状态
Check if GitLab and its environment are configured correctly:
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
# or
sudo /etc/init.d/gitlab restart
9. apache
Note: Nginx is the officially supported web server for GitLab. If you cannot or do not want to use Nginx as your web server, have a look at the GitLab recipes.
安装
yum install httpd
站点配置
Copy the example site config:
cd /etc/httpd/conf
wget https://gitlab.com/gitlab-org/gitlab-recipes/blob/8cee2936371f6d597990adc19f02f03338a8b8ed/web-server/apache/gitlab-8.0-apache2.4.conf
编辑一下httpd.conf
把这个vhost conf添加进去
vi http.conf
重启Apache
systemctl restart httpd
至此就完成了
再检测一下安装是否正确
sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production
初始化登陆
root
5iveL!fe
Important Note: On login you'll be prompted to change the password.
愉悦~!
Custom SSH Connection
If you are running SSH on a non-standard port, you must change the GitLab user's SSH config.
# Add to /home/git/.ssh/config
host localhost # Give your setup a name (here: override localhost)
user git # Your remote git user
port 2222 # Your port number
hostname 127.0.0.1; # Your server name or IP
You also need to change the corresponding options (e.g. ssh_user
, ssh_host
, admin_uri
) in the config\gitlab.yml
file.
设置QQ邮箱发件GitLab SMTP
sudo mv /home/git/gitlab/config/initializers/smtp_settings.rb.example /home/git/gitlab/config/initializers/smtp_settings.rb
$ sudo vim /home/git/gitlab/config/initializers/smtp_settings.rb
# To enable smtp email delivery for your GitLab instance do the following:
# 1. Rename this file to smtp_settings.rb
# 2. Edit settings inside this file
# 3. Restart GitLab instance #
# For full list of options and their values see http://api.rubyonrails.org/classes/ActionMailer/Base.html #
# If you change this file in a Merge Request, please also create a Merge Request on https://gitlab.com/gitlab-org/omnibus-gitlab/merge_requests
if Rails.env.production? Gitlab::Application.config.action_mailer.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
address: "smtp.qq.com",
port: 25,
user_name: "username@domainname", //
QQ企业邮箱账号 password: "password",
domain: "smtp.qq.com",
authentication: :plain,
enable_starttls_auto: false,
openssl_verify_mode: 'none' # See ActionMailer documentation for other possible options
}
end
$ sudo /home/git/gitlab/config/environments/production.rb
...
config.action_mailer.delivery_method = :smtp //这里修改为:smtp
# Defaults to:
# # config.action_mailer.sendmail_settings = {
# # location: '/usr/sbin/sendmail',
# # arguments: '-i -t'
# # } ...
$ sudo service gitlab restart && sudo service apache restart
Additional Markup Styles
Apart from the always supported markdown style there are other rich text files that GitLab can display. But you might have to install a dependency to do so. Please see the github-markup gem readme for more information.
Troubleshooting
如果使用的是apache但是提示NGINX错误什么的话,执行
bundle exec unicorn_rails -c config/unicorn.rb -E production -D
"You appear to have cloned an empty repository."
If you see this message when attempting to clone a repository hosted by GitLab, this is likely due to an outdated Nginx or Apache configuration, or a missing or misconfigured gitlab-git-http-server
instance. Double-check that you've installed Go, installed gitlab-git-http-server, and correctly configured Nginx.
备份
# if you've installed GitLab from source
sudo -u git -H bundle exec rake gitlab:backup:create RAILS_ENV=production