GitLab build detailed process

1. Premise

  1. System: Centos 6.5
  2. Software version: gitlab-7.8.4
  3. Selinux: off
  4. Firewall rules: clear first (after setting up, add relevant release rules by yourself)

 

Second, yum source configuration and related dependencies

  1. Add epel source and PUIAS_6_computational source

1
# yum -y install epel-release

     Create the file and add the following:

1
2
3
4
5
6
7
# vim /etc/yum.repos.d/PUIAS_6_computational.repo
[PUIAS_6_computational]
name=PUIAS computational Base $releasever - $basearch
mirrorlist=http: //puias .math.ias.edu /data/puias/computational/ $releasever/$basearch /mirrorlist
#baseurl=http://puias.math.ias.edu/data/puias/computational/$releasever/$basearch
gpgcheck=1
gpgkey= file : ///etc/pki/rpm-gpg/RPM-GPG-KEY-puias

  Obtain and import relevant verification files

1
2
3
# 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
# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-puias
# yum repolist

  2. Install dependency packages

1
2
3
4
5
6
7
# yum install -y vim lrzsz wget gcc gcc-c++ make makeconf cmake
# yum -y update
# yum -y groupinstall 'Development Tools'
# 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 cmake libicu-devel libicu openssl openssl-devel
 
查看安装的git版本,需要1.7.12以上,有PUIAS源会装1.8
# git --version

 

3. Install Ruby

  1. Check if Ruby is installed

1
# rpm -qa | grep ruby

  2. Install Ruby

1
2
3
4
5
6
# mkdir /tmp/ruby && cd /tmp/ruby
# curl --progress ftp://ftp.ruby-lang.org/pub/ruby/2.1/ruby-2.1.2.tar.gz | tar xz
# cd ruby-2.1.2
# ./configure --disable-install-rdoc
# make
# make prefix=/usr/local install

  3. Install Bundler Gem

1
# gem install bundler --no-doc

    The following error may be reported. This is because the domestic network causes the indirect link failure of the resource files stored on Amazon S3 by rubygems.org. Replace the official image with the domestic RubyGems image (see http://ruby.taobao.org/).

    

    Change the mirror address:

1
2
# gem sources --remove https://rubygems.org/        # 删除原镜像地址
# gem sources -a https://ruby.taobao.org/           # 添加新镜像地址

    Check if the replacement is successful:

    

    Install again:

     

 

Fourth, create a system user git

1
2
3
4
5
6
7
8
9
10
11
# adduser --system --shell /bin/bash --comment 'GitLab' --create-home --home-dir /home/git/ git
让git用户可以找到 /usr/local/bin 命令,并可以使用 sudo
# 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    ALL=(ALL)       ALL
在下一行添加:
git    ALL=(ALL)       ALL

 

5. Install MySQL

  1. Premise

    The database here needs to be installed with Mysql 5.5 or above, and the epel source is only 5.1 by default, so the source of Mysql 5.5 needs to be added

1
2
3
4
5
# rpm -qa | grep mysql   # 查看是否安装比较低版本的mysql,然后卸载
# yum remove -y mysql*
# yum install -y mysql55-server mysql55-devel mysql55 postfix # 安装5.5版本
# chkconfig mysqld on   # 设置开机启动
# service mysqld start

    The requirement is InnoDB engine, log in to see if it is InnoDB engine

    

    If not, you can set it with SET storage_engine=INNODB, or restart mysql after modifying the my.cnf file

  2. Configure the database used by GitLab

1
2
3
4
5
> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
> GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO  'git' @ 'localhost'  identified by  'git' ;
> GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO  'git' @ '127.0.0.1'  identified by  'git' ;
> flush privileges;
exit ;

6. Install Redis

  Install Reids

1
2
3
# yum -y install redis
# chkconfig redis on
# cp /etc/redis.conf /etc/redis.conf.orig

  The following command will set the port of redis.conf to 0, and redis.conf.orig will remain unchanged

1
2
3
# sed 's/^port .*/port 0/' /etc/redis.conf.orig | sudo tee /etc/redis.conf
# echo 'unixsocket /var/run/redis/redis.sock' | sudo tee -a /etc/redis.conf
# echo -e 'unixsocketperm 0770' | sudo tee -a /etc/redis.conf

  Authorize /var/run/redis to give redis permissions

1
2
3
# mkdir -p /var/run/redis/
# chown redis:redis /var/run/redis
# chmod 755 /var/run/redis

  将git加入redis组,并启动Redis

1
2
# usermod -aG redis git
# service redis start

 

七、安装GitLab

  1.克隆GitLab

1
2
3
# su - git
# cd /home/git
# git clone https://gitlab.com/larryli/gitlab.git -b 7-8-zh gitlab

  2.配置

    切换至GitLab目录下面,复制一份配置文件

1
2
# cd gitlab
# cp config/gitlab.yml.example config/gitlab.yml

    确保GitLab可以对 log 和 tmp 目录有写入权限

1
2
3
4
# chown -R git log/
# chown -R git tmp/
# chmod -R u+rwX log/
# chmod -R u+rwX tmp/

    为satelites创建目录

1
2
# mkdir /home/git/gitlab-satellites
# chmod u+rwx,g=rx,o-rwx /home/git/gitlab-satellites

    确保GitLab可以对 tmp/pids、tmp/sockets、public/uploads目录有写入权限

1
2
3
# chmod -R u+rwX tmp/pids/
# chmod -R u+rwX tmp/sockets/
# chmod -R u+rwX  public/uploads

    从配置案例复制一份unicorn配置文件,并修改配置文件中的timeout选项的值为600(防止仓库文件太大,拉取时间过长出现超时)

1
2
3
4
5
# su -
# cd /home/git/gitlab
# sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb
# vim gitlab/config/unicorn.rb
修改timeout 600

    从配置案例复制一份rack attack配置文件

1
# sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb

    为git用户配置git全局配置

1
2
3
# sudo -u git -H git config --global user.name "GitLab"
# sudo -u git -H git config --global user.email "[email protected]"
# sudo -u git -H git config --global core.autocrlf input

    配置redis连接

1
# sudo -u git -H cp config/resque.yml.example config/resque.yml

    配置GitLab数据库设置

1
2
# sudo -u git cp config/database.yml.mysql config/database.yml
# vim config/database.yml

    只需配置生产的部分(第一部分),用户名和密码

    

    配置好以后运行该命令

1
# sudo -u git -H chmod o-rwx config/database.yml

    配置GitLab绑定的域名或者IP

1
2
3
# vim config/gitlab.yml
修改host为gitlab的域名为你主机的IP地址(有两项, test 一项应该没有影响,不过也修改吧)
host:主机IP

    安装Gems

1
# sudo -u git -H bundle install --deployment --without development test postgres aws

    可能会报错,还是大陆访问官网的问题,替换成https://ruby.taobao.org,然后再安装

    

    替换命令:

1
# sed -i '/^source/s/https\:\/\/rubygems\.org/https\:\/\/ruby\.taobao\.org/' Gemfile

    安装GitLab shell

1
# sudo -u git -H bundle exec rake gitlab:shell:install[v2.5.4] REDIS_URL=unix:/var/run/redis/redis.sock RAILS_ENV=production

    初始化数据库

1
# sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production

    如果想要自己设置GitLab的root默认登陆密码则运行以下命令:

1
# sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production GITLAB_ROOT_PASSWORD=yourpassword

    默认登陆账号密码

1
2
login.........root
password......5iveL!fe

    配置启动脚本

1
# cp lib/support/init.d/gitlab /etc/init.d/

    配置日志切割

1
# cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab

    运行命令检测GitLab和它的环境是否正确

1
# sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production

    运行命令结果截图如下:

    

    拉取GitLab静态资源文件

1
# sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production

    修改配置文件的gitlab_url为主机IP或者域名

1
# vim /home/git/gitlab-shell/config.yml

    启动GitLab实例

1
# service gitlab start

 

八、配置Nginx

  安装和配置开机启动(这里用yum安装,也可以自己编译安装)

1
2
# yum install -y nginx
# chkconfig nginx on

  下载Nginx配置文件,并命名为gitlab.conf

1
# wget -O /etc/nginx/conf.d/gitlab.conf https://gitlab.com/gitlab-org/gitlab-ce/raw/master/lib/support/nginx/gitlab

  把nginx加入到git组

1
2
# usermod -a -G git nginx
# chmod g+rx /home/git/

  修改gitlab.conf文件

1
2
3
4
5
# vim /etc/nginx/conf.d/gitlab.conf
server unix: /home/git/gitlab/tmp/sockets/gitlab-workhorse .socket fail_timeout=0; 修改为 server unix: /home/git/gitlab/tmp/sockets/gitlab .socket fail_timeout=0;
listen 0.0.0.0:80 default_server;   修改为 listen 80;
listen [::]:80 default_server;       该行删除
server_name YOUR_SERVER_FQDN;  修改为 server_name 主机IP

  启动Nginx

1
# service nginx start

 

九、访问

  访问地址,http://主机IP或者域名,第一次登陆后就需要修改root用户的密码,然后再去掉GitLab的用户注册功能。到此GitLab搭建完毕!

  

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325393577&siteId=291194637