Linux之CentOS 6或者CentOS 7上全编译安装GitLab 8-1中文版

  • A+
所属分类:Linux  Linux中级
摘要

GitLab,是一个利用 Ruby on Rails 开发的开源应用程序,实现一个自托管的Git项目仓库,可通过Web界面进行访问公开的或者私人项目。
它拥有与GitHub类似的功能,能够浏览源代码,管理缺陷和注释。可以管理团队对仓库的访问,它非常易于浏览提交过的版本并提供一个文件历史库。团队成员可以利用内置的简单聊天程序(Wall)进行交流。它还提供一个代码片段收集功能可以轻松实现代码复用,便于日后有需要的时候进行查找。

1、关闭SELinux

#下面的命令实现永久关闭SELinux
[root@vps197119 ~]# sed -i 's/^SELINUX=.*/#&/;s/^SELINUXTYPE=.*/#&/;/SELINUX=.*/a SELINUX=disabled' /etc/sysconfig/selinux
#下面的命令实现临时关闭SELinux
[root@vps197119 ~]# /usr/sbin/setenforce 0
/usr/sbin/setenforce: SELinux is disabled

2、设置PS1

[root@vps197119 ~]# echo "PS1='[\[\033[0;34m\]\u\[\033[0;37m\]@\[\033[0;35m\]\h\[\033[0;33m\] \w\[\033[0;37m\]]\[\033[0;31m\]\\$\[\033[00m\] '" >>/etc/profile

3、设置命令记录和阻止You have mail in /var/spool/mail/root提示

[root@vps197119 ~]# echo "export PROMPT_COMMAND='{ msg=\$(history 1 | { read x y; echo \$y; });user=\$(whoami); echo \$(date \"+%F %H:%M:%S\"):\$user:\`pwd\`/:\$msg ---- \$(who am i); } >> /tmp/\`date \"+%F\"\`.\`hostname\`.\`whoami\`.history-timestamp'" >> /etc/profile
[root@vps197119 ~]# echo "unset MAILCHECK" >> /etc/profile

4、source /etc/profile使之刚才的设置生效

[root@vps197119 ~]# . /etc/profile

Linux之CentOS 6或者CentOS 7上全编译安装GitLab 8-1中文版

5、安装wget yum-utils和epel源

[root@vps197119 ~]# yum -y install epel* wget yum-utils

6、导入EPEL源的key

[root@vps197119 ~]# rpm --import https://www.fedoraproject.org/static/0608B895.txt

7、安装bash-completion (主要左右是支持tab键补齐)

[root@vps197119 ~]# yum -y install bash-completion
[root@vps197119 ~]# . /etc/bash_completion

8、安装PUIAS源和导入对应key

[root@vps197119 ~]# wget -qO- https://gitlab.com/gitlab-org/gitlab-recipes/raw/master/install/centos/PUIAS_6_computational.repo > /etc/yum.repos.d/PUIAS_6_computational.repo
[root@vps197119 ~]# rpm --import http://springdale.math.ias.edu/data/puias/6/x86_64/os/RPM-GPG-KEY-puias

9、重新建立源缓存和检测key导入是否成功

[root@vps197119 ~]# yum clean all && yum makecache
[root@vps197119 ~]# rpm -qa gpg*| grep '0608b895'
[root@vps197119 ~]# rpm -qa gpg*| grep '41a40948'

Linux之CentOS 6或者CentOS 7上全编译安装GitLab 8-1中文版

10、安装Development Tools开发组包和一下必要的包文件

[root@vps197119 ~]# yum -y groupinstall 'Development Tools'
[root@vps197119 ~]# 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 sudo crontabs logwatch logrotate perl-Time-HiRes \
libcom_err-devel.i686 libcom_err-devel.x86_64 nodejs

11、安装vim且设置为默认编辑器

[root@vps197119 ~]# yum -y install vim-enhanced
[root@vps197119 ~]# update-alternatives --set editor /usr/bin/vim.basic
[root@vps197119 ~]# ln -sv /usr/bin/vim /usr/bin/editor

12、安装reStructuredText markup语法支持需要的依赖包和postfix、ntp

[root@vps197119 ~]# yum install -y python-docutils postfix ntp

13、同步时间

[root@vps197119 tmp]# rm -rf /etc/localtime 
[root@vps197119 ~]# ln -sv /usr/share/zoneinfo/Asia/Shanghai /etc/localtime 
[root@vps197119 ~]# ntpdate pool.ntp.org
[root@vps197119 ~]# echo '*/20 * * * * /usr/sbin/ntpdate pool.ntp.org > /dev/null 2>&1' >>/var/spool/cron/root

14、编译安装高版本git

[root@vps197119 ~]# yum -y remove git
[root@vps197119 ~]# yum -y install zlib-devel perl-CPAN gettext curl-devel expat-devel gettext-devel openssl-devel
[root@vps197119 ~]# mkdir /tmp/git && cd /tmp/git
[root@vps197119 /tmp/git]# wget http://mirrors.dwhd.org/Git/git-2.5.3.tar.xz
#最新版下载方法
#[root@vps197119 /tmp/git]# URL='https://www.kernel.org/pub/software/scm/git/' && wget -c `curl -s $URL|awk --posix -F'"' '$2~/git-([0-9]+.){3}tar.xz/{a=$2}END{print "'"$URL"'"a}'`
[root@vps197119 /tmp/git]# tar xf git-2.5.3.tar.xz 
[root@vps197119 /tmp/git]# cd git-2.5.3/
[root@vps197119 /tmp/git/git-2.5.3]# ./configure --prefix=/usr/local
[root@vps197119 /tmp/git/git-2.5.3]# make -j $(awk '/processor/{i++}END{print i}' /proc/cpuinfo) && make install && cd ../..
#[root@vps197119 /tmp]# echo "PATH=/usr/local/bin:\$PATH" > /etc/profile.d/git.sh
#[root@vps197119 /tmp]# . /etc/profile.d/git.sh
[root@vps197119 /tmp]# which git
/usr/local/bin/git
[root@vps197119 /tmp]# git --version
git version 2.5.3

15、编译安装高版本ruby

[root@vps197119 /tmp]# yum -y remove ruby
[root@vps197119 /tmp]# mkdir /tmp/ruby && cd /tmp/ruby
[root@vps197119 /tmp/ruby]# wget -c http://mirrors.dwhd.org/Ruby/ruby/2.2/ruby-2.2.3.tar.xz
#最新版本下载
#[root@vps197119 /tmp/ruby]# URL1='http://mirrors.dwhd.org/Ruby/ruby/' && URL2=`curl -s $URL1|awk -PF'"' '{if ($2~/^[0-9]+\.[0-9]+/)a=$2}END{print "'$URL1'"a}'` && wget -c `curl -s $URL2|awk -PF'"' '{if ($2~/^ruby.*xz$/)a=$2}END{print "'$URL2'"a}'`
[root@vps197119 /tmp/ruby]# tar xf ruby-2.2.3.tar.xz 
[root@vps197119 /tmp/ruby]# cd ruby-2.2.3/
[root@vps197119 /tmp/ruby/ruby-2.2.3]# ./configure --prefix=/usr/local --disable-install-rdoc
[root@vps197119 /tmp/ruby/ruby-2.2.3]# make -j $(awk '/processor/{i++}END{print i}' /proc/cpuinfo) && make install && cd ../..
[root@vps197119 /tmp]# ruby -v
ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-linux]

16、安装bundler

[root@vps197119 tmp]# gem install bundler --no-doc
##如果地址被墙请跟换ruby源
gem sources --remove https://rubygems.org/
gem sources -a https://ruby.taobao.org/
gem sources -l

Linux之CentOS 6或者CentOS 7上全编译安装GitLab 8-1中文版

17、安装go (gitlab 8.0 以后的版本需要go语言的支持)

[root@vps197119 /tmp/go]# wget https://storage.googleapis.com/golang/go1.6.linux-amd64.tar.gz
#最新版本下载
#64位 [root@vps197119 /tmp/go]# URL='https://storage.googleapis.com/golang/' && wget -c `curl -s $URL|xmllint --format - |awk -PF'[><]' '{if ($3~/linux/ && $3!~/(beta|rc)[0-9]+|armv6l|386/)a=$3}END{print "'$URL'"a}'`
#32位 [root@vps197119 /tmp/go]# URL='https://storage.googleapis.com/golang/' && wget -c `curl -s $URL|xmllint --format - |awk -PF'[><]' '{if ($3~/linux/ && $3!~/(beta|rc)[0-9]+|armv6l|amd64/)a=$3}END{print "'$URL'"a}'`
[root@vps197119 /tmp/go]# tar xf go1.6.linux-amd64.tar.gz -C /usr/local/
[root@vps197119 /tmp/go]# echo "PATH=/usr/local/go/bin:\$PATH" >/etc/profile.d/go.sh
[root@vps197119 /tmp/go]# . /etc/profile.d/go.sh
[root@vps197119 /tmp/go]# go version
go version go1.6 linux/amd64

18、添加系统用户git

[root@vps197119 /tmp]# adduser -r -s /bin/bash -c 'GitLab' -m -d /home/git/ git

19、编译按cmake

[root@vps197119 tmp]# mkdir /tmp/cmake && cd /tmp/cmake
[root@vps197119 cmake]# wget http://cmake.org/files/v3.5/cmake-3.5.1.tar.gz
[root@vps197119 cmake]# tar xf cmake-3.5.1.tar.gz 
[root@vps197119 cmake]# cd cmake-3.5.1
[root@vps197119 cmake-3.5.1]# ./bootstrap && make -j $(awk '/processor/{i++}END{print i}' /proc/cpuinfo) && make install && cd ../..

20、编译安装kytea,后面编译MariaDB需要

[root@vps197119 tmp]# mkdir /tmp/kytea && cd /tmp/kytea
[root@vps197119 kytea]# wget http://www.phontron.com/kytea/download/kytea-0.4.7.tar.gz
[root@vps197119 kytea]# tar xf kytea-0.4.7.tar.gz
[root@vps197119 kytea]# cd kytea-0.4.7
[root@vps197119 kytea-0.4.7]# ./configure && make -j $(awk '/processor/{i++}END{print i}' /proc/cpuinfo) && make install && cd ../..

21、编译安装MariaDB

[root@vps197119 tmp]# mkdir /tmp/mariadb && cd /tmp/mariadb
[root@vps197119 /tmp/mariadb]# wget http://mirrors.dwhd.org/SQL/MariaDB/mariadb-10.0.21/source/mariadb-10.0.21.tar.gz
[root@vps197119 /tmp/mariadb]# tar xf mariadb-10.0.21.tar.gz 
[root@vps197119 /tmp/mariadb]# cd mariadb-10.0.21
[root@vps197119 /tmp/mariadb/mariadb-10.0.21]# adduser -r -s /sbin/nologin -c 'MariaDB' -M mysql
[root@vps197119 /tmp/mariadb/mariadb-10.0.21]# mkdir -p /data/mariadb
[root@vps197119 /tmp/mariadb/mariadb-10.0.21]# chown -R mysql.mysql /data/mariadb
[root@vps197119 /tmp/mariadb/mariadb-10.0.21]# rpm --import https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
[root@vps197119 /tmp/mariadb/mariadb-10.0.21]# yum -y install libxml2-devel lz4 lz4-devel libpcap nmap lsof socat #这里有几个包是galera用到的,不是全部必须安装
##如果需要重新编译,请编译前做清空动作
##make clean && rm CMakeCache.txt 
[root@vps197119 /tmp/mariadb/mariadb-10.0.21]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mariadb \
-DMYSQL_DATADIR=/data/mariadb \
-DWITH_SSL=system \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DWITH_SPHINX_STORAGE_ENGINE=1 \
-DWITH_ARIA_STORAGE_ENGINE=1 \
-DWITH_XTRADB_STORAGE_ENGINE=1 \
-DWITH_PARTITION_STORAGE_ENGINE=1 \
-DWITH_FEDERATEDX_STORAGE_ENGINE=1 \
-DWITH_MYISAM_STORAGE_ENGINE=1 \
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \
-DWITH_EXTRA_CHARSETS=all \
-DWITH_EMBEDDED_SERVER=1 \
-DWITH_READLINE=1 \
-DWITH_ZLIB=system \
-DWITH_LIBWRAP=0 \
-DEXTRA_CHARSETS=all \
-DENABLED_LOCAL_INFILE=1 \
-DMYSQL_UNIX_ADDR=/tmp/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci
[root@vps197119 /tmp/mariadb/mariadb-10.0.21]# make -j $(awk '/processor/{i++}END{print i}' /proc/cpuinfo) && make install && cd ../..
[root@vps197119 /tmp/mariadb/mariadb-10.0.21]# cd /usr/local/mariadb/
##拷贝MariaDB的启动脚本
[root@vps197119 /usr/local/mariadb]# cp support-files/mysql.server /etc/rc.d/init.d/mysqld
##MariaDB启动脚本添加可执行权限
[root@vps197119 /usr/local/mariadb]# chmod +x /etc/rc.d/init.d/mysqld
##拷贝MariaDB的主配置文件
[root@vps197119 /usr/local/mariadb]# \cp /usr/local/mariadb/support-files/my-large.cnf /etc/my.cnf
[root@vps197119 /usr/local/mariadb]# sed -i '/query_cache_size/a datadir = /data/mariadb/' /etc/my.cnf
##设置环境变量加入MariaDB
[root@vps197119 /usr/local/mariadb]# echo "export PATH=/usr/local/mariadb/bin:\$PATH" > /etc/profile.d/mariadb.sh
[root@vps197119 /usr/local/mariadb]# . /etc/profile.d/mariadb.sh
##设置man文档加入MariaDB
[root@vps197119 /usr/local/mariadb]# sed -i "$(awk '$1=="MANPATH"{i=NR}END{print i}' /etc/man.config)a \MANPATH\tMANPATH /usr/local/mariadb/man" /etc/man.config
##初始化数据库
[root@vps197119 /usr/local/mariadb]# /usr/local/mariadb/scripts/mysql_install_db --user=mysql --datadir=/data/mariadb
##启动MariaDB
[root@vps197119 /usr/local/mariadb]# cd && service mysqld start
##删除MariaDB的空密码用户、test库和添加git用户
[root@vps197119 ~]# mysql -uroot -p <<<"USE mysql;
UPDATE user SET password=PASSWORD('lookback') WHERE USER='root';
DELETE FROM user WHERE User='';
DROP DATABASE test;
CREATE USER 'git'@'localhost' IDENTIFIED BY 'lookback';
SET storage_engine=INNODB;
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';
FLUSH PRIVILEGES;
SELECT USER,PASSWORD,HOST FROM user;
SHOW DATABASES;"
[root@vps197119 ~]# usermod -a -G git mysql

22、编译安装redis

[root@vps197119 ~]# yum -y remove redis
[root@vps197119 ~]# mkdir /tmp/redis && cd /tmp/redis
[root@vps197119 /tmp/redis]# wget -c `curl -s http://redis.io/download | awk -F"'" '/[0-9].[0-9].*.tar.gz/{print $4;exit}'`
[root@vps197119 /tmp/redis]# tar xf redis*
[root@vps197119 /tmp/redis]# cd redis*
[root@vps197119 /tmp/redis/redis-3.0.4]# if [ `getconf WORD_BIT` == 32 ] && [ `getconf LONG_BIT` == 32 ];then sed -i '1i\CFLAGS= -march=i686' src/Makefile && sed -i 's@^OPT=.*@OPT=-O2 -march=i686@' src/.make-settings;fi
[root@vps197119 /tmp/redis/redis-3.0.4]# make
[root@vps197119 /tmp/redis/redis-3.0.4]# mkdir -p /usr/local/redis/{bin,etc,var}
[root@vps197119 /tmp/redis/redis-3.0.4]# cp -af src/{redis-benchmark,redis-check-aof,redis-check-dump,redis-cli,redis-sentinel,redis-server} /usr/local/redis/bin/
[root@vps197119 /tmp/redis/redis-3.0.4]# cp -a redis.conf /usr/local/redis/etc/
[root@vps197119 /tmp/redis/redis-3.0.4]# echo "export PATH=/usr/local/redis/bin:\$PATH" > /etc/profile.d/redis.sh
[root@vps197119 /tmp/redis/redis-3.0.4]# . /etc/profile.d/redis.sh
[root@vps197119 /tmp/redis/redis-3.0.4]# sed -i 's@pidfile.*@pidfile /var/run/redis.pid@' /usr/local/redis/etc/redis.conf
[root@vps197119 /tmp/redis/redis-3.0.4]# sed -i "s@logfile.*@logfile /usr/local/redis/var/redis.log@" /usr/local/redis/etc/redis.conf
[root@vps197119 /tmp/redis/redis-3.0.4]# sed -i "s@^dir.*@dir /usr/local/redis/var@" /usr/local/redis/etc/redis.conf
[root@vps197119 /tmp/redis/redis-3.0.4]# sed -i 's@daemonize no@daemonize yes@' /usr/local/redis/etc/redis.conf
[root@vps197119 /tmp/redis/redis-3.0.4]# [ -z "`grep ^maxmemory /usr/local/redis/etc/redis.conf`" ] && sed -i 's@maxmemory <bytes>@maxmemory <bytes>\nmaxmemory 360000000@' /usr/local/redis/etc/redis.conf
[root@vps197119 /tmp/redis/redis-3.0.4]# wget http://www.dwhd.org/script/Redis-server-init-CentOS -O /etc/init.d/redis-server
[root@vps197119 /tmp/redis/redis-3.0.4]# sed -i "/touch $lockfile/a \    chown git $(awk '/^unixsocket /{print $2}' /usr/local/redis/etc/redis.conf)" /etc/init.d/redis-server
[root@vps197119 /tmp/redis/redis-3.0.4]# chmod +x /etc/init.d/redis-server
[root@vps197119 /tmp/redis/redis-3.0.4]# chkconfig redis-server on
#启动redis
[root@vps197119 /tmp/redis/redis-3.0.4]# service redis-server start
Starting redis-server:                                     [  OK  ]
#验证启动成功
[root@vps197119 /tmp/redis/redis-3.0.4]# ss -tnl|grep :6379
LISTEN     0      128                       *:6379                     *:*     
LISTEN     0      128                      :::6379                    :::*     
#停止redis
[root@vps197119 /tmp/redis/redis-3.0.4]# service redis-server stop
Stopping redis-server:                                     [  OK  ]
#设置redis基于socket运行
[root@vps197119 /tmp/redis/redis-3.0.4]# mkdir -p /var/run/redis && chown -R git.redis /var/run/redis/
[root@vps197119 /tmp/redis/redis-3.0.4]# sed -ri 's/^(port).*/\1 0/' /usr/local/redis/etc/redis.conf
[root@vps197119 /tmp/redis/redis-3.0.4]# echo 'unixsocket /var/run/redis/redis.sock' >> /usr/local/redis/etc/redis.conf
[root@vps197119 /tmp/redis/redis-3.0.4]# echo 'unixsocketperm 0770' >> /usr/local/redis/etc/redis.conf
[root@vps197119 /tmp/redis/redis-3.0.4]# service redis-server start
Starting redis-server:                                     [  OK  ]
##验证redis安装是否成功
[root@vps197119 /tmp/redis/redis-3.0.4]# redis-cli -s /var/run/redis/redis.sock <<< "info" | grep 'redis.version'
redis_version:3.0.4
##将git添加到redis用户组中
[root@vps197119 /tmp/redis/redis-3.0.4]# usermod -aG redis git && cd ../..

23、编译安装Nginx

[root@vps197119 /tmp]# mkdir /tmp/nginx && cd /tmp/nginx
[root@vps197119 /tmp/nginx]# wget http://mirrors.dwhd.org/Nginx/nginx-1.9.5.tar.gz
[root@vps197119 /tmp/nginx]# tar xf nginx-1.9.5.tar.gz 
[root@vps197119 /tmp/nginx]# cd nginx-1.9.5/
[root@vps197119 /tmp/nginx/nginx-1.9.5]# yum -y install pcre-devel pcre
[root@vps197119 /tmp/nginx/nginx-1.9.5]# adduser -r -s /sbin/nologin -c 'Web' -M www
[root@vps197119 /tmp/nginx/nginx-1.9.5]# ./configure --prefix=/usr/local/nginx/ \
--user=www --group=www \
--error-log-path=/tmp/nginx/error.log \
--http-log-path=/tmp/nginx/access.log \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--with-pcre \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_v2_module \
--with-http_gzip_static_module \
--with-http_stub_status_module \
--http-client-body-temp-path=/usr/local/nginx/client/ \
--http-proxy-temp-path=/usr/local/nginx/proxy/ \
--http-fastcgi-temp-path=/usr/local/nginx/fcgi/ \
--http-uwsgi-temp-path=/usr/local/nginx/uwsgi \
--http-scgi-temp-path=/usr/local/nginx/scgi
[root@vps197119 /tmp/nginx/nginx-1.9.5]# make -j $(awk '/processor/{i++}END{print i}' /proc/cpuinfo) && make install && cd ../..
[root@vps197119 /tmp]#  echo "export PATH=/usr/local/nginx/sbin:\$PATH" > /etc/profile.d/nginx.sh
[root@vps197119 /tmp]# . /etc/profile.d/nginx.sh
[root@vps197119 /tmp]# wget http://www.dwhd.org/script/Nginx-init-CentOS -O /etc/rc.d/init.d/nginx
[root@vps197119 /tmp]# chmod +x /etc/rc.d/init.d/nginx
[root@vps197119 /tmp]# chkconfig nginx on
[root@vps197119 /tmp]# nginxCONF=/usr/local/nginx/conf/nginx.conf
[root@vps197119 /tmp]# sed "$(awk '{a=NR}END{print a}' $nginxCONF)s@^@    include vhost/*.conf;\n&@" $nginxCONF
[root@vps197119 /tmp]# mkdir -p /usr/local/nginx/conf/vhost/
[root@vps197119 /tmp]# mkdir -p /var/log/nginx/
[root@vps197119 /tmp]# wget https://gitlab.com/gitlab-org/gitlab-ce/raw/master/lib/support/nginx/gitlab -O /usr/local/nginx/conf/vhost/git.dwhd.org.conf
[root@vps197119 /tmp]# usermod -a -G git www
[root@vps197119 /tmp]# cmake --version
cmake version 3.3.2

CMake suite maintained and supported by Kitware (kitware.com/cmake).
[root@vps197119 /tmp]# mysql -V
mysql  Ver 15.1 Distrib 10.0.21-MariaDB, for Linux (x86_64) using readline 5.1
[root@vps197119 /tmp]# redis-cli -s /var/run/redis/redis.sock <<< "info" | grep 'redis.version'
redis_version:3.0.4
[root@vps197119 /tmp]# nginx -v
nginx version: nginx/1.9.5
[root@vps197119 /tmp]#

Nginx配置文件参考

[root@vps197119 /tmp]# grep -Ev '^(\s+)?(#|$)' /usr/local/nginx/conf/vhost/git.dwhd.org.conf
upstream gitlab {
  server unix:/home/git/gitlab/tmp/sockets/gitlab.socket fail_timeout=0;
}
server {
  listen 0.0.0.0:80 default_server;
  server_name git.dwhd.org; ## Replace this with something like gitlab.example.com
  server_tokens off; ## Don't show the nginx version number, a security best practice
  root /home/git/gitlab/public;
  client_max_body_size 256m;
  access_log  /var/log/nginx/gitlab_access.log;
  error_log   /var/log/nginx/gitlab_error.log;
  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    Host                $http_host;
    proxy_set_header    X-Real-IP           $remote_addr;
    proxy_set_header    X-Forwarded-For     $proxy_add_x_forwarded_for;
    proxy_set_header    X-Forwarded-Proto   $scheme;
    proxy_set_header    X-Frame-Options     SAMEORIGIN;
    proxy_pass http://gitlab;
  }
}

Linux之CentOS 6或者CentOS 7上全编译安装GitLab 8-1中文版

24、修改sudo配置

[root@vps197119 /tmp]# chmod u+w /etc/sudoers
[root@vps197119 /tmp]# sed -ri 's@^(Defaults\s+secure_path\s+=).*@\1 /usr/local/mariadb/bin:/usr/local/nginx/sbin:/usr/local/redis/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin@' /etc/sudoers
[root@vps197119 /tmp]# chmod ugo-w /etc/sudoers

二、安装GitLab

1、GitLab

#使用git用户身份下载gitlab 7-14-zh 中文版
[root@vps197119 /tmp]# cd /home/git/gitlab/
[root@vps197119 /home/git]# sudo -u git -H git clone https://gitlab.com/jieme/gitlab.git -b 7-14-zh gitlab
#8.1中文版
#[root@vps197119 /home/git]# sudo -u git -H git clone https://git.oschina.net/Yxnt/gitlab.git -b 8-1-zh gitlab
#[root@vps197119 /home/git]# sudo -u git -H git clone https://gitlab.com/larryli/gitlab.git -b 8-1-zh gitlab
#验证下载
[root@vps197119 /home/git]# cd /home/git/gitlab/
[root@vps197119 /home/git/gitlab]# sudo -u git -H git branch -va |head -1
* 7-14-zh                    12bbae4 Merge branch '7-14-stable' into 7-14-zh

2、复制GitLab配置文件config/gitlab.yml

[root@vps197119 /home/git/gitlab]# sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml

3、修改gitlab配置文件

####如果你有公网IP可以按照以下方法修改配置文件,如果没有请自行做相关修改
[root@vps197119 /home/git/gitlab]# IPaddress=$(curl -4s curlip.me|awk '{print $2;exit}')
[root@vps197119 /home/git/gitlab]# sudo -u git -H sed -ri "s/^(\s+host:).*/\1 $IPaddress/" config/gitlab.yml
[root@vps197119 /home/git/gitlab]# sudo -u git -H sed -ri "s/^(\s+email_from:).*/\1 GitLab@dwhd.org/" config/gitlab.yml
####下面的命令是手工修改方法
##[root@vps197119 /home/git/gitlab]# sudo -u git -H editor config/gitlab.yml
#如下是修改后的参考
[root@vps197119 /home/git/gitlab]# grep -Ev '^(\s+)?(#|$)' config/gitlab.yml
production: &base
  gitlab:
    host: 0.0.0.0
    port: 80 # Set to 443 if using HTTPS, see installation.md#using-https for additional HTTPS configuration details
    https: false # Set to true if using HTTPS, see installation.md#using-https for additional HTTPS configuration details
    email_enabled: false
    email_from: GitLab@dwhd.org
    email_display_name: GitLab
    email_reply_to: noreply@example.com
    default_theme: 2
    default_projects_features:
      issues: true
      merge_requests: true
      wiki: true
      snippets: false
  gravatar:
    enabled: true                 # Use user avatar image from Gravatar.com (default: true)
  ldap:
    enabled: false
    servers:
      main: # 'main' is the GitLab 'provider ID' of this LDAP server
        label: 'LDAP'
        host: '_your_ldap_server'
        port: 389
        uid: 'sAMAccountName'
        method: 'plain' # "tls" or "ssl" or "plain"
        bind_dn: '_the_full_dn_of_the_user_you_will_bind_with'
        password: '_the_password_of_the_bind_user'
        active_directory: true
        allow_username_or_email_login: false
        block_auto_created_users: false
        base: ''
        user_filter: ''
  omniauth:
    enabled: false
    allow_single_sign_on: false
    block_auto_created_users: true
    auto_link_ldap_user: false
    providers:
  satellites:
    path: /home/git/gitlab-satellites/
    timeout: 30
  backup:
    path: "tmp/backups"   # Relative paths are relative to Rails.root (default: tmp/backups/)
  gitlab_shell:
    path: /home/git/gitlab-shell/
    repos_path: /home/git/repositories/
    hooks_path: /home/git/gitlab-shell/hooks/
    upload_pack: true
    receive_pack: true
  git:
    bin_path: /usr/bin/git
    max_size: 20971520 # 20.megabytes
    timeout: 10
  extra:
  rack_attack:
    git_basic_auth:
development:
  <<: *base
test:
  <<: *base
  gravatar:
    enabled: true
  gitlab:
    host: localhost
    port: 80
  satellites:
    path: tmp/tests/gitlab-satellites/
  backup:
    path: tmp/tests/backups
  gitlab_shell:
    path: tmp/tests/gitlab-shell/
    repos_path: tmp/tests/repositories/
    hooks_path: tmp/tests/gitlab-shell/hooks/
  issues_tracker:
    redmine:
      title: "Redmine"
      project_url: "http://redmine/projects/:issues_tracker_id"
      issues_url: "http://redmine/:project_id/:issues_tracker_id/:id"
      new_issue_url: "http://redmine/projects/:issues_tracker_id/issues/new"
  ldap:
    enabled: false
    servers:
      main:
        label: ldap
        host: 127.0.0.1
        port: 3890
        uid: 'uid'
        method: 'plain' # "tls" or "ssl" or "plain"
        base: 'dc=example,dc=com'
        user_filter: ''
        group_base: 'ou=groups,dc=example,dc=com'
        admin_group: ''
        sync_ssh_keys: false
staging:
  <<: *base

4、给目录log/和tmp/ git用户有写权限

[root@vps197119 /home/git/gitlab]# chown -R git {log,tmp}/
[root@vps197119 /home/git/gitlab]# chmod -R u+rwX {log,tmp}/

5、创建satellites目录并设置权限

[root@vps197119 /home/git/gitlab]# sudo -u git -H mkdir /home/git/gitlab-satellites
[root@vps197119 /home/git/gitlab]# chmod u+rwx,g=rx,o-rwx /home/git/gitlab-satellites

6、给tmp/pids、tmp/sockets以及public/uploads/目录 git用户有写权限

[root@vps197119 /home/git/gitlab]# chmod -R u+rwX tmp/pids/
[root@vps197119 /home/git/gitlab]# chmod -R u+rwX tmp/sockets/
[root@vps197119 /home/git/gitlab]# chmod -R u+rwX public/uploads
#确认权限
[root@vps197119 /home/git/gitlab]# ls -ld tmp/pids/ tmp/sockets/ public/uploads
drwxr-xr-x 2 git git 4096 Oct  1 01:19 public/uploads
drwxr-xr-x 2 git git 4096 Oct  1 01:19 tmp/pids/
drwxr-xr-x 2 git git 4096 Oct  1 01:19 tmp/sockets/

7、从模版拷贝出Unicorn配置文件

[root@vps197119 /home/git/gitlab]# sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb

8、如果你负载比较大请启用集群模式

[root@vps197119 /home/git/gitlab]# sudo -u git -H sed -ri "s/^(worker_processes ).*/\1 $(nproc)/" config/unicorn.rb #绑定cpu
[root@vps197119 /home/git/gitlab]# sudo -u git -H sed -ri "s/^(timeout ).*/\1 300/" config/unicorn.rb

9、从模版拷贝出Rack attack配置文件

[root@vps197119 /home/git/gitlab]# sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb

10、为git用户做全局配置

# Edit user.email according to what is set in gitlab.yml
[root@vps197119 /home/git/gitlab]# sudo -u git -H git config --global user.name "GitLab"
[root@vps197119 /home/git/gitlab]# sudo -u git -H git config --global user.email "gitlab@dwhd.org"
[root@vps197119 /home/git/gitlab]# sudo -u git -H git config --global core.autocrlf input

11、配置redis的连接

[root@vps197119 /home/git/gitlab]# sudo -u git -H cp config/resque.yml.example config/resque.yml
#修改为socket连接方式
[root@vps197119 /home/git/gitlab]# sudo -u git -H sed -ri "s@^(development:).*@\1 unix:/var/run/redis/redis.sock@" config/resque.yml

12、配置Gitlab 数据库设置

[root@vps197119 /home/git/gitlab]# sudo -u git cp config/database.yml.mysql config/database.yml
[root@vps197119 /home/git/gitlab]# sudo -u git -H editor config/database.yml
修改为正确的用户名和密码
分别修改git用户和root用户
[root@vps197119 /home/git/gitlab]# sudo -u git -H chmod o-rwx config/database.yml

Linux之CentOS 6或者CentOS 7上全编译安装GitLab 8-1中文版

13、安装Gems

[root@vps197119 /home/git/gitlab]# sudo -u git -H bundle install --deployment --without development test postgres aws
##如果是国内服务器安装请修改为淘宝的ruby源
##[root@vps197119 /home/git/gitlab]# sed -ri 's@^(source ).*@\1"https://ruby.taobao.org"@' Gemfile

Linux之CentOS 6或者CentOS 7上全编译安装GitLab 8-1中文版

14、安装gitlab-shell

[root@vps197119 /home/git/gitlab]# sudo -u git -H bundle exec rake gitlab:shell:install[v$(cat GITLAB_SHELL_VERSION)] REDIS_URL=unix:/var/run/redis/redis.sock RAILS_ENV=production

如果遇到下图中的错误请按照下面的方式做修改

[root@vps197119 /home/git/gitlab]# sudo -u git -H bundle exec rake gitlab:shell:install[v$(cat GITLAB_SHELL_VERSION)] REDIS_URL=unix:/var/run/redis/redis.sock RAILS_ENV=production
/home/git/gitlab/vendor/bundle/ruby/2.2.0/gems/rouge-1.9.1/lib/rouge/lexers/shell.rb:20: warning: already initialized constant Rouge::Lexers::Shell::KEYWORDS
/home/git/gitlab/vendor/bundle/ruby/2.2.0/gems/rouge-1.9.1/lib/rouge/lexers/shell.rb:20: warning: previous definition of KEYWORDS was here
/home/git/gitlab/vendor/bundle/ruby/2.2.0/gems/rouge-1.9.1/lib/rouge/lexers/shell.rb:25: warning: already initialized constant Rouge::Lexers::Shell::BUILTINS
/home/git/gitlab/vendor/bundle/ruby/2.2.0/gems/rouge-1.9.1/lib/rouge/lexers/shell.rb:25: warning: previous definition of BUILTINS was here

Linux之CentOS 6或者CentOS 7上全编译安装GitLab 8-1中文版

sed -i '43s/ load / require /' /home/git/gitlab/vendor/bundle/ruby/2.*/gems/rouge-1.9.1/lib/rouge.rb
sed -i '436,438d' /home/git/gitlab/vendor/bundle/ruby/2.*/gems/rouge-1.9.1/lib/rouge/lexer.rb
sed -i '435s/module Lexers.*/&\n    def self.require_lexer(relpath)/' /home/git/gitlab/vendor/bundle/ruby/2.*/gems/rouge-1.9.1/lib/rouge/lexer.rb
sed -i '438s/.*/      require root.join(relpath)/' /home/git/gitlab/vendor/bundle/ruby/2.*/gems/rouge-1.9.1/lib/rouge/lexer.rb
sed -i "5s/.*/    require_lexer 'c'/" /home/git/gitlab/vendor/bundle/ruby/2.*/gems/rouge-1.9.1/lib/rouge/lexers/cpp.rb
sed -i "5s/.*/    require_lexer 'c'/" /home/git/gitlab/vendor/bundle/ruby/2.*/gems/rouge-1.9.1/lib/rouge/lexers/glsl.rb
sed -i "5s/.*/    require_lexer 'lua'/" /home/git/gitlab/vendor/bundle/ruby/2.*/gems/rouge-1.9.1/lib/rouge/lexers/moonscript.rb
sed -i "5s/.*/    require_lexer 'c'/" /home/git/gitlab/vendor/bundle/ruby/2.*/gems/rouge-1.9.1/lib/rouge/lexers/objective_c.rb
sed -i "5s/.*/    require_lexer 'shell'/" /home/git/gitlab/vendor/bundle/ruby/2.*/gems/rouge-1.9.1/lib/rouge/lexers/powershell.rb
sed -i "5s/.*/    require_lexer 'javascript'\n/" /home/git/gitlab/vendor/bundle/ruby/2.*/gems/rouge-1.9.1/lib/rouge/lexers/qml.rb
sed -i "5s@.*@    require_lexer 'sass/common'@" /home/git/gitlab/vendor/bundle/ruby/2.*/gems/rouge-1.9.1/lib/rouge/lexers/sass.rb
sed -i "5s@.*@    require_lexer 'sass/common'@" /home/git/gitlab/vendor/bundle/ruby/2.*/gems/rouge-1.9.1/lib/rouge/lexers/scss.rb
##上面的几处修改原因见https://github.com/jneen/rouge/commit/0b91f25bedecdffba05300821ef6f1e49334abf7

Linux之CentOS 6或者CentOS 7上全编译安装GitLab 8-1中文版

配置gitlab-shell

[root@vps197119 /home/git/gitlab]# sudo -u git -H editor /home/git/gitlab-shell/config.yml
##配置参考如下
[root@vps197119 /home/git/gitlab]# cat /home/git/gitlab-shell/config.yml
---
user: git
gitlab_url: http://51.254.102.19/
http_settings:
  self_signed_cert: false
repos_path: "/home/git/repositories/"
auth_file: "/home/git/.ssh/authorized_keys"
redis:
  bin: "/usr/local/redis/bin/redis-cli"
  namespace: resque:gitlab
  socket: "/var/run/redis/redis.sock"
log_level: INFO
audit_usernames: false

初始化数据并且激活高级特性

[root@vps197119 /home/git/gitlab]# sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production
[root@vps197119 /home/git/gitlab]# sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production GITLAB_ROOT_PASSWORD=lookback

Linux之CentOS 6或者CentOS 7上全编译安装GitLab 8-1中文版Linux之CentOS 6或者CentOS 7上全编译安装GitLab 8-1中文版
Linux之CentOS 6或者CentOS 7上全编译安装GitLab 8-1中文版Linux之CentOS 6或者CentOS 7上全编译安装GitLab 8-1中文版

安装启动脚本和设置开机启动

[root@vps197119 /home/git/gitlab]# wget -O /etc/init.d/gitlab https://gitlab.com/gitlab-org/gitlab-recipes/raw/master/init/sysvinit/centos/gitlab-unicorn
[root@vps197119 /home/git/gitlab]# chmod +x /etc/init.d/gitlab
[root@vps197119 /home/git/gitlab]# chkconfig gitlab on
[root@vps197119 /home/git/gitlab]# service gitlab start

设置日志滚动

[root@vps197119 /home/git/gitlab]# cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab
[root@vps197119 /tmp]# chmod g+rx /home/git/

检查应用程序状态

[root@vps197119 /home/git/gitlab]# sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production

System information
System:  
Current User:   git
Using RVM:      no
Ruby Version:   2.1.6p336
Gem Version:    2.2.3
Bundler Version:1.10.6
Rake Version:   10.4.2
Sidekiq Version:3.3.0

GitLab information
Version:        7.14.3
Revision:       12bbae4
Directory:      /home/git/gitlab
DB Adapter:     mysql2
URL:            http://51.254.102.19
HTTP Clone URL: http://51.254.102.19/some-group/some-project.git
SSH Clone URL:  git@51.254.102.19:some-group/some-project.git
Using LDAP:     no
Using Omniauth: no

GitLab Shell
Version:        2.6.5
Repositories:   /home/git/repositories/
Hooks:          /home/git/gitlab-shell/hooks/
Git:            /usr/bin/git
[root@vps197119 /home/git/gitlab]# 

Linux之CentOS 6或者CentOS 7上全编译安装GitLab 8-1中文版

Linux之CentOS 6或者CentOS 7上全编译安装GitLab 8-1中文版
一起都好了之后看看web
Linux之CentOS 6或者CentOS 7上全编译安装GitLab 8-1中文版

Linux之CentOS 6或者CentOS 7上全编译安装GitLab 8-1中文版

Linux之CentOS 6或者CentOS 7上全编译安装GitLab 8-1中文版

lookback

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: