环境要求
- Ubuntu/Debian/CentOS/RHEL
- Ruby (MRI) 2.1
- Git 2.7.4+
- Redis 2.8+
- MySQL or PostgreSQL
安装方法
一键镜像源安装(下面各个版本安装方法)
https://about.gitlab.com/downloads/本节介绍基于Ubuntu14.04源码安装方法
GitLab包括以下组件
- Packages / Dependencies
- Ruby
- Go
- System Users
- Database
- Redis
- GitLab
- Nginx
开始部署
一、Packages / Dependencies
sudo is not installed on Debian by default. Make sure your system is up-to-date and install it.
(1) run as root!1
2
3apt-get update -y
apt-get upgrade -y
apt-get install sudo -y
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.
(2) Install vim and set as default editor1
2sudo apt-get install -y vim
sudo update-alternatives --set editor /usr/bin/vim.basic
Install the required packages (needed to compile Ruby and native extensions to Ruby gems):1
sudo apt-get install -y build-essential zlib1g-dev libyaml-dev libssl-dev libgdbm-dev libreadline-dev libncurses5-dev libffi-dev curl openssh-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:1
sudo apt-get install libkrb5-dev
Note: If you don’t know what Kerberos is, you can assume you don’t need it.
Make sure you have the right version of Git installed
(3) Install Git1
sudo apt-get install -y git-core
(4) Make sure Git is version 2.7.4 or higher1
git --version
Is the system packaged Git too old? Remove it and compile from source.
(5) Remove packaged Git1
sudo apt-get remove git-core git
(6) Install dependencies1
sudo apt-get install -y libcurl4-openssl-dev libexpat1-dev gettext libz-dev libssl-dev build-essential
(7) Download and compile from source1
2
3
4
5
6cd /tmp
curl -O --progress https://www.kernel.org/pub/software/scm/git/git-2.7.4.tar.gz
echo '7104c4f5d948a75b499a954524cb281fe30c6649d8abe20982936f75ec1f275b git-2.7.4.tar.gz' | shasum -a256 -c - && tar -xzf git-2.7.4.tar.gz
cd git-2.7.4/
./configure
make prefix=/usr/local all
(8) Install into /usr/local/bin1
2sudo make prefix=/usr/local install
sudo ln -s /usr/local/bin/git /usr/bin/git
(9) When editing config/gitlab.yml (Step 5), change the git -> bin_path to /usr/local/bin/git
Note: In order to receive mail notifications, make sure to install a mail server. By default, Debian is shipped with exim4 but this has problems while Ubuntu does not ship with one. The recommended mail server is postfix and you can install it with:1
sudo apt-get install -y postfix
Then select ‘Internet Site’ and press enter to confirm the hostname.
二、Ruby
Note: The current supported Ruby version is 2.1.x. Ruby 2.2 and 2.3 are currently not supported.
The use of Ruby version managers such as RVM, rbenv or chruby with GitLab in production, frequently leads to hard to diagnose problems. For example, GitLab Shell is called from OpenSSH, and having a version manager can prevent pushing and pulling over SSH. Version managers are not supported and we strongly advise everyone to follow the instructions below to use a system Ruby.
Remove the old Ruby 1.8 if present:1
sudo apt-get remove ruby1.8 ruby
Download Ruby and compile it:1
2
3
4
5
6
7
8
9mkdir /tmp/ruby && cd /tmp/ruby
curl -O --progress https://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.8.tar.gz
echo 'c7e50159357afd87b13dc5eaf4ac486a70011149 ruby-2.1.8.tar.gz' | shasum -c - && tar xzf ruby-2.1.8.tar.gz
cd ruby-2.1.8
./configure --disable-install-rdoc
make
sudo make install
Install the Bundler Gem:
sudo gem install bundler --no-ri --no-rdoc
1 | gem ruby镜像(如果服务器不能访问Ruby源,请按下面操作) |
三、 Go
Since GitLab 8.0, Git HTTP requests are handled by gitlab-workhorse (formerly gitlab-git-http-server). This is a small daemon written in Go. To install gitlab-workhorse we need a Go compiler. The instructions below assume you use 64-bit Linux. You can find downloads for other platforms at the Go download page.1
2
3
4
5curl -O --progress https://storage.googleapis.com/golang/go1.5.3.linux-amd64.tar.gz
echo '43afe0c5017e502630b1aea4d44b8a7f059bf60d7f29dfd58db454d4e4e0ae53 go1.5.3.linux-amd64.tar.gz' | shasum -a256 -c - && \
sudo tar -C /usr/local -xzf go1.5.3.linux-amd64.tar.gz
sudo ln -sf /usr/local/go/bin/{go,godoc,gofmt} /usr/local/bin/
rm go1.5.3.linux-amd64.tar.gz
四、 System Users
Create a git user for GitLab:1
sudo adduser --disabled-login --gecos 'GitLab' git
五、 Database
(1) MYSQL Install
Install the database packages
1 | sudo apt-get install -y mysql-server mysql-client libmysqlclient-dev |
Ensure you have MySQL version 5.5.14 or later
1 | mysql --version |
Pick a MySQL root password (can be anything), type it and press enter
Retype the MySQL root password and press enter
Secure your installation
1 | sudo mysql_secure_installation |
Login to MySQL
1 | mysql -u root -p |
Type the MySQL root password
Create a user for GitLab
do not type the ‘mysql>’, this is part of the prompt
change $password in the command below to a real password you pick1
mysql> CREATE USER 'git'@'localhost' IDENTIFIED BY '$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”1
mysql> SET storage_engine=INNODB;
Create the GitLab production database
1 | mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`; |
Grant the GitLab user necessary permissions on the database
1 | mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, CREATE TEMPORARY TABLES, DROP, INDEX, ALTER, LOCK TABLES ON `gitlabhq_production`.* TO 'git'@'localhost'; |
Quit the database session
1 | mysql> \q |
Try connecting to the new database with the new user
1 | sudo -u git -H mysql -u git -p -D gitlabhq_production |
Type the password you replaced $password with earlier
1 | You should now see a 'mysql>' prompt |
Quit the database session
1 | mysql> \q |
You are done installing the database and can go back to the rest of the installation.
MySQL strings limits
After installation or upgrade, remember to run the add_limits_mysql Rake task:1
bundle exec rake add_limits_mysql
The text type in MySQL has a different size limit than the text type in PostgreSQL. In MySQL text columns are limited to ~65kB, whereas in PostgreSQL text columns are limited up to ~1GB!
The add_limits_mysql Rake task converts some important text columns in the GitLab database to longtext columns, which can persist values of up to 4GB (sometimes less if the value contains multibyte characters).
(2)Postgresql Install
1.Install the database packages:1
sudo apt-get install -y postgresql postgresql-client libpq-dev postgresql-contrib
2.Create a database user for GitLab:1
sudo -u postgres psql -d template1 -c "CREATE USER git CREATEDB;"
3.Create the GitLab production database and grant all privileges on database:1
sudo -u postgres psql -d template1 -c "CREATE DATABASE gitlabhq_production OWNER git;"
4.Create the pg_trgm extension (required for GitLab 8.6+):1
sudo -u postgres psql -d template1 -c "CREATE EXTENSION IF NOT EXISTS pg_trgm;"
5.Try connecting to the new database with the new user:1
sudo -u git -H psql -d gitlabhq_production
6.Check if the pg_trgm extension is enabled:1
2
3
4SELECT true AS enabled
FROM pg_available_extensions
WHERE name = 'pg_trgm'
AND installed_version IS NOT NULL;
If the extension is enabled this will produce the following output:1
2
3
4enabled
---------
t
(1 row)
7.Quit the database session:1
gitlabhq_production> \q
六、Redis
GitLab requires at least Redis 2.8.
If you are using Debian 8 or Ubuntu 14.04 and up, then you can simply install Redis 2.8 with:
sudo apt-get install redis-server
If you are using Debian 7 or Ubuntu 12.04, follow the special documentation on an alternate Redis installation. Once done, follow the rest of the guide here.
Configure redis to use sockets
1 | sudo cp /etc/redis/redis.conf /etc/redis/redis.conf.orig |
Disable Redis listening on TCP by setting ‘port’ to 0
1 | sed 's/^port .*/port 0/' /etc/redis/redis.conf.orig | sudo tee /etc/redis/redis.conf |
Enable Redis socket for default Debian / Ubuntu path
1 | echo 'unixsocket /var/run/redis/redis.sock' | sudo tee -a /etc/redis/redis.conf |
Grant permission to the socket to all members of the redis group
1 | echo 'unixsocketperm 770' | sudo tee -a /etc/redis/redis.conf |
Create the directory which contains the socket
1 | mkdir /var/run/redis |
Persist the directory which contains the socket, if applicable
1 | if [ -d /etc/tmpfiles.d ]; then |
Activate the changes to redis.conf
1 | sudo service redis-server restart |
Add git to the redis group
1 | sudo usermod -aG redis git |
七、GitLab
We’ll install GitLab into home directory of the user “git”1
cd /home/git
(1) Clone the Source
Clone GitLab repository1
sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 8-9-stable gitlab
Note: You can change 8-9-stable to master if you want the bleeding edge version, but never install master on a production server!
(2) Configure It
Go to GitLab installation folder1
cd /home/git/gitlab
Copy the example GitLab config1
sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml
Update GitLab config file, follow the directions at top of file1
sudo -u git -H editor config/gitlab.yml
Copy the example secrets file1
2sudo -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/ directories1
2
3
4sudo 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/ directories1
2sudo chmod -R u+rwX tmp/pids/
sudo chmod -R u+rwX tmp/sockets/
Create the public/uploads/ directory1
sudo -u git -H mkdir public/uploads/
Make sure only the GitLab user has access to the public/uploads/ directory
now that files in public/uploads are served by gitlab-workhorse1
sudo chmod 0700 public/uploads
Change the permissions of the directory where CI build traces are stored1
sudo chmod -R u+rwX builds/
Change the permissions of the directory where CI artifacts are stored1
sudo chmod -R u+rwX shared/artifacts/
Copy the example Unicorn config1
sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb
Find number of cores1
nproc
Enable cluster mode if you expect to have a high load instance
Set the number of workers to at least the number of cores
Ex. change amount of workers to 3 for 2GB RAM server1
sudo -u git -H vim config/unicorn.rb
Copy the example Rack attack config1
sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb
Configure Git global settings for git user
‘autocrlf’ is needed for the web editor1
sudo -u git -H git config --global core.autocrlf input
Disable ‘git gc –auto’ because GitLab already runs ‘git gc’ when needed1
sudo -u git -H git config --global gc.auto 0
Configure Redis connection settings1
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 configuration1
sudo -u git -H vim config/resque.yml
Important Note: Make sure to edit both gitlab.yml and unicorn.rb to match your setup.
Note: If you want to use HTTPS, see Using HTTPS for the additional steps.
(3) Configure GitLab DB Settings1
2# PostgreSQL only:
sudo -u git cp config/database.yml.postgresql config/database.yml
MySQL only:1
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 password1
sudo -u git -H editor config/database.yml
PostgreSQL and MySQL:
Make config/database.yml readable to git only1
sudo -u git -H chmod o-rwx config/database.yml
(4) Install Gems
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”)1
sudo -u git -H bundle install --deployment --without development test mysql aws kerberos
Or if you use MySQL (note, the option says “without … postgres”)1
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.
(5) Install 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):1
sudo -u git -H bundle exec rake gitlab:shell:install 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:1
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)”.
(6) Install gitlab-workhorse
GitLab-Workhorse uses GNU Make. If you are not using Linux you may have to run gmake instead of make below.1
2
3
4
5cd /home/git
sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-workhorse.git
cd gitlab-workhorse
sudo -u git -H git checkout v0.7.5
sudo -u git -H make
(7) Initialize Database and Activate Advanced Features
Go to GitLab installation folder1
2cd /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 and e-mail by supplying them in environmental variables, GITLAB_ROOT_PASSWORD and GITLAB_ROOT_EMAIL respectively, 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.1
sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production GITLAB_ROOT_PASSWORD=yourpassword GITLAB_ROOT_EMAIL=youremail
(8) 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.
(9) Install Init Script
Download the init script (will be /etc/init.d/gitlab):1
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:1
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:1
sudo update-rc.d gitlab defaults 21
(10) Setup Logrotate1
sudo cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab
(11) Check Application Status
Check if GitLab and its environment are configured correctly:1
sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production
(12) Compile Assets1
sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production
(13) Start Your GitLab Instance1
sudo service gitlab start
or1
sudo /etc/init.d/gitlab restart
八、Nginx
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.
(1) Installation1
sudo apt-get install -y nginx
(2) Site Configuration
Copy the example site config:1
2sudo cp lib/support/nginx/gitlab /etc/nginx/sites-available/gitlab
sudo ln -s /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab
Make sure to edit the config file to match your setup:
Change YOUR_SERVER_FQDN to the fully-qualified
domain name of your host serving GitLab.
If using Ubuntu default nginx install:
either remove the default_server from the listen line
or else1
2sudo rm -f /etc/nginx/sites-enabled/default
sudo editor /etc/nginx/sites-available/gitlab
Note: If you want to use HTTPS, replace the gitlab Nginx config with gitlab-ssl. See Using HTTPS for HTTPS configuration details.
(3) Test Configuration
Validate your gitlab or gitlab-ssl Nginx config file with the following command:1
sudo nginx -t
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.
(4) Restart1
sudo service nginx restart
Done!
部署完成后检查和配置https
1.Double-check Application Status
To make sure you didn’t miss anything run a more thorough check with:1
sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production
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.
2.Initial Login
Visit YOUR_SERVER in your web browser for your first GitLab login.
If you didn’t provide a root password during setup, you’ll be redirected to a password reset screen to provide the password for the initial administrator account. Enter your desired password and you’ll be redirected back to the login screen.
The default account’s username is root. Provide the password you created earlier and login. After login you can change the username if you wish.
Enjoy!
You can use sudo service gitlab start and sudo service gitlab stop to start and stop GitLab.
3.Advanced Setup Tips
Relative URL support
See the Relative URL documentation for more information on how to configure GitLab with a relative URL.
4.Using HTTPS
To use GitLab with HTTPS:
(1) In gitlab.yml:
Set the port option in section 1 to 443.
Set the https option in section 1 to true.
(2) In the config.yml of gitlab-shell:
Set gitlab_url option to the HTTPS endpoint of GitLab (e.g. https://git.example.com).
Set the certificates using either the ca_file or ca_path option.
(3) Use the gitlab-ssl Nginx example config instead of the gitlab config.
Update YOUR_SERVER_FQDN.
Update ssl_certificate and ssl_certificate_key.
Review the configuration file and consider applying other security and performance enhancing features.
5.Using a self-signed certificate is discouraged but if you must use it follow the normal directions then:
(1) Generate a self-signed SSL certificate:1
2
3
4mkdir -p /etc/nginx/ssl/
cd /etc/nginx/ssl/
sudo openssl req -newkey rsa:2048 -x509 -nodes -days 3560 -out gitlab.crt -keyout gitlab.key
sudo chmod o-r gitlab.key
(2) In the config.yml of gitlab-shell set self_signed_cert to true.
6.Enable Reply by email
See the “Reply by email” documentation for more information on how to set this up.
7.LDAP Authentication
You can configure LDAP authentication in config/gitlab.yml. Please restart GitLab after editing this file.
8.Using Custom Omniauth Providers
See the omniauth integration document
9.Build your projects
GitLab can build your projects. To enable that feature you need GitLab Runners to do that for you. Checkout the GitLab Runner section to install it
10.Adding your Trusted Proxies
If you are using a reverse proxy on an separate machine, you may want to add the proxy to the trusted proxies list. Otherwise users will appear signed in from the proxy’s IP address.
You can add trusted proxies in config/gitlab.yml by customizing the trusted_proxies option in section 1. Save the file and reconfigure GitLab for the changes to take effect.
11.Custom Redis Connection
If you’d like Resque to connect to a Redis server on a non-standard port or on a different host, you can configure its connection string via the config/resque.yml file.
example
production: redis://redis.example.tld:6379
If you want to connect the Redis server via socket, then use the “unix:” URL scheme and the path to the Redis socket file in the
config/resque.yml file.
example
production: unix:/path/to/redis/socket
12.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.
13.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.
14.Troubleshooting
“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-workhorse instance. Double-check that you’ve installed Go, installed gitlab-workhorse, and correctly configured Nginx.
---本文结束感谢您的阅读。微信扫描二维码,关注我的公众号---
本文链接: https://www.yp14.cn/2016/07/05/GitLab/
版权声明: 本作品采用 知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议 进行许可。转载请注明出处!