gitlab部署
一、配置epel源1
2
wget http://mirrors.aliyun.com/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm-ivhepel-release-6-8.noarch.rpm
二、安装依赖包
1
yum -y install libicu-devel patch gcc-c++ readline-devel zlib-devel libffi-devel openssl-devel make cmake autoconf automake libtool bison libxml2-devel libxslt-devel libyaml-devel zlib-devel openssl-devel cpio expat-devel gettext-devel curl-devel perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker
三、安装git下载链接:
1
wget -O git-src.zip https://github.com/git/git/archive/master.zip
1
2
3
4
5
# unzip git-src.zip
# cd git-master/
# make prefix=/usr/local all
# make prefix=/usr/local install
# ln -fs /usr/local/bin/git* /usr/bin/
四、安装ruby
1
2
3
4
5
6
7
8
# wget ftp://ftp.ruby-lang.org/pub/ruby/ruby-2.1.5.tar.gz
# tar-zxf ruby-2.1.5.tar.gz
# cd ruby-2.1.5
# ./configure --disable-install-rdoc && make && make install
# ln -s /usr/local/bin/ruby /usr/bin/ruby
# ln -s /usr/local/bin/gem /usr/bin/gem
# gem install bundler --no-ri --no-rdoc
# ln -s /usr/local/bin/bundle /usr/bin/bundle
五、安装mysql并初始化gitlab库
1
2
3
4
5
6
# yum -y install mysql mysql-devel mysql-server
# service mysqld start
# chkconfig mysqld on
# mysql
mysql> create database gitlab;
mysql> grant all privileges on gitlab.* to 'gitlab'@'localhost' identified by 'gitlab';
测试是否可以用gitlab登录数据库:
1
2
# mysql -u gitlab -p -D gitlab
Enter password:
六、安装redis
1
2
3
4
5
6
# yum -y install redis
# vi /etc/redis.conf
36 unixsocket /tmp/redis.sock
37 unixsocket perm 755
# service redis start
# chkconfig redis on
七、创建git用户并允许sudo
1
2
# useradd git
echo "git ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
八、安装gitlab
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# cd /home/git/
# sudo -u git -H git clone -b 7-8-stable gitlab
# cd gitlab
# cp config/gitlab.yml.example config/gitlab.yml
# vi config/gitlab.yml
20 host: localhost
21 port: 80
267 bin_path: /usr/bin/git
# chown -R git log/
# chown -R git tmp/
# chmod -R u+rwX log/
# chmod -R u+rwX tmp/
# sudo -u git -H mkdir /home/git/gitlab-satellites
# sudo chmod u+rwx,g=rx,o-rwx /home/git/gitlab-satellites
# chmod -R u+rwX tmp/pids/
# chmod -R u+rwX tmp/sockets
# chmod -R u+rwX public/uploads/
# cp config/unicorn.rb.exampleconfig/unicorn.rb
# cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb
以上不存在的目录,手动创建。配置数据库:
1
2
3
4
5
6
# cp config/database.yml.mysql config/database.yml
# vi config/database.yml
9database: gitlab #这里的数据库要跟在mysql中创建的库名一致。
10pool: 10
11username: gitlab
12password: gitlab
九、安装gitlab-shell
1
2
3
4
5
6
7
8
# cd /home/git/
# sudo -u git -H git clone -b v2.6.0
# cd gitlab-shell/
# cp config.yml.example config.yml
# vi config.yml
9 gitlab_url: http://localhost:8080/
30 bin: /usr/bin/redis-cli
# sudo -u git -H ./bin/install
十、nginx安装
1
2
3
4
5
6
7
# tar -zxf pcre-8.38.tar.gz
# cd pcre-8.38
# ./configure --prefix=/usr/local/pcre-8.38 && make && make install
# wget http://124.205.69.171/files/8095000002FE839E/nginx.org/download/nginx-1.8.1.tar.gz
# tar -zxf nginx-1.8.1.tar.gz
# cd nginx-1.8.1
# ./configure--prefix=/usr/local/nginx --user=git--group=git--with-http_ssl_module--with-http_stub_status_module --with-pcre=/usr/local/src/pcre-8.38/&& make&& make install
十一、安装需要的gems
1
2
# cd /home/git/gitlab
# sudo -u git -H bundle install --deployment --without development testpostgres aws
十二、初始化数据库
1
# sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production
十三、拷贝启动文件脚本及日志切割文件
1
2
3
# cp lib/support/init.d/gitlab /etc/init.d/gitlab
# cp lib/support/init.d/gitlab.default.example /etc/default/gitlab
# cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab
十四、设置git账号信息
1
2
3
# sudo -u git -H "/usr/bin/git" config --global user.name"GitLab"
# sudo -u git -H "/usr/bin/git" config --global user.email "example@example.com"
# sudo -u git -H "/usr/bin/git" config --global core.autocrlf "input"
十五、配置nginx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# vi /usr/local/nginx/conf/nginx.conf
upstream gitlab {
server unix:/home/git/gitlab/tmp/sockets/gitlab.socket;
}
server {
listen 80;
server_namelocalhost;
access_log/var/log/nginx/gitlab_access.log;
error_log /var/log/nginx/gitlab_error.log;
root/home/git/gitlab/public;
location / {
try_files $uri $uri/index.html $uri.html @gitlab;
}
location @gitlab {
proxy_read_timeout 300;
proxy_connect_timeout 300;
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;
}
}
# mkdir -p /var/log/nginx
# chown -R git:git/var/log/nginx/
# chown -R git:git /usr/local/nginx/
# /usr/local/nginx/sbin/nginx -t
# service nginx restart
十六、检测当前环境
1
# sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production
可能会有报错:Error: Table 'gitlab.projects' doesn't exist这时重新初始化数据库,执行以下命令:
1
# sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production
会发现,执行结束时生成了一个登录账号和密码:
1
2
login.........root
password......5iveL!fe 用来登录gitlab
再次执行环境检测命令……OK十七、拉取gitlab静态资源文件
1
# sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production
十八、启动gitlab
1
2
3
4
# /etc/init.d/gitlab start
# sudo chmod -R ug+rwX,o-rwx /home/git/repositories/
# sudo chmod -R ug-s /home/git/repositories/
# find /home/git/repositories/ -type d -print0 | sudo xargs -0 chmod g+s
十九、检测各个组件是否正常工作
1
#sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production
错误一:Send ping to redisserver: Could not connect to Redis at /tmp/redis.sock: Permission denied
1
2
#vi /home/git/gitlab-shell/config.yml
35 #socket: /tmp/redis.sock # Comment out thisline if you want to use TCP
错误二:用浏览器访问时,出现“502 Bad Gateway”编译nginx时指定 --user=git --group=git
1
2
# vi/usr/local/nginx/conf/nginx.conf
2 user git;
页:
[1]