一.环境
系统 CentOS 6.4x64
二.安装依赖包#添加epel源
[root@gitlab-ci ~]# rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
[root@gitlab-ci ~]# sed -i 's@#b@b@g' /etc/yum.repos.d/epel.repo
[root@gitlab-ci ~]# sed -i 's@mirrorlist@#mirrorlist@g' /etc/yum.repos.d/epel.repo
#配置时间同步
[root@gitlab-ci ~]# echo "*/10 * * * * /usr/sbin/ntpdate asia.pool.ntp.org &>/dev/null" >/var/spool/cron/root
[root@gitlab-ci ~]# yum groupinstall "Development Tools" -y
[root@gitlab-ci ~]# yum update && yum upgrade
[root@gitlab-ci ~]# yum install vim python wget curl git openssh-server -y
[root@gitlab-ci ~]# yum install sqlite sqlite-devel mysql mysql-libs mysql-devel -y
[root@gitlab-ci ~]# yum install ncurses-devel libcurl-devel libcurl patch nodejs -y
[root@gitlab-ci ~]# yum install libxslt-devel libyaml-devel libxml2 libxml2-devel gdbm-devel libffi libffi-devel zlib zlib-devel openssl-devel readline readline-devel curl-devel openssl-devel pcre-devel memcached-devel valgrind-devel ImageMagick-devel ImageMagick libicu libicu-devel make bzip2 autoconf automake libtool bison redis libpq-devel libicu-devel postgresql-libs postgresql-devel -y
[root@gitlab-ci ~]# chkconfig redis on
[root@gitlab-ci ~]# chkconfig postfix on
[root@gitlab-ci ~]# service redis start
Starting redis-server: [ OK ]
三.安装配置mysql
这里使用脚本安装mysql,版本为事先下载好的mysql-5.5.37
脚本内容如下[root@gitlab-ci ~]# cat install_mysql.sh
#!/bin/bash
DATADIR='/data/mysql/data'
VERSION='mysql-5.5.37'
export LANG=zh_CN.UTF-8
#Source function library.
. /etc/init.d/functions
#camke install mysql5.5.X
install_mysql(){
read -p "please input a password for root: " PASSWD
if [ ! -d $DATADIR ];then
mkdir -p $DATADIR
fi
yum install cmake make gcc-c++ bison-devel ncurses-devel -y
id mysql &>/dev/null
if [ $? -ne 0 ];then
useradd mysql -s /sbin/nologin -M
fi
#useradd mysql -s /sbin/nologin -M
#change datadir owner to mysql
chown -R mysql.mysql $DATADIR
cd
#wget http://mirrors.sohu.com/mysql/MySQL-5.5/mysql-5.5.38.tar.gz
tar xf $VERSION.tar.gz
cd $VERSION
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/$VERSION \
-DMYSQL_DATADIR=$DATADIR \
-DMYSQL_UNIX_ADDR=$DATADIR/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DENABLED_LOCAL_INFILE=ON \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_FEDERATED_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITHOUT_EXAMPLE_STORAGE_ENGINE=1 \
-DWITHOUT_PARTITION_STORAGE_ENGINE=1
make && make install
if [ $? -ne 0 ];then
action "install mysql is failed" /bin/false
exit $?
fi
sleep 2
#link
ln -s /usr/local/$VERSION/ /usr/local/mysql
ln -s /usr/local/mysql/bin/* /usr/bin/
#copy config and start file
/bin/cp /usr/local/mysql/support-files/my-small.cnf /etc/my.cnf
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
chmod 700 /etc/init.d/mysqld
#init mysql
/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql --datadir=$DATADIR --user=mysql
if [ $? -ne 0 ];then
action "install mysql is failed" /bin/false
exit $?
fi
#check mysql
/etc/init.d/mysqld start
if [ $? -ne 0 ];then
action "mysql start is failed" /bin/false
exit $?
fi
chkconfig --add mysqld
chkconfig mysqld on
/usr/local/mysql/bin/mysql -e "update mysql.user set password=password('$PASSWD') where host='localhost' and user='root';"
/usr/local/mysql/bin/mysql -e "update mysql.user set password=password('$PASSWD') where host='127.0.0.1' and user='root';"
/usr/local/mysql/bin/mysql -e "delete from mysql.user where password='';"
/usr/local/mysql/bin/mysql -e "flush privileges;"
#/usr/local/mysql/bin/mysql -e "select version();" >/dev/null 2>&1
if [ $? -eq 0 ];then
echo "+---------------------------+"
echo "+------mysql安装完成--------+"
echo "+---------------------------+"
fi
#/etc/init.d/mysqld stop
}
install_mysql
创建gitlab-ci相关数据库信息mysql> CREATE DATABASE IF NOT EXISTS `gitlab_ci` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
Query OK, 1 row affected (0.04 sec)
#创建用户和密码
mysql> CREATE USER 'gitlab_ci'@'localhost' IDENTIFIED BY '123456';
Query OK, 0 rows affected (0.00 sec)
#赋予相关权限
mysql> GRANT SELECT,INSERT,UPDATE,DELETE,CREATE,DROP,INDEX,ALTER ON gitlab_ci.* TO 'gitlab_ci'@'localhost';
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
四.创建系统用户gitlab_ci[root@gitlab-ci ~]# useradd gitlab_ci
[root@gitlab-ci ~]# passwd gitlab_ci
Changing password for user gitlab_ci.
New password: #这里设置密码为gitlab_ci
Retype new password:
passwd: all authentication tokens updated successfully.
[root@gitlab-ci ~]# chmod 755 /home/gitlab_ci
五.安装ruby[root@gitlab-ci ~]# wget ftp://ftp.ruby-lang.org/pub/ruby/ruby-2.2.0.tar.gz
[root@gitlab-ci ~]# tar xf ruby-2.2.0.tar.gz
[root@gitlab-ci ~]# cd ruby-2.2.0
[root@gitlab-ci ruby-2.2.0]# ./configure
[root@gitlab-ci ruby-2.2.0]# make && make install
#安装bundler
[root@gitlab-ci ruby-2.2.0]# gem install bundler --no-doc
ERROR: While executing gem ... (Gem::RemoteFetcher::FetchError)
Errno::ECONNRESET: Connection reset by peer - SSL_connect (https://api.rubygems.org/quick/Marshal.4.8/bundler-1.10.6.gemspec.rz)
#报错解决如下
[root@gitlab-ci ruby-2.2.0]# gem sources --remove https://rubygems.org/
https://rubygems.org/ removed from sources
[root@gitlab-ci ruby-2.2.0]# gem sources -a https://ruby.taobao.org/
https://ruby.taobao.org/ added to sources
[root@gitlab-ci ruby-2.2.0]# gem sources -l
*** CURRENT SOURCES ***
https://ruby.taobao.org/
#从新安装
[root@gitlab-ci ruby-2.2.0]# gem install bundler --no-doc
六.安装gitlab ci#切换到gitlab_ci用户下,并进入到用户家目录
[root@gitlab-ci ruby-2.2.0]# su - gitlab_ci
[gitlab_ci@gitlab-ci ~]$ git clone https://gitlab.com/gitlab-org/gitlab-ci.git
[gitlab_ci@gitlab-ci ~]$ cd gitlab-ci/
[gitlab_ci@gitlab-ci gitlab-ci]$ git checkout 5-4-stable
[gitlab_ci@gitlab-ci gitlab-ci]$ mkdir -p tmp/pids
[gitlab_ci@gitlab-ci gitlab-ci]$ mkdir -p tmp/sockets
[gitlab_ci@gitlab-ci gitlab-ci]$ gem install bundler
#报错如下
ERROR: While executing gem ... (Gem::RemoteFetcher::FetchError)
Errno::ECONNRESET: Connection reset by peer - SSL_connect (https://api.rubygems.org/quick/Marshal.4.8/bundler-1.10.6.gemspec.rz)
#解决如下
[gitlab_ci@gitlab-ci gitlab-ci]$ gem sources --remove https://rubygems.org/
https://rubygems.org/ removed from sources
[gitlab_ci@gitlab-ci gitlab-ci]$ gem sources -a https://ruby.taobao.org/
https://ruby.taobao.org/ added to sources
[gitlab_ci@gitlab-ci gitlab-ci]$ gem sources -l
*** CURRENT SOURCES ***
https://ruby.taobao.org/
[gitlab_ci@gitlab-ci gitlab-ci]$ gem install bundler
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /usr/local/lib/ruby/gems/2.2.0 directory.
#切换到root用户下修改权限
[root@gitlab-ci ~]# chmod -R 777 /usr/local/lib/ruby
[root@gitlab-ci ~]# chmod -R 777 /usr/local/bin
#再次重新执行
[gitlab_ci@gitlab-ci gitlab-ci]$ gem install bundler
[gitlab_ci@gitlab-ci gitlab-ci]$ bundle --without development test
[gitlab_ci@gitlab-ci gitlab-ci]$ cp config/database.yml.mysql config/database.yml
[gitlab_ci@gitlab-ci gitlab-ci]$ vim config/database.yml
#修改内容如下
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: gitlab_ci #数据库名称
pool: 5
username: gitlab_ci #数据库用户名
password: "123456" #密码
host: localhost
socket: /data/mysql/data/mysql.sock #这里指向mysql的socket文件,由于我修改过socket文件的位置,所以这个地方需要手动修改
[gitlab_ci@gitlab-ci gitlab-ci]$ cp config/application.yml.example config/application.yml
[gitlab_ci@gitlab-ci gitlab-ci]$ cp config/unicorn.rb.example config/unicorn.rb
[gitlab_ci@gitlab-ci gitlab-ci]$ bundle exec rake db:setup RAILS_ENV=production
[gitlab_ci@gitlab-ci gitlab-ci]$ bundle exec whenever -w RAILS_ENV=production
七.配置gitlab_ci的服务启动脚本#切换到root用户下,执行下面的命令
[root@gitlab-ci gitlab_ci]# cp /home/gitlab_ci/gitlab-ci/lib/support/init.d/gitlab_ci /etc/init.d/gitlab_ci
[root@gitlab-ci gitlab_ci]# chkconfig --add gitlab_ci
[root@gitlab-ci gitlab_ci]# chkconfig gitlab_ci on
[root@gitlab-ci gitlab_ci]# /etc/init.d/gitlab_ci start
八.安装配置nginx[root@gitlab-ci gitlab_ci]# yum install nginx -y
#复制站点配置文件
[root@gitlab-ci gitlab_ci]# cp /home/gitlab_ci/gitlab-ci/lib/support/nginx/gitlab_ci /etc/nginx/conf.d/gitlab_ci.conf
#修改gitlab_ci.conf配置文件如下
[root@gitlab-ci gitlab_ci]# cat /etc/nginx/conf.d/gitlab_ci.conf
# GITLAB CI
# Maintainer: @randx
# App Version: 2.0
upstream gitlab_ci {
server unix:/home/gitlab_ci/gitlab-ci/tmp/sockets/gitlab-ci.socket;
}
server {
listen 80 ; # e.g., listen 192.168.1.1:80;
server_name gitci.keluofu.com; #修改这里
root /home/gitlab_ci/gitlab-ci/public;
access_log /var/log/nginx/gitlab_ci_access.log;
error_log /var/log/nginx/gitlab_ci_error.log;
location / {
try_files $uri $uri/index.html $uri.html @gitlab_ci;
}
location @gitlab_ci {
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_pass http://gitlab_ci;
}
# adjust this to match the largest build log your runners might submit,
# set to 0 to disable limit
client_max_body_size 10m;
}
#测试nginx配置是否有误,并启动nginx
[root@gitlab-ci gitlab_ci]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@gitlab-ci gitlab_ci]# /etc/init.d/nginx start
Starting nginx: [ OK ]
[root@gitlab-ci gitlab_ci]# netstat -tunlp |grep nginx
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 36894/nginx