https://gitlab.com/gitlab-org/gitlab-recipes/tree/master/install/centos --centos安装gitlab
https://github.com/gitlabhq/gitlab-recipes/tree/master/install/centos --centos安装gitlab
https://github.com/gitlabhq/gitlabhq/blob/master/doc/install/installation.md --ubuntu安装gitlab
http://blog.csdn.net/w13770269691/article/details/38705473 --gitlab的使用
http://www.open-open.com/lib/view/open1397006572653.html --带切换用户的
http://blog.csdn.net/yanjiangbo/article/details/39155547
安装要求:
1、操作系统版本要求在RedHat
6.5以上
2、GitLab版本要求在7.3 - 7.4之间或者7.5以上
3、GitShell版本要求要与GitLab版本匹配(如果GitLab版本在7.3 - 7.4之间,那么GitShell要用v2.0.1,如果如果GitLab版本在7.5以上,那么GitShell要用v2.2.0以上)
具体对应版本到 https://gitlab.com/gitlab-org/gitlab-ce/blob/master/CHANGELOG网址来查。
到 https://gitlab.com/gitlab-org/gitlab-shell/blob/master/CHANGELOG查看gitlab-shell的版本。
4、Web Server是Apache或者Nginx(Nginx一定要安装最新版的,否则可能会出问题)
5、Init system : sysvinit(upstart), 可以用runlevel命令查看
6、数据库: MySQL(5.5.14以上)或者PostgreSQL(9.3以上)
7、redis不能用标准安装,要设置socket在系统路径下
8、Contributors(贡献者): @nielsbasjes, @axilleas, @mairin, @ponsjuh, @yorn, @psftw, @etcet, @mdirkse, @nszceta, @herkalurk
9、附加说明: 为了安装一套能够兼容GitLab的Ruby,需要采用源码方式安装Ruby-2.1.7,Python 2.6.6
10、如果是在VMware的虚拟机上操作,请先安装VMware Tools插件。
[root@testgitlab ~]# wget -O /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 https://www.fedoraproject.org/static/0608B895.txt --no-check-certificate
[root@testgitlab ~]# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
[root@testgitlab ~]# rpm -qa gpg*
gpg-pubkey-0608b895-4bd22942
gpgme-1.1.8-3.el6.x86_64
[root@testgitlab ~]# rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
[root@testgitlab ~]# wget -O /etc/yum.repos.d/PUIAS_6_computational.repo https://gitlab.com/gitlab-org/gitlab-recipes/raw/master/install/centos/PUIAS_6_computational.repo
[root@testgitlab ~]# wget -O /etc/pki/rpm-gpg/RPM-GPG-KEY-puias http://springdale.math.ias.edu/data/puias/6/x86_64/os/RPM-GPG-KEY-puias
[root@testgitlab ~]# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-puias
[root@testgitlab ~]# rpm -qa gpg*
gpg-pubkey-41a40948-4ce19266
gpg-pubkey-0608b895-4bd22942
gpgme-1.1.8-3.el6.x86_64
[root@testgitlab ~]# yum repolist
PUIAS_6_computational | 3.3 kB 00:01
PUIAS_6_computational/primary_db | 2.0 MB 06:49
epel/metalink | 5.9 kB 00:00
epel | 4.3 kB 00:00
epel/primary_db | 5.7 MB 00:22
repo id repo name status
HighAvailability HighAvailability 56
LoadBalancer LoadBalancer 4
PUIAS_6_computational PUIAS computational Base 6Server - x86_64 3,213
ResilientStorage ResilientStorage 62
ScalableFileSystem ScalableFileSystem 7
Server Server 3,690
epel Extra Packages for Enterprise Linux 6 - x86_64 11,887
rhel-dvd Red Hat Enterprise Linux 6Server - $dvd 3,690
repolist: 22,609
[root@testgitlab ~]# yum-config-manager --enable epel --enable PUIAS_6_computational
[root@testgitlab ~]# yum -y update
[root@testgitlab ~]# yum -y groupinstall 'Development Tools'
[root@testgitlab ~]# 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 git cmake libcom_err-devel.i686 libcom_err-devel.x86_64 nodejs
[root@testgitlab ~]# wget ftp://ftp.muug.mb.ca/mirror/centos/6.7/os/x86_64/Packages/libffi-devel-3.0.5-3.2.el6.x86_64.rpm
[root@testgitlab ~]# wget ftp://ftp.icm.edu.pl/vol/rzm5/linux-oracle-repo/OracleLinux/OL6/openstack10/x86_64/getPackage/libyaml-0.1.6-1.el6.x86_64.rpm
[root@testgitlab ~]# wget ftp://ftp.icm.edu.pl/vol/rzm5/linux-oracle-repo/OracleLinux/OL6/openstack10/x86_64/getPackage/libyaml-devel-0.1.6-1.el6.x86_64.rpm
[root@testgitlab ~]# rpm -ivh libffi-devel-3.0.5-3.2.el6.x86_64.rpm
[root@testgitlab ~]# rpm -ivh libyaml-0.1.6-1.el6.x86_64.rpm
[root@testgitlab ~]# rpm -ivh libyaml-devel-0.1.6-1.el6.x86_64.rpm
[root@testgitlab ~]# yum-config-manager --enable rhel-6-server-optional-rpms
[root@testgitlab ~]# yum -y install vim-enhanced
[root@testgitlab ~]# update-alternatives --set editor /usr/bin/vim.basic
[root@testgitlab ~]# wget ftp://rpmfind.net/linux/centos/6.7/os/x86_64/Packages/python-docutils-0.6-1.el6.noarch.rpm
[root@testgitlab ~]# wget ftp://rpmfind.net/linux/centos/6.7/os/x86_64/Packages/python-imaging-1.1.6-19.el6.x86_64.rpm
[root@testgitlab ~]# rpm -ivh python-imaging-1.1.6-19.el6.x86_64.rpm
[root@testgitlab ~]# rpm -ivh python-docutils-0.6-1.el6.noarch.rpm
[root@testgitlab ~]# rm -f *.rpm
[root@testgitlab ~]# yum -y install postfix
[root@testgitlab ~]# git --version
git version 1.8.3.1
[root@testgitlab ~]# yum -y remove git
[root@testgitlab ~]# yum install zlib-devel perl-CPAN gettext curl-devel expat-devel gettext-devel openssl-devel
[root@testgitlab ~]# mkdir /tmp/git && cd /tmp/git
[root@testgitlab git]# curl --progress https://www.kernel.org/pub/software/scm/git/git-2.1.3.tar.gz | tar xz
[root@testgitlab git]# cd git-2.1.3/
[root@testgitlab git-2.1.3]# ./configure
[root@testgitlab git-2.1.3]# make
[root@testgitlab git-2.1.3]# make PREFIX=/usr/local install
[root@testgitlab git-2.1.3]# which git
/usr/local/bin/git
[root@testgitlab git-2.1.3]# yum remove ruby
必须删干净所有的ruby,如果有ruby文件夹,可以做下列两步:
cd <your-ruby-source-path>
make uninstall
下面安装ruby-2.1.7,一定要用源码安装,不能用rvm安装
[root@testgitlab git-2.1.3]# mkdir /tmp/ruby && cd /tmp/ruby
[root@testgitlab ruby]# curl --progress ftp://ftp.ruby-lang.org/pub/ruby/2.1/ruby-2.1.7.tar.gz | tar xz
[root@testgitlab ruby]# cd ruby-2.1.7
[root@testgitlab ruby]# ./configure --disable-install-rdoc
[root@testgitlab ruby-2.1.7]# make
[root@testgitlab ruby-2.1.7]# make PREFIX=/usr/local install
[root@testgitlab ruby-2.1.7]# gem sources -l
*** CURRENT SOURCES ***
https://rubygems.org/
[root@testgitlab ruby-2.1.7]# gem sources --remove https://rubygems.org/
https://rubygems.org/ removed from sources
[root@testgitlab ruby-2.1.7]# gem sources --add https://ruby.taobao.org/
https://ruby.taobao.org/ added to sources
[root@testgitlab ruby-2.1.7]# gem sources -l
*** CURRENT SOURCES ***
https://ruby.taobao.org/
[root@testgitlab ruby-2.1.7]# gem install bundler --no-doc
Fetching: bundler-1.11.2.gem (100%)
Successfully installed bundler-1.11.2
1 gem installed
[root@testgitlab ruby-2.1.7]# which ruby
/usr/local/bin/ruby
[root@testgitlab ruby-2.1.7]# ruby -v
ruby 2.1.7p400 (2015-08-18 revision 51632) [x86_64-linux]
[root@testgitlab ruby-2.1.7]# adduser --system --shell /bin/bash --comment 'GitLab' --create-home --home-dir /home/git/ git
[root@testgitlab ruby-2.1.7]# cd
[root@testgitlab ~]# visudo
在visudo文件中找到Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin这一句,在后面加上/usr/local/bin,加完后的结果如下:
Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
[root@testgitlab ~]# yum remove postgresql
[root@testgitlab ~]# wget http://yum.postgresql.org/9.3/redhat/rhel-6-x86_64/pgdg-redhat93-9.3-1.noarch.rpm
[root@testgitlab ~]# rpm -ivh pgdg-redhat93-9.3-1.noarch.rpm
[root@testgitlab ~]# yum install postgresql93-server postgresql93-contrib postgresql93-devel
[root@testgitlab ~]# service postgresql-9.3 initdb
Initializing database: [ OK ]
[root@testgitlab ~]# service postgresql-9.3 start
Starting postgresql-9.3 service: [ OK ]
[root@testgitlab ~]# chkconfig postgresql-9.3 on
[root@testgitlab ~]# su - postgres
-bash-4.1$ export PATH=$PATH:/usr/pgsql-9.3/bin/
-bash-4.1$ psql -d template1
psql (9.3.10)
Type "help" for help.
template1=# CREATE USER git CREATEDB;
CREATE ROLE
template1=# CREATE DATABASE gitlabhq_production OWNER git;
CREATE DATABASE
template1=# \q
-bash-4.1$ su -
Password:
[root@testgitlab ~]# whoami
root
[root@testgitlab ~]# sudo -u git psql -d gitlabhq_production
could not change directory to "/root": Permission denied
psql (9.3.10)
Type "help" for help.
gitlabhq_production=> \q
[root@testgitlab ~]# cd /var/lib/pgsql/9.3/data
[root@testagent data]# vi pg_hba.conf
加入host replication postgres 127.0.0.1/32 trust一行
退出并保存。
配置redis服务步骤如下:
[root@testgitlab data]# cd
启动redis服务:
[root@testgitlab ~]# service redis start
Starting redis-server: [ OK ]
确认redis已经在boot下启动:
[root@testgitlab ~]# service redis status
redis-server (pid 37166) is running...
[root@testgitlab ~]# ps -ef|grep redis
redis 37166 1 0 18:05 ? 00:00:00 /usr/sbin/redis-server /etc/redis.conf
root 37184 37072 0 18:07 pts/0 00:00:00 grep redis
确认redis服务是开机启动的:
[root@testgitlab ~]# chkconfig redis on
配置redis使用sockets通信:
[root@testgitlab ~]# cp /etc/redis.conf /etc/redis.conf.orig
禁用redis的监听端口:
[root@testgitlab ~]# sed 's/^port .*/port 0/' /etc/redis.conf.orig | sudo tee /etc/redis.conf
在CentOS系统路径下启用redis的socket通信:
[root@testgitlab ~]# echo 'unixsocket /var/run/redis/redis.sock' | sudo tee -a /etc/redis.conf
unixsocket /var/run/redis/redis.sock
[root@testgitlab ~]# echo -e 'unixsocketperm 0770' | sudo tee -a /etc/redis.conf
unixsocketperm 0770
创建包含redis的socket通信的文件夹并设置redis用户权限:
[root@testgitlab ~]# mkdir /var/run/redis
[root@testgitlab ~]# chown redis:redis /var/run/redis
[root@testgitlab ~]# chmod 755 /var/run/redis
如果适用的话,把套接字持久在目录中:
[root@testgitlab ~]#
if [ -d /etc/tmpfiles.d ]; then
echo 'd /var/run/redis 0755 redis redis 10d -' | sudo tee -a /etc/tmpfiles.d/redis.conf
fi
[root@testgitlab ~]#
重新启动redis服务以使修改过的redis.conf文件生效:
[root@testgitlab ~]# service redis restart
Stopping redis-server: [ OK ]
Starting redis-server: [ OK ]
把git用户加入到redis组:
[root@testgitlab ~]# usermod -aG redis git
把GitLab安装到home目录下的git用户文件夹下:
[root@testgitlab ~]# cd /home/git
克隆一个GitLab库:
[root@testgitlab git]# sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 7-5-stable gitlab
Cloning into 'gitlab'...
remote: Counting objects: 208364, done.
remote: Compressing objects: 100% (46302/46302), done.
remote: Total 208364 (delta 162153), reused 204676 (delta 159234)
Receiving objects: 100% (208364/208364), 106.04 MiB | 1.88 MiB/s, done.
Resolving deltas: 100% (162153/162153), done.
Checking connectivity... done.
进入安装了gitlab的文件夹:
[root@testgitlab git]# cd /home/git/gitlab
[root@testgitlab gitlab]# sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml
[root@testgitlab gitlab]# su - git
[git@testgitlab ~]$ cd gitlab
[git@testgitlab gitlab]$ vi config/
gitlab.yml
这里需要进行如下4行的修改:
host:localhost ==> host: 192.168.1.89
port: 80 ==> port: 8080
email_from:
[email protected] ==> email_from:
[email protected]
email_reply_to:
[email protected] ==> email_reply_to:
[email protected]
timeout: 30 ==> timeout: 600
bin_path: /usr/bin/git ==> bin_path: /usr/local/bin/git
保存并退出。
-------------------------------------------------------------网上用sed命令修改config/gitlab.yml文件的方法---------------------------------------------------
# 修改配置文件中的访问域名
(your_domain_name为项目的访问域名)
$ sed -i 's|localhost|your_domain_name|g' config/gitlab.yml
-------------------------------------------------------------网上用sed命令修改config/gitlab.yml文件的方法---------------------------------------------------
[git@testgitlab gitlab]$ su -
Password:
[root@testgitlab ~]# cd /home/git/gitlab/
[root@testgitlab gitlab]# chown -R git log/
[root@testgitlab gitlab]# chown -R git tmp/
[root@testgitlab gitlab]# chmod -R u+rwX log/
[root@testgitlab gitlab]# chmod -R u+rwX tmp/
创建一个satellites文件夹:
[root@testgitlab gitlab]# sudo -u git -H mkdir /home/git/gitlab-satellites
[root@testgitlab gitlab]# chmod u+rwx,g=rx,o-rwx /home/git/gitlab-satellites
[root@testgitlab gitlab]# chmod -R u+rwX tmp/pids/
[root@testgitlab gitlab]# chmod -R u+rwX tmp/sockets/
[root@testgitlab gitlab]# chmod -R u+rwX public/uploads
[root@testgitlab gitlab]# sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb
[root@testgitlab gitlab]# su - git
[git@testgitlab ~]$ cd gitlab
[git@testgitlab gitlab]$ vi config/
unicorn.rb
listen "127.0.0.1:8080", :tcp_nopush => true 改成 listen "192.168.1.89:8080", :tcp_nopush => true
[git@testgitlab gitlab]$ su -
Password:
[root@testgitlab ~]# cd /home/git/gitlab
[root@testgitlab gitlab]# sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb
[root@testgitlab gitlab]# su - git
[git@testgitlab ~]$ cd gitlab
[git@testgitlab gitlab]$ vi config/initializers/rack_attack.rb
这里用默认配置,什么也没改
[git@testgitlab gitlab]$ su -
Password:
[root@testgitlab ~]# cd /home/git/gitlab
[root@testgitlab gitlab]# sudo -u git -H git config --global user.name "GitLab"
[root@testgitlab gitlab]# git config --global user.email "
[email protected]"
[root@testgitlab gitlab]# sudo -u git -H git config --global core.autocrlf input
[root@testgitlab gitlab]# sudo -u git -H cp config/resque.yml.example config/resque.yml
如果你不使用默认的CentOS配置改变Redis服务器的路径
[root@testgitlab gitlab]# su - git
[git@testgitlab ~]$ cd gitlab
[git@testgitlab gitlab]$ vi config/resque.yml
这里用默认配置,什么也没改
【注】: 确保修改过的gitlab.yml和unicorn.rb两个文件与实际机器的安装情况相匹配。
给GitLab配置使用的数据库:
[root@testgitlab gitlab]# sudo -u git cp config/database.yml.postgresql config/database.yml
[root@testgitlab gitlab]# su - git
[git@testgitlab ~]$ cd gitlab
[git@testgitlab gitlab]$ vi config/
database.yml
这里只修改了postgresql数据库的encoding属性值为utf8。
[git@testgitlab gitlab]$ su -
Password:
[root@testgitlab ~]# cd /home/git/gitlab
[root@testgitlab gitlab]# sudo -u git -H chmod o-rwx config/database.yml
安装Gems:
[root@testgitlab gitlab]# cd /home/git/gitlab
[root@testgitlab gitlab]# sudo -u git -H bundle config build.pg --with-pg-config=/usr/pgsql-9.3/bin/pg_config
[root@testgitlab gitlab]# vi Gemfile
把第一行的source "https://rubygems.org"换成source "https://ruby.taobao.org/"
保存并退出。
源码安装icu4c或者安装libicu-devel的rpm包:
[root@testgitlab gitlab]# wget ftp://195.220.108.108/linux/centos/6.7/os/x86_64/Packages/libicu-devel-4.2.1-12.el6.x86_64.rpm
[root@testgitlab gitlab]# rpm -ivh libicu-devel-4.2.1-12.el6.x86_64.rpm --force --nodeps
[root@testgitlab gitlab]# rm -f libicu-devel-4.2.1-12.el6.x86_64.rpm
[root@testgitlab gitlab]# gem install charlock_holmes -v '0.6.9.4'
Fetching: charlock_holmes-0.6.9.4.gem (100%)
Building native extensions. This could take a while...
Successfully installed charlock_holmes-0.6.9.4
Parsing documentation for charlock_holmes-0.6.9.4
Installing ri documentation for charlock_holmes-0.6.9.4
Done installing documentation for charlock_holmes after 1 seconds
1 gem installed
--------------------------------------------------------------------安装rugged 0.23.3------------------------------------------------------------------------------
[root@testgitlab gitlab]# gem install rugged -v '0.23.3' --在gitlab8.4版本中这句出错,这句在gitlab7.5版本中不要执行,要安装更高版本的ruby才能安装rugged 0.23.3
--------------------------------------------------------------------安装rugged 0.23.3------------------------------------------------------------------------------
[root@testgitlab gitlab]# sudo -u git -H bundle install --deployment --without development test mysql aws
......
Installing rugged 0.21.2 with native extensions --在这个过程中安装了rugged 0.21.2
......
安装GitLab shell:
[root@testgitlab gitlab]# sudo -u git -H bundle exec rake gitlab:shell:install[v2.4.3] REDIS_URL=unix:/var/run/redis/redis.sock RAILS_ENV=production
git clone 'https://gitlab.com/gitlab-org/gitlab-shell.git' '/home/git/gitlab-shell/'
Cloning into '/home/git/gitlab-shell'...
remote: Counting objects: 2378, done.
remote: Compressing objects: 100% (838/838), done.
remote: Total 2378 (delta 1481), reused 2328 (delta 1454)
Receiving objects: 100% (2378/2378), 340.09 KiB | 197.00 KiB/s, done.
Resolving deltas: 100% (1481/1481), done.
Checking connectivity... done.
git reset --hard $(git describe v2.1.0 || git describe origin/v2.1.0) || git fetch origin && git reset --hard $(git describe v2.1.0 || git describe origin/v2.1.0)
HEAD is now at 823aba6 Merge branch 'master' of github.com:gitlabhq/gitlab-shell
HEAD is now at 823aba6 Merge branch 'master' of github.com:gitlabhq/gitlab-shell
bin/install
mkdir -p /home/git/repositories/: OK
mkdir -p /home/git/.ssh: OK
chmod 700 /home/git/.ssh: OK
touch /home/git/.ssh/authorized_keys: OK
chmod 600 /home/git/.ssh/authorized_keys: OK
chmod -R ug+rwX,o-rwx /home/git/repositories/: OK
find /home/git/repositories/ -type d -exec chmod g+s {} ;: OK
[root@testgitlab gitlab]# su - git
[git@testgitlab ~]$ pwd
/home/git/
[git@testgitlab ~]$ vi gitlab-shell/
config.yml
gitlab_url: http://192.168.1.89/ ===> gitlab_url: http://192.168.1.89:8080/
[git@testgitlab ~]$ restorecon -Rv /home/git/.ssh
restorecon reset /home/git/.ssh context unconfined_u:object_r:default_t:s0->unconfined_u:object_r:ssh_home_t:s0
restorecon reset /home/git/.ssh/environment context unconfined_u:object_r:default_t:s0->unconfined_u:object_r:ssh_home_t:s0
restorecon reset /home/git/.ssh/authorized_keys context unconfined_u:object_r:default_t:s0->unconfined_u:object_r:ssh_home_t:s0
[git@testgitlab ~]$ su -
Password:
[root@testgitlab ~]# cd /home/git/gitlab
初始化gitlab的数据库并且激活高级功能:
[root@testgitlab gitlab]# sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production
......
Administrator account created:
login.........root
password......5iveL!fe
这步做完后会发现管理员权限的登录名和密码:root/5iveL!fe
可以用sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production GITLAB_ROOT_PASSWORD=newpassword来修改密码。
例如:
[root@testgitlab gitlab]# sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production GITLAB_ROOT_PASSWORD=newpassword
安装初始化脚本:
下载初始化脚本,这个脚本将被下载到/etc/init.d/gitlab目录下:
[root@testgitlab gitlab]# wget -O /etc/init.d/gitlab https://gitlab.com/gitlab-org/gitlab-recipes/raw/master/init/sysvinit/centos/gitlab-unicorn
[root@testgitlab gitlab]# chmod +x /etc/init.d/gitlab
[root@testgitlab gitlab]# chkconfig --add gitlab
使GitLab在boot下启动:
[root@testgitlab gitlab]# chkconfig gitlab on
安装logrotate:
[root@testgitlab gitlab]# cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab
检查GitLab的环境是否配置正确了:
[root@testgitlab gitlab]# sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production
System information
System: RedHatEnterpriseServer 6.5
Current User: git
Using RVM: no
Ruby Version:
2.1.7p400
Gem Version:
2.2.5
Bundler Version:
1.11.2
Rake Version:
10.3.2
Sidekiq Version:
2.17.0
GitLab information
Version:
7.5.3
Revision: b656b85
Directory: /home/git/gitlab
DB Adapter: postgresql
URL: http://192.168.1.89:8080
HTTP Clone URL: http://192.168.1.89:8080/some-project.git
SSH Clone URL:
[email protected]:some-project.git
Using LDAP: no
Using Omniauth: no
GitLab Shell
Version:
2.4.3
Repositories: /home/git/repositories/
Hooks: /home/git/gitlab-shell/hooks/
Git: /usr/local/bin/git
编译资产(Compile assets):
[root@testgitlab gitlab]# sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production
启动GitLab实例:
[root@testgitlab gitlab]# service gitlab start
Starting unicorn: [ OK ]
Starting sidekiq: [ OK ]
配置web server:
[root@testgitlab gitlab]# yum update
[root@testgitlab gitlab]# cd /etc/yum.repos.d/
[root@testgitlab yum.repos.d]# vi nginx.repo
[nginx]
name=nginx repo
#baseurl=http://nginx.org/packages/rhel/$releasever/$basearch/
baseurl=http://nginx.org/packages/rhel/6/x86_64/
gpgcheck=0
enabled=1
[root@testgitlab yum.repos.d]# cd /home/git/gitlab
[root@testgitlab gitlab]# yum -y install nginx
[root@testgitlab gitlab]# chkconfig nginx on
[root@testgitlab gitlab]# wget -O /etc/nginx/conf.d/gitlab.conf https://gitlab.com/gitlab-org/gitlab-ce/raw/master/lib/support/nginx/gitlab-ssl
[root@testgitlab gitlab]# vi /etc/nginx/conf.d/gitlab.conf
将配置中server_name替换成实际访问的域名,一共有2个地方
例如: server_name YOUR_SERVER_FQDN; ==> server_name gitlab.shihuan.com;
listen 0.0.0.0:80; ==> listen 0.0.0.0:8081;
listen [::]:80 ipv6only=on default_server; ==> listen [::]:8081 ipv6only=on default_server;
proxy_pass http://gitlab-workhorse; ==> proxy_pass http://192.168.1.89:8080;
保存并退出。
将nginx加入git用户组:
[root@testgitlab gitlab]# usermod -a -G git nginx
[root@testgitlab gitlab]# chmod g+rx /home/git/
添加ssl证书或者自己生成一个:
[root@testgitlab gitlab]# mkdir /etc/nginx/ssl
[root@testgitlab gitlab]# cd /etc/nginx/ssl
[root@testgitlab ssl]# openssl req -new -x509 -nodes -days 3560 -out gitlab.crt -keyout gitlab.key
Generating a 2048 bit RSA private key
....................................................................................................................+++
.+++
writing new private key to 'gitlab.key'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:CN
State or Province Name (full name) []:shanghai
Locality Name (eg, city) [Default City]:pudong
Organization Name (eg, company) [Default Company Ltd]:shihuan
Organizational Unit Name (eg, section) []:technology
Common Name (eg, your name or your server's hostname) []:testgitlab
Email Address []:
[email protected]
[root@testgitlab ssl]# cd /home/git/gitlab
[root@testgitlab gitlab]# nginx -V
nginx version: nginx/1.8.0
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-3) (GCC)
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_random_index_module --with-http_secure_link_module --with-http_stub_status_module --with-http_auth_request_module --with-mail --with-mail_ssl_module --with-file-aio --with-ipv6 --with-http_spdy_module --with-cc-opt='-O2 -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic'
[root@testgitlab gitlab]# which nginx
/usr/sbin/nginx
启动nginx:
[root@testgitlab gitlab]# service nginx start
Starting nginx: [ OK ]
用如下命令校验gitlab或者gitlab-ssl在nginx中的配置:
[root@testgitlab gitlab]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
配置系统防火墙:
配置iptables,使用户可以访问http、https和ssh的端口:
[root@testgitlab gitlab]# lokkit -s http -s https -s ssh
重新启动防火墙:
[root@testgitlab gitlab]# service iptables restart
iptables: Setting chains to policy ACCEPT: filter [ OK ]
iptables: Flushing firewall rules: [ OK ]
iptables: Unloading modules: [ OK ]
iptables: Applying firewall rules: [ OK ]
到此为止所有操作完毕。
默认的账号密码:root/5iveL!fe
[root@testgitlab gitlab]# cd /home/git/gitlab-shell
[root@testgitlab gitlab-shell]# vi Gemfile
替换source "http://rubygems.org" ===> source "https://ruby.taobao.org/"
---------------------这几句是为执行sudo -u git bundle install时跳过密码准备的,在加了--path vendor/bundle参数的命令后不需要执行者几句了------------------------
[root@testgitlab gitlab-shell]# gem env
RubyGems Environment:
- RUBYGEMS VERSION: 2.2.5
- RUBY VERSION: 2.1.7 (2015-08-18 patchlevel 400) [x86_64-linux]
- INSTALLATION DIRECTORY: /usr/local/lib/ruby/gems/2.1.0
- RUBY EXECUTABLE: /usr/local/bin/ruby
- EXECUTABLE DIRECTORY: /usr/local/bin
- SPEC CACHE DIRECTORY: /root/.gem/specs
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-linux
- GEM PATHS:
- /usr/local/lib/ruby/gems/2.1.0
- /root/.gem/ruby/2.1.0
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- :sources => ["https://ruby.taobao.org/"]
- REMOTE SOURCES:
- https://ruby.taobao.org/
- SHELL PATH:
- /usr/lib64/qt-3.3/bin
- /usr/local/sbin
- /usr/local/bin
- /sbin
- /bin
- /usr/sbin
- /usr/bin
- /root/bin
[root@testgitlab gitlab-shell]# su - git
[git@testgitlab ~]$ vi .bash_profile
加入如下几句:
export GEM_HOME=/usr/local/lib/ruby/gems/2.1.0
PATH=$PATH:$HOME/bin
PATH=$PATH:$HOME/bin:$GEM_HOME:/root/.gem/ruby/2.1.0
export PATH
[git@testgitlab ~]$ su -
Password:
[root@testgitlab ~]# gem install rubygems-update
Fetching: rubygems-update-2.5.1.gem (100%)
Successfully installed rubygems-update-2.5.1
Parsing documentation for rubygems-update-2.5.1
Installing ri documentation for rubygems-update-2.5.1
Done installing documentation for rubygems-update after 13 seconds
1 gem installed
---------------------这几句是为执行sudo -u git bundle install时跳过密码准备的,在加了--path vendor/bundle参数的命令后不需要执行者几句了------------------------
[root@testgitlab ~]# cd /home/git/gitlab-shell
[root@testgitlab gitlab-shell]# sudo -u git bundle install --path vendor/bundle
Double-check Application Status:
[root@testgitlab gitlab]# cd /home/git/gitlab
[git@testgitlab gitlab]$ ps -ef|grep gitlab
git 72128 1 21 16:10 ? 00:00:10 unicorn_rails master -D -c /home/git/gitlab/config/unicorn.rb -E production
git 72136 72128 0 16:11 ? 00:00:00 unicorn_rails worker[0] -D -c /home/git/gitlab/config/unicorn.rb -E production
git 72139 72128 0 16:11 ? 00:00:00 unicorn_rails worker[1] -D -c /home/git/gitlab/config/unicorn.rb -E production
git 72158 1 27 16:11 ? 00:00:09 sidekiq 2.17.0 gitlab [0 of 25 busy]
postgres 72195 2327 0 16:11 ? 00:00:00 postgres: git gitlabhq_production [local] idle
git 72229 71922 0 16:11 pts/0 00:00:00 grep gitlab
[git@testgitlab gitlab]$ bundle exec rake gitlab:check RAILS_ENV=production
或者
[root@testgitlab gitlab]# sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production
Checking Environment ...
Git configured for git user? ... no
Try fixing it:
sudo -u git -H "/usr/local/bin/git" config --global user.name "GitLab"
sudo -u git -H "/usr/local/bin/git" config --global user.email "
[email protected]"
sudo -u git -H "/usr/local/bin/git" config --global core.autocrlf "input"
For more information see:
doc/install/installation.md in section "GitLab"
Please fix the error above and rerun the checks.
Checking Environment ... Finished
Checking GitLab Shell ...
GitLab Shell version >= 2.2.0 ? ... OK (
2.4.3)
Repo base directory exists? ... yes
Repo base directory is a symlink? ... no
Repo base owned by git:git? ... yes
Repo base access is drwxrws---? ... yes
Satellites access is drwxr-x---? ... yes
hooks directories in repos are links: ... can't check, you have no projects
Running /home/git/gitlab-shell/bin/check
Check GitLab API access: OK
Check directories and files:
/home/git/repositories/: OK
/home/git/.ssh/authorized_keys: OK
Test redis-cli executable: redis-cli
2.4.10
Send ping to redis server: PONG
gitlab-shell self-check successful
Checking GitLab Shell ... Finished
Checking Sidekiq ...
Running? ... yes
Number of Sidekiq processes ... 1
Checking Sidekiq ... Finished
Checking LDAP ...
LDAP is disabled in config/gitlab.yml
Checking LDAP ... Finished
Checking GitLab ...
Database config exists? ... yes
Database is SQLite ... no
All migrations up? ... yes
Database contains orphaned GroupMembers? ... no
GitLab config exists? ... yes
GitLab config outdated? ... no
Log directory writable? ... yes
Tmp directory writable? ... yes
Init script exists? ... yes
Init script up-to-date? ... no
Try fixing it:
Redownload the init script
For more information see:
doc/install/installation.md in section "Install Init Script"
Please fix the error above and rerun the checks.
projects have namespace: ... can't check, you have no projects
Projects have satellites? ... can't check, you have no projects
Redis version >= 2.0.0? ... yes
Ruby version >= 2.0.0 ? ... yes (
2.1.7)
Your git bin path is "/usr/local/bin/git"
Git version >= 1.7.10 ? ... yes (
2.1.3)
Checking GitLab ...
Finished
打开浏览器访问: http://192.168.1.89:8080/
【注】: 如果公司有外网域名,那么这里可以换成 http://gitlab.shihuan.com
默认的账号密码:root/5iveL!fe
第一次登陆后要求设置新密码,笔者这里设置为: ShiHuan123456