CentOS

xiaoxiao2021-02-28  132

开始之前请先查看官方的刚需文档: https://github.com/gitlabhq/gitlabhq/blob/master/doc/install/requirements.md ,该文档说明了系统,软件和硬件等各方面的需求。详细的了解这些,可以避免碰到很多怪异的问题。

 

EPEL,即Extra Packages for Enterprise Linux,这个软件仓库里有很多非常常用的软件,而且是专门针对RHEL设计的,对RHEL标准yum源是一个很好的补充,完全免费使用,由 Fedora项目维护,所以如果你使用的是RHEL,或者CentOS,Scientific等RHEL系的linux,可以非常放心的使用EPEL的 yum源。

 

升级操作系统和安装wget

$ sudo yum -y update

$ sudo yum -y install wget

环境

Requirements

软件

版本

CentOS

6.5

Python

2.6

Ruby

2.1.5

Git

1.7.10+

Redis

2.0+

MySQL

 

GitLab

7-8-stable

GitLab Shell

v2.6.0

Gem

2.2.2

Bundler

1.11.2

Rake

10.3.2

yum源

为了提高软件安装速度,将yum源设置为阿里云开源镜像

$ cd /etc/yum.repos.d

$ wget -O CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo

必要软件包

$ yum -y install libicu-devel patch gcc-c++ readline-devel zlib-devel libffi-devel openssl-devel make 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

// 查看当前git版本

$ git --version

 

// 如果小于1.7.10则先卸载

$ yum remove git

 

// 下载最新的git并安装

$ wget -O git-src.zip https://github.com/git/git/archive/master.zip

$ 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环境

$ mkdir /tmp/ruby && cd /tmp/ruby

$ curl --progress ftp://ftp.ruby-lang.org/pub/ruby/ruby-2.1.5.tar.gz | tar xz

$ 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

$ ln -s /usr/local/bin/bundle /usr/bin/bundle

 

// 设置ruby gem源为淘宝

$ gem source -r https://rubygems.org/

$ gem source -a https://ruby.taobao.org/

 

$ gem install bundler --no-ri --no-rdoc

安装MySQL及初始化GitLab

$ yum install mysql mysql-devel mysql-server -y

$ /etc/init.d/mysqld start

$ chkconfig mysqld on

// 登录mysql创建gitab的帐号和数据库

mysql> CREATE USER 'gitlab'@'localhost' IDENTIFIED BY 'gitlab';

mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;

mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'localhost';

//测试是否可以用git帐号登录数据库

sudo -u git -H mysql -u gitlab -p -D gitlabhq_production

安装Redis

$ yum -y install redis

$ /etc/init.d/redis start

$ chkconfig redis on

添加git帐号并允许sudo

$ useradd --comment 'GitLab' git

$ echo "git ALL=(ALL)       NOPASSWD: ALL" >>/etc/sudoers

安装GitLab

$ cd /home/git

$ sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 7-8-stable gitlab

$ cd /home/git/gitlab

//显示ruby-2.1.5 is not installed.需要运行rvm install ruby-2.1.5

$ sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml

 

// 编辑git路径, gitlab的host:port

$ vim config/gitlab.yml

bin_path: /usr/local/bin/git

host:192.168.56.101

port:80 

 

// 给文件夹添加相应的权限

$ 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 -u git -H mkdir tmp/pids/

$ sudo -u git -H mkdir tmp/sockets/

$ sudo chmod -R u+rwX  tmp/pids/

$ sudo chmod -R u+rwX  tmp/sockets/

$ sudo -u git -H mkdir public/uploads

$ sudo chmod -R u+rwX  public/uploads

$ sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb

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

 config/initializers/rack_attack.rb

 

// 配置数据库连接信息

$ sudo -u git cp config/database.yml.mysql config/database.yml

$ sudo -u git -H vim  config/database.yml

$ vim config/database.yml

production:

     username: gitlab

     password: "gitlab"

安装GitLab-Shell

$ cd /home/git

$ sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-shell.git -b v2.6.0

$ cd gitlab-shell/

$ sudo -u git -H cp config.yml.example config.yml

 

// 编辑配置文件, 设置gitlab_url, redis-cli, log-level...

$ vim config.yml

//前头不能有空格,ip和端口必须和上边的GitLab设置一样。否则git clone项目发生错误(协议异常错误)

gitlab_url:"http://192.168.56.101:80/"

// redis设置

redis:

  bin: /usr/bin/redis-cli

  host: 192.168.56.101

  port: 6379

  # pass: redispass # Allows you to specify the password for Redis

  database: 0

  #socket: /var/run/redis/redis.sock # Comment out this line if you want to use TCP

  namespace: resque:gitlab

 

// 安装git-shell

$ sudo -u git -H ./bin/install

安装需要rubygems

$ cd /home/git/gitlab

//需要修改Gemfile以及Gemfile.lock

//Gemfile中,修改source "https://rubygems.org/"变为source "http://ruby.taobao.org/"

//Gemfile.lock中,修改remote: https://rubygems.org/变为remote: http://ruby.taobao.org/

$ gem install bundler --no-ri --no-rdoc

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

//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.

//发生上边的错误,需要手动安装的gem ,手动安装,然后继续执行上面的bundle install

$ sudo yum -y install cmake

$ sudo gem install rugged -v '0.21.4'

$ bundle install

 

初始化数据库(创建GitLab相关表)

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

安装启动文件以及日志切割文件

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帐号信息

$ sudo -u git -H git config --global user.name "Troy Zhang"

$ sudo -u git -H git config --global user.email "troyz@synnex.com"

$ sudo -u git -H git config --global core.autocrlf input

安装Nginx

$ yum -y install nginx

$ vim /etc/nginx/nginx.conf

user              root git;

worker_processes  2;

pid        /var/run/nginx.pid;

 

events {

    worker_connections  1024;

}

 

http {

    include       /etc/nginx/mime.types;

    default_type  application/octet-stream;

 

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '

                      '$status $body_bytes_sent "$http_referer" '

                      '"$http_user_agent" "$http_x_forwarded_for"';

# GITLAB

# Maintainer: @randx

# App Version: 5.0

 

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 192.168.56.101:8080;     # 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;

 

  # Set value of client_max_body_size to at least the value of git.max_size in gitlab.yml

  client_max_body_size 5m;

 

  # individual nginx logs for this gitlab vhost

  access_log  /var/log/nginx/gitlab_access.log;

  error_log   /var/log/nginx/gitlab_error.log;

 

  location / {

    # serve static files from defined root folder;.

    # @gitlab is a named location for the upstream fallback, see below

    try_files $uri $uri/index.html $uri.html @gitlab;

  }

 

  # if a file, which is not found in the root folder is requested,

  # then the proxy pass the request to the upsteam (gitlab unicorn)

  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;

  }

}

}

更改权限,启动nginx

$ nginx -t

$ chown -R git:git /var/lib/nginx/

$ /etc/init.d/nginx start

检测当前环境

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

拉取gitlab静态资源文件

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

启动gitlab

$ /etc/init.d/gitlab start

检测各个组件是否正常工作

$ sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production

//如果组件有问题,照着命令行的日志修改即可。

 

 

注意事项:如果是win7主机不能访问虚拟机的centos下的gitlab,则需要配置防火墙。

 

配置防火墙iptables,使用户可以访问httphttpsssh的端口。

$ lokkit -s http -s https -s ssh

重新启动防火墙

$ service iptables restart

至此就算安装完成了。

默认的管理员账号:

admin@example.com

5iveL!fe

转载请注明原文地址: https://www.6miu.com/read-46507.html

最新回复(0)