Gitlab需要用到的依赖环境
Ruby
Git
GitLab
Nginx
PostgreSQL or MySQL
1. Packages /Dependencies
sudo is notinstalled on Debian by default. Make sure your system is up-to-date and installit.
# run asroot!
apt-getupdate -y
apt-getupgrade -y
apt-getinstall sudo -y
Note: Duringthis installation some files will need to be edited manually. If you arefamiliar with vim set it as default editor with the commands below. If you arenot familiar with vim please skip this and keep using the default editor.
# Install vimand set as default editor
sudoapt-get install -y vim
sudoupdate-alternatives --set editor /usr/bin/vim.basic
Install therequired packages (needed to compile Ruby and native extensions to Ruby gems):
sudoapt-get install -y build-essential zlib1g-dev libyaml-dev libssl-devlibgdbm-dev libreadline-dev libncurses5-dev libffi-dev curl openssh-serverredis-server checkinstall libxml2-dev libxslt-dev libcurl4-openssl-devlibicu-dev logrotate
Make sure youhave the right version of Git installed
# Install Git
sudoapt-get install -y git-core
# Make sureGit is version 1.7.10 or higher, for example 1.7.12 or 1.8.4
git--version
Is the systempackaged Git too old? Remove it and compile from source.
# Removepackaged Git
sudoapt-get remove git-core
# Installdependencies
sudoapt-get install -y libcurl4-openssl-dev libexpat1-dev gettext libz-devlibssl-dev build-essential
# Downloadand compile from source
cd /tmp
curl--progress https://git-core.googlecode.com/files/git-1.8.5.2.tar.gz | tar xz
cdgit-1.8.5.2/
makeprefix=/usr/local all
# Installinto /usr/local/bin
sudomake prefix=/usr/local install
#When editing config/gitlab.yml (Step 6), change the git bin_path to/usr/local/bin/git
Note: Inorder to receive mail notifications, make sure to install a mail server. Bydefault, Debian is shipped with exim4 whereas Ubuntu does not ship with one.The recommended mail server is postfix and you can install it with:
sudoapt-get install -y postfix
Then select'Internet Site' and press enter to confirm the hostname.
2. Ruby
The use ofruby version managers such as RVM, rbenv or chruby with GitLab in productionfrequently leads to hard to diagnose problems. For example, GitLab Shell iscalled from OpenSSH and having a version manager can prevent pushing andpulling over SSH. Version managers are not supported and we stronly adviseeveryone to follow the instructions below to use a system ruby.
Remove theold Ruby 1.8 if present
sudoapt-get remove ruby1.8
Download Rubyand compile it:
mkdir/tmp/ruby && cd /tmp/ruby
curl--progress ftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p481.tar.gz | tar xz
cdruby-2.0.0-p481
./configure--disable-install-rdoc
make
sudomake install
Install theBundler Gem:
sudogem install bundler --no-ri --no-rdoc
3. SystemUsers
Create a gituser for Gitlab: 此处是一大坑
sudoadduser --disabled-login --gecos 'GitLab' git
这样就不能使用ssh登陆了,--disabled-login不运行passwd设置密码,用户只有设置了密码才能使用他的账号。所以就出问题了。
应该使用:
sudo adduser --disabled-password --gecos 'GitLab' git
4. Database
We recommendusing a PostgreSQL database. For MySQL check MySQL setup guide. NOTE: becausewe need to make use of extensions you need at least pgsql 9.1.
# Install thedatabase packages
sudoapt-get install -y postgresql-9.1 postgresql-client libpq-dev
# Login toPostgreSQL
sudo-u postgres psql -d template1
# Create auser for GitLab.
template1=#CREATE USER git CREATEDB;
# Create theGitLab production database & grant all privileges on database
template1=#CREATE DATABASE gitlabhq_production OWNER git;
# Quit thedatabase session
template1=#\q
# Tryconnecting to the new database with the new user
sudo-u git -H psql -d gitlabhq_production
5. GitLab
# We'llinstall GitLab into home directory of the user "git"
cd/home/git
Clone theSource
# CloneGitLab repository
sudo-u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 6-9-stablegitlab
# Go togitlab dir
cd/home/git/gitlab
Note: You canchange 6-9-stable to master if you want the bleeding edge version, but neverinstall master on a production server!
Configure it
cd/home/git/gitlab
# Copy theexample GitLab config
sudo-u git -H cp config/gitlab.yml.example config/gitlab.yml
#Make sure to change "localhost" to the fully-qualified domain name ofyour
# hostserving GitLab where necessary
#
# If youinstalled Git from source, change the git bin_pathto /usr/local/bin/git
sudo-u git -H editor config/gitlab.yml
# Make sureGitLab can write to the log/ and tmp/ directories
sudochown -R git log/
sudochown -R git tmp/
sudochmod -R u+rwX log/
sudochmod -R u+rwX tmp/
# Createdirectory for satellites
sudo-u git -H mkdir /home/git/gitlab-satellites
sudochmod u+rwx,g+rx,o-rwx /home/git/gitlab-satellites
# Make sureGitLab can write to the tmp/pids/ and tmp/sockets/ directories
sudochmod -R u+rwX tmp/pids/
sudochmod -R u+rwX tmp/sockets/
# Make sureGitLab can write to the public/uploads/ directory
sudochmod -R u+rwX public/uploads
# Copy the exampleUnicorn config
sudo-u git -H cp config/unicorn.rb.example config/unicorn.rb
# Enablecluster mode if you expect to have a high load instance
# Ex. changeamount of workers to 3 for 2GB RAM server x
sudo-u git -H editor config/unicorn.rb
# Copy theexample Rack attack config
sudo-u git -H cp config/initializers/rack_attack.rb.exampleconfig/initializers/rack_attack.rb
# ConfigureGit global settings for git user, useful when editing via web
# Edituser.email according to what is set in gitlab.yml
sudo-u git -H git config --global user.name "GitLab"
sudo-u git -H git config --global user.email "example@example.com"
sudo-u git -H git config --global core.autocrlf input
ImportantNote: Make sure to edit both gitlab.yml and unicorn.rb to match your setup.
ConfigureGitLab DB settings
# PostgreSQLonly:
sudo-u git cp config/database.yml.postgresql config/database.yml
# MySQL only:
sudo-u git cp config/database.yml.mysql config/database.yml
# MySQL andremote PostgreSQL only:
# Update username/passwordin config/database.yml.
# You onlyneed to adapt the production settings (first part).
# If youfollowed the database guide then please do as follows:
# Change'secure password' with the value you have given to $password
# You cankeep the double quotes around the password
sudo-u git -H editor config/database.yml
# PostgreSQLand MySQL:
# Makeconfig/database.yml readable to git only
sudo-u git -H chmod o-rwx config/database.yml
Install Gems
Note: As ofbundler 1.5.2, you can invoke bundle install -jN (where N the number of yourprocessor cores) and enjoy the parallel gems installation with measurabledifference in completion time (~60% faster). Check the number of your coreswith nproc. For more information check this post. First make sure you havebundler >= 1.5.2 (run bundle -v) as it addresses some issues that were fixedin 1.5.2.
cd/home/git/gitlab
# ForPostgreSQL (note, the option says "without ... mysql")
sudo-u git -H bundle install --deployment --without development test mysql aws
# Or if youuse MySQL (note, the option says "without ... postgres")
sudo-u git -H bundle install --deployment --without development test postgres aws
InstallGitLab shell
GitLab Shellis an ssh access and repository management software developed specially forGitLab.
# Go to theGitlab installation folder:
cd/home/git/gitlab
# Run theinstallation task for gitlab-shell (replace `REDIS_URL` if needed):
sudo-u git -H bundle exec rake gitlab:shell:install[v1.9.4] REDIS_URL=redis://localhost:6379RAILS_ENV=production
# By default,the gitlab-shell config is generated from your main gitlab config. You canreview (and modify) it as follows:
sudo-u git -H editor /home/git/gitlab-shell/config.yml X
InitializeDatabase and Activate Advanced Features
sudo-u git -H bundle exec rake gitlab:setup RAILS_ENV=production
# Type 'yes' to create the database tables.
# When doneyou see 'Administrator account created:'
Install InitScript
Download theinit script (will be /etc/init.d/gitlab):
sudocp lib/support/init.d/gitlab /etc/init.d/gitlab
And if youare installing with a non-default folder or user copy and edit the defaultsfile:
sudocp lib/support/init.d/gitlab.default.example /etc/default/gitlab
If youinstalled gitlab in another directory or as a user other than the default youshould change these settings in /etc/default/gitlab. Do not edit/etc/init.d/gitlab as it will be changed on upgrade.
Make GitLabstart on boot:
sudoupdate-rc.d gitlab defaults 21
Set uplogrotate
sudocp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab
CheckApplication Status
Check ifGitLab and its environment are configured correctly:
sudo-u git -H bundle exec rake gitlab:env:info RAILS_ENV=production
Compileassets
sudo-u git -H bundle exec rake assets:precompile RAILS_ENV=production
Start YourGitLab Instance
sudoservice gitlab start
# or
sudo/etc/init.d/gitlab restart
6. Nginx
Note: Nginxis the officially supported web server for GitLab. If you cannot or do not wantto use Nginx as your web server, have a look at the GitLab recipes.
Installation
sudoapt-get install -y nginx
SiteConfiguration
Download anexample site config:
sudocp lib/support/nginx/gitlab /etc/nginx/sites-available/gitlab
sudoln -s /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab
Make sure toedit the config file to match your setup:
# Change YOUR_SERVER_FQDNto the fully-qualified
# domain nameof your host serving GitLab.
sudo editor/etc/nginx/sites-available/gitlab
Restart
sudoservice nginx restart
Done!
Double-checkApplication Status
To make sureyou didn't miss anything run a more thorough check with:
sudo-u git -H bundle exec rake gitlab:check RAILS_ENV=production
If all itemsare green, then congratulations on successfully installing GitLab!
Initial Login
VisitYOUR_SERVER in your web browser for your first GitLab login. The setup hascreated an admin account for you. You can use it to log in:
root
5iveL!fe
ImportantNote: 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!
AdvancedSetup Tips
Additionalmarkup styles
Apart fromthe always supported markdown style there are other rich text files that GitLabcan display. But you might have to install a dependency to do so. Please seethe github-markup gem readme for more information. For example,reStructuredText markup language support requires python-docutils:
sudoapt-get install -y python-docutils
Custom RedisConnection
If you'd likeResque to connect to a Redis server on a non-standard port or on a differenthost, you can configure its connection string via the config/resque.yml file.
# example
production:redis://redis.example.tld:6379
If you wantto connect the Redis server via socket, then use the "unix:" URLscheme and the path to the Redis socket file in the config/resque.yml file.
# example
production:unix:/path/to/redis/socket
Custom SSHConnection
If you arerunning SSH on a non-standard port, you must change the gitlab user's SSHconfig.
# Add to/home/git/.ssh/config
hostlocalhost # Give your setup aname (here: override localhost)
user git # Your remote git user
port 2222 # Your port number
hostname 127.0.0.1; # Your server name orIP
You also needto change the corresponding options (e.g. ssh_user, ssh_host, admin_uri) in theconfig\gitlab.yml file.
LDAPauthentication
You canconfigure LDAP authentication in config/gitlab.yml. Please restart GitLab afterediting this file.
Using CustomOmniauth Providers
GitLab usesOmniauth for authentication and already ships with a few providers preinstalled(e.g. LDAP, GitHub, Twitter). But sometimes that is not enough and you need tointegrate with other authentication solutions. For these cases you can use theOmniauth provider.
Steps
These stepsare fairly general and you will need to figure out the exact details from theOmniauth provider's documentation.
Stop GitLab sudo service gitlab stop
Addprovider specific configuration options to your config/gitlab.yml (you can usethe auth providers section of the example config as a reference)
Add the gem to your Gemfile gem"omniauth-your-auth-provider"
If you're using MySQL, install the newOmniauth provider gem by running the following command:sudo -u git -H bundle install --without development test postgres --pathvendor/bundle --no-deployment
If you're using PostgreSQL, install the newOmniauth provider gem by running the following command:sudo -u git -H bundle install --without development test mysql --pathvendor/bundle --no-deployment
These are the same commands you used in theInstall Gems section with --path vendor/bundle --no-deployment instead of--deployment.
Start GitLab sudo service gitlab start
配置url的地方有:
sudo-u git -H cp config/gitlab.yml.example config/gitlab.yml
sudoeditor /etc/nginx/sites-available/gitlab
原文地址:https://github.com/gitlabhq/gitlabhq/blob/master/doc/install/installation.md