http://www.iyunv.com/thread-97282-1-1.html
cat /etc/issue
CentOS release 6.6 (Final)Kernel \r on an \m
epel el6 64 位源
rpm –ivh http://dl.fedoraproject.org/pub/ ... ease-6-8.noarch.rpm
1、初始化安装环境
yum -y groupinstall 'Development Tools'
yum -y install readline readline-devel ncurses-devel gdbm-devel glibc-develtcl-devel openssl-devel curl-devel expat-devel db4-devel byaccsqlite-devel libyaml libyaml-devel libffi libffi-devel libxml2libxml2-devel libxslt libxslt-devel libicu libicu-develsystem-config-firewall-tui crontabs logwatch logrotateperl-Time-HiRes cmakelibcom_err-devel.i686 libcom_err-devel.x86_64 zlib-devel perl-CPANgettext gettext-devel perl-ExtUtils-MakeMaker
2、安装GIT
确保git版本至少在1.7.10或以上,如果不是,卸载重装
yum -y remove git
mkdir /tools/git -p && cd /tools/git
curl --progress https://www.kernel.org/pub/software/scm/git/git-2.1.3.tar.gz | tar xz
cd git-2.1.3/
./configure
make
make prefix=/usr/local install
创建软连接
ln -s /usr/local/bin/git /usr/bin/git
git --version
3、安装ruby
注意:请不要用rvm安装ruby,否则,后续会出现一些难以解决的问题
Gitlab7.x需要ruby2.x
如果系统自带的ruby版本低于2.x,就需要升级ruby
yum remove ruby
或者
cd <your-ruby-source-path>
make uninstall
mkdir /tools/ruby && cd /tools/ruby
curl --progress ftp://ftp.ruby-lang.org/pub/ruby/2.1/ruby-2.1.5.tar.gz | tar xz
cd ruby-2.1.5
./configure --disable-install-rdoc
make
make prefix=/usr/local install
安装bundler
gem source -r https://rubygems.org /
gem source -a http://ruby.taobao.org /
gem install bundler --no-doc
4、添加git账户
useradd -c 'GitLab' git
执行命令:visudo
把/usr/local/bin加入到secure_path里面去
然后,配置git用户可以使用sudo
git ALL=(ALL) ALL
5、安装mysql
yum install mysql mysql-devel mysql-server -y
/etc/init.d/mysqld start
mysql_secure_installation
创建gitlab 数据库用户
CREATE USER 'gitlab'@'localhost' IDENTIFIED BY 'gitlab';
CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'localhost';
\q
6、安装redis
mkdir /tools/redis && cd /tools/redis
wget http://download.redis.io/releases/redis-3.0.3.tar.gz
tar xzf redis-3.0.3.tar.gz
cd redis-3.0.3
make
mkdir -p /usr/local/redis-3.0.3/etc
mkdir /usr/local/redis-3.0.3/start_script
/bin/cp -r src /usr/local/redis-3.0.3/
vim /usr/local/redis-3.0.3/etc/redis.conf
daemonize yes
pidfile /data/redisdata/redis6379.pid
port 6379
timeout 300
logfile /data/redisdata/redis6379.log
databases 16
#save 300 1
#save 150 10
#save 60 10000
maxmemory 20480000000
rdbcompression yes
dbfilename redis6379.rdb
dir /data/redisdata/
slave-serve-stale-data yes
appendonly no
appendfsync no
no-appendfsync-on-rewrite no
slowlog-log-slower-than 10000
slowlog-max-len 1024
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-entries 512
list-max-ziplist-value 64
set-max-intset-entries 512
activerehashing yes
#requirepass admin
bind 0.0.0.0
mkdir /data/redisdata/
ln -s /usr/local/redis-3.0.3/src/redis-* /bin/
cd /usr/local/redis-3.0.3/start_script/
chmod 744 /usr/local/redis-3.0.3/start_script/redis.sh
echo "/usr/local/redis-3.0.3/start_script/redis.sh start" >> /etc/rc.local
7、安装gitlab(使用git用户)
1)
注意,这里必须用git clone下载(在git用户家目录下执行),不要下载网上已经打包好的tar.gz文件,否则以后不能升级
git clone https://gitlab.com/gitlab-org/gitlab-ce.git gitlab
cd /home/git/gitlab (注意目录位置,尽量使用默认的)
然后,切换到需要安装的版本上
这里安装的是v7.9.2
git checkout v7.9.2(注意这里是tag)
git checkout -b v7.9.2
2)复制配置文件
cp config/gitlab.yml.example config/gitlab.yml
修改host 为当前机器的ip地址
sed -i 's|localhost|10.1.7.201|g' config/gitlab.yml
cp config/unicorn.rb.example config/unicorn.rb
3) 授权目录
chmod -R u+rwX public/uploads
chown -R git log tmp/
chmod -R u+rwx log/ tmp/
mkdir /home/git/gitlab-satellites
chmod u+rwx,g=rx,o-rwx /home/git/gitlab-satellites
mkdir tmp/backups
配置数据库访问文件
cp config/database.yml.mysql config/database.yml
编辑config/database.yml,设置其中连接数据库的账号密码
username: gitlab
password: "gitlab"
chmod o-rwx config/database.yml
4)配置git的用户和邮件
git config --global user.name "GitLab"
git config --global user.email " gitlab@test.com "
git config --global core.autocrlf input
5)修改Gemfile
vim Gemfile
修改source为 http://ruby.taobao.org
sed -i s# https://rubygems.org # http://ruby.taobao.org #g Gemfile
安装node.js
8、bundle install
bundle install --no-deployment --without development test postgres aws
中途如果不出意外的话,就安装完成(install中途可能要提示输入密码)
如果提示下面的错误:
--------------------------------------------------------------------------------------------
An error occurred while installing charlock_holmes (0.6.9.4), and Bundler cannot continue.
Make sure that `gem install charlock_holmes -v '0.6.9.4'` succeeds before bundling.
gem install charlock_holmes -v '0.6.9.4'
ERROR: Could not find a valid gem 'charlock_holmes' (= 0.6.9.4), here is why:
Unable to download data from https://rubygems.org / - Errno::ECONNRESET: Connection reset by peer - SSL_connect ( https://api.rubygems.org/quick/Marshal.4.8 /charlock_holmes-0.6.9.4.gemspec.rz)
ERROR: Possible alternatives: charlock_holmes
yum install libicu-devel
--------------------------------------------------------------------------------------------
An error occurred while installing rugged (0.21.4), and Bundler cannot continue.
Make sure that `gem install rugged -v '0.21.4'` succeeds before bundling.
sudo yum -y install cmake
sudo gem install rugged -v '0.21.4'
类似这样的,需要手动安装的gem ,手动安装,然后继续执行上面的bundle install
9、安装GitLab-shell
su - git && cd /home/git
git clone https://github.com/gitlabhq/gitlab-shell.git
cd gitlab-shell/
通过 git tag 查看最新版本并切换之
git tag
git checkout -b v2.6.3
修改配置文件
cp config.yml.example config.yml
vi config.yml
gitlab_url: " http://git.test.com /"
注意:如果gitlab是使用https访问,则需将http替换成https,配置文件中的self_signed_cert要修改成true,否则gitlab shell在通过api和gitlab进行通信的时候就会出现错误,导致项目push出错。因为后面配置web服务器的时候是使用ssl,所以这里要按照ssl的方式配置。
Tips: 另外如果使用的域名是测试域名,不要忘记在系统的/etc/hosts做域名映射。
安装
./bin/install
10、初始化数据库
bundle exec rake gitlab:setup RAILS_ENV=production
成功的话,会输出
Administrator account created:
login.........root
password......5iveL!fe
记住这里的用户名和密码
--------------------------------------------------------------------------------------------
如果提示下面的错误:
rake aborted!
ExecJS::RuntimeUnavailable: Could not find a JavaScript runtime. See https://github.com/sstephenson/execjs for a list of available runtimes.
/home/git/gitlab/config/application.rb:6:in `<top (required)>'
/home/git/gitlab/Rakefile:5:in `require'
/home/git/gitlab/Rakefile:5:in `<top (required)>'
(See full trace by running task with --trace)
sudo yum install nodejs -y
11、检查GitLab及其环境的配置是否正确
git@KVM-7-201 ~/gitlab $ bundle exec rake gitlab:env:info RAILS_ENV=production
System information
System:
Current User: git
Using RVM: no
Ruby Version: 2.1.5p273
Gem Version: 2.2.2
Bundler Version:1.10.6
Rake Version: 10.4.2
Sidekiq Version:3.3.0
GitLab information
Version: 7.9.2
Revision: c46d4f5
Directory: /home/git/gitlab
DB Adapter: mysql2
URL: http://10.1.7.201
HTTP Clone URL: http://10.1.7.201/some-project.git
SSH Clone URL: git@10.1.7.201 :some-project.git
Using LDAP: no
Using Omniauth: no
GitLab Shell
Version: 2.6.3
Repositories: /home/git/repositories/
Hooks: /home/git/gitlab-shell/hooks/
Git: /usr/bin/git
12、下载启动脚本
sudo wget https://raw.github.com/gitlabhq/gitlab-recipes/master/init/sysvinit/centos/gitlab-unicorn -P /etc/init.d/
sudo mv /etc/init.d/gitlab-unicorn /etc/init.d/gitlab
sudo chmod +x /etc/init.d/gitlab
sudo chkconfig --add gitlab
sudo chkconfig gitlab on
sudo /etc/init.d/gitlab start
13、复制配置文件[使用nginx做为WEB服务]
cat /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo
baseurl= http://nginx.org/packages/centos /$releasever/$basearch/
gpgcheck=0
enabled=1
sudo yum -y install nginx
sudo cp lib/support/nginx/gitlab /etc/nginx/conf.d/
cd /etc/nginx/conf.d/
sudo chown -R git:git .
cp gitlab gitlab.conf
vi gitlab.conf
upstream gitlab {
server unix:/home/git/gitlab/tmp/sockets/gitlab.socket;
}
server {
listen *:80 default_server; # e.g., listen 192.168.1.1:80; In most cases *:80 is a good idea
server_name gitlab.test.com; # e.g., server_name source.example.com;
server_tokens off; # don't show the version number, a security best practice
root /home/git/gitlab/public;
client_max_body_size 5m;
access_log logs/gitlab_access.log;
error_log logs/gitlab_error.log;
location / {
try_files $uri $uri/index.html $uri.html @gitlab;
}
location @gitlab {
proxy_read_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694
proxy_connect_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694
proxy_redirect off;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://gitlab;
}
}
sudo service nginx restart
14、拉取GitLab静态文件
cd /home/git/gitlab
bundle exec rake assets:precompile RAILS_ENV=production
sudo service gitlab restart
15、访问测试
初始管理员帐号和密码为:
root
5iveL!fe
1)访问gitlab.test.com 如果配置正常会显示如下页面:
![](http://www.iyunv.com/data/attachment/forum/201508/11/092132u8qp89jlppq9p2aj.jpg)
第一次访问需要修改默认密码
![](http://www.iyunv.com/data/attachment/forum/201508/11/092132xwrn92ej2n301n9v.jpg)
登录成功会显示
![](http://www.iyunv.com/data/attachment/forum/201508/11/092133ezjk5jsr8e8djp5g.jpg)
2) 访问如果出现502
![](http://www.iyunv.com/data/attachment/forum/201508/11/092134r1ezfpw2jcw2llp0.jpg)
查看nginx日志,报权限错误
tail /var/log/nginx/gitlab_error.log
2015/08/07 19:50:31 [crit] 4190#0: *24 connect() to unix:/home/git/gitlab/tmp/sockets/gitlab.socket failed (13: Permission denied) while connecting to upstream, client: 10.190.0.6, server: gitlab.test.com, request: "GET /favicon.ico HTTP/1.1", upstream: " http://unix:/home/git/gitlab/tmp/sockets/gitlab.socket:/502.html ", host: "gitlab.test.com"
解决方案:
chmod 775 /home/git