yum groupinstall "Development tools" yum install gcc autoconf cmake unzip vim libcurl-devel zlib-devel curl-devel expat-devel gettext-devel openssl-devel perl-devel nodejs libicu-devel wget curl
安装git
若是已经用yum安装过git,而且版本低于2.7.4,要先卸载掉旧的版本前端
yum remove git
使用源码编译安装gitnode
mkdir /tmp/git && cd /tmp/git curl -O --progress https://www.kernel.org/pub/software/scm/git/git-2.10.0.tar.gz tar -xzf git-2.10.0.tar.gz cd git-2.10.0 ./configure make prefix=/usr/local all # 安装到/usr/local/bin make prefix=/usr/local install # 验证git版本号 git --version #查看git安装路径 which git # 编辑 config/gitlab.yml (第5步中), 修改 git 路径为 /usr/local/bin/git
咱们添加一个用来管理运行Gitlab的用户git
mysql
adduser -c 'Gitlab' -s /bin/bash git
# 修改git用户的环境变量PATH,以root用户运行 visudo # 找到下面一行 Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin #修改成 Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:
在Gitlab生产环境使用Ruby版本管理工具RVM,rbenv或者chruby经常会带来不少疑难杂症.好比Gitlab-shell版本管 理器调用OpenSSH的功能以防止越过ssh对仓库进行pull和push操做.而前面提到的三个版本管理器不支持这样的功能,因此咱们强烈建议你们按 照下面的方式来安装Ruby.linux
yum remove ruby
mkdir /tmp/ruby && cd /tmp/ruby curl -O --progress https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.1.tar.gz tar xzf ruby-2.3.1.tar.gz cd ruby-2.3.1 ./configure --disable-install-rdoc make && make install
# 修改git用户gem安装源为中科大源 $ gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/ # 确保git用户当前gems源为中科大源 $ gem sources -l *** CURRENT SOURCES *** https://gems.ruby-china.org/
gem install bundler --no-ri --no-rdoc # 修改bundler的源为中科大源 sudo -u git -H bundle config mirror.https://rubygems.org https://gems.ruby-china.org/
从Gitlab8.0开始,Git的HTTP请求由gitlab-git-http-server来处理.咱们须要Go编译器来安装gitlab-git-http-server.下面一系列的指令都将假定你用的是64位的Linux系统.你也能够在GoLang官方网站下载其余平台的Go编译器.nginx
$ mkdir /tmp/go && cd /tmp/go $ curl -O --progress http://www.golangtc.com/static/go/1.6.2/go1.6.2.linux-amd64.tar.gz $ tar -C /usr/local -xzf go1.6.2.linux-amd64.tar.gz $ sudo ln -sf /usr/local/go/bin/{go,godoc,gofmt} /usr/local/bin/ $ rm go1.6.2.linux-amd64.tar.gz #验证go是否安装正确 $ go version go version go1.6.2 linux/amd64
Gitlab官方建议咱们用PostgreSQL数据库.若是喜欢用Mysql请前往Gitlab使用Mysql数据库的安装说明.git
略过golang
版本要求: redis版本不低于2.8.web
添加redis用户和组redis
groupadd redis && useradd -g redis redis -s /sbin/nologin
mkdir /tmp/redis && cd /tmp/redis #这里是最新的 curl -O --progress http://download.redis.io/releases/redis-stable.tar.gz tar zxf redis-stable.tar.gz cd redis-stable make && make install mkdir -p /etc/redis cp redis.conf /etc/redis
cp /etc/redis/redis.conf /etc/redis/redis.conf.orig # 把'post'设置为0以禁止监听TCP端口 sed 's/^port .*/port 0/' /etc/redis/redis.conf.orig | sudo tee /etc/redis/redis.conf # 让redis以socket方式启动 echo 'unixsocket /var/run/redis/redis.sock' | sudo tee -a /etc/redis/redis.conf # 启动守护进程 sed -i 's/daemonize no/daemonize yes/g' /etc/redis/redis.conf # 建立存放socket的目录 mkdir /var/run/redis sudo chown redis:redis /var/run/redis sudo chmod 755 /var/run/redis # Persist the directory which contains the socket, if applicable if [ -d /etc/tmpfiles.d ]; then echo 'd /var/run/redis 0755 redis redis 10d -' | sudo tee -a /etc/tmpfiles.d/redis.conf fi # 把git用户加入redis组 sudo usermod -aG redis git # 下载redis init 脚本 $ curl -L http://packages.gitlab.cc/install/init-script/redis/cenots6/redis-server -o /etc/init.d/redis-server $ chmod +x /etc/init.d/redis-server
# 启动redis服务 $ service redis-server start # 将redis加入自启动 $ chkconfig redis-server on
# 咱们将gitlab安装到git用户的HOME目录 cd /home/git
sudo -u git -H git clone https://gitlab.com/larryli/gitlab.git -b 8-8-zh gitlab
Note: 你能够直接克隆,这样就能够体验到最新的中文版本sql
# 进入gitlab目录 cd /home/git/gitlab # 复制gitlab.yml(Gitlab的主配置文件) sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml # 修改gitlab.yml sudo -u git -H vim config/gitlab.yml ####修改第32行 host: localhost为 host: 你的域名或者ip ####修改第435行 bin_path: /usr/bin/git 为bin_path: /usr/local/bin/git # 复制 secrets 文件 sudo -u git -H cp config/secrets.yml.example config/secrets.yml sudo -u git -H chmod 0600 config/secrets.yml # 修改 log/ 和 tmp/ 文件夹权限 sudo chown -R git log/ sudo chown -R git tmp/ sudo chmod -R u+rwX,go-w log/ sudo chmod -R u+rwX tmp/ # 修改 tmp/pids/ 个 tmp/sockets/ 文件夹权限 sudo chmod -R u+rwX tmp/pids/ sudo chmod -R u+rwX tmp/sockets/ # 建立 public/uploads/ 文件夹 sudo -u git -H mkdir public/uploads/ # 修改 public/uploads/ 文件夹权限,只有git用户有访问权限 # now that files in public/uploads are served by gitlab-workhorse sudo chmod 0700 public/uploads # 修改 CI build traces are stored 文件夹的权限 sudo chmod -R u+rwX builds/ # 修改 CI artifacts are stored 文件夹的权限 sudo chmod -R u+rwX shared/artifacts/ # 复制 Unicorn 配置文件 sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb # 查询CPU核心数 nproc # 若是你想搭建一个高负载的Gitlab实例,可启用集群模式. # 修改'worker_processes'参数,至少要跟cpu核心数同样. # 举例:2G RAM的服务器修改workers数量为3 sudo -u git -H vim config/unicorn.rb # 复制Rack attack 配置文件 sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb # Configure Git global settings for git user # 'autocrlf' is needed for the web editor sudo -u git -H git config --global core.autocrlf input # Disable 'git gc --auto' because GitLab already runs 'git gc' when needed sudo -u git -H git config --global gc.auto 0 # 复制 Redis 链接配置文件 sudo -u git -H cp config/resque.yml.example config/resque.yml # 若是以前修改过redis socket的路径,在这个配置文件里面修改成当前的路径. sudo -u git -H vim config/resque.yml
修改GitLab DB 设置
# 此命令仅针对PostgreSQl: sudo -u git cp config/database.yml.postgresql config/database.yml # 若是使用Mysql,执行下面命令 sudo -u git cp config/database.yml.mysql config/database.yml #host,socket有必要能够本身修改 # 如下修改针对MySQL和远程PostgreSQL: # 修改username/password. # 生产环境只须要修改第一部分便可. # 修改'secure password' 为你设置的密码 # 密码字段可使用"双引号" sudo -u git -H vim config/database.yml # PostgreSQL MySQL都适用: # 修改database.yml的权限,确保git用户能够读取该文件. sudo -u git -H chmod o-rwx config/database.yml
这个步骤是不少新手头疼的问题,不过你只要严格按照本文关于Ruby环境的搭建来作.仍是能够保证你顺利的安装下来的.
Note: 自bundler1.5.2起,你可使用bundle install -jN(N就是cpu核心数)安装Gems,速度比以前要快大约60%.详细的内容能够点此处查看.不过首先要确保你的bundler版本>=1.5.2(运行bundle -v查看).
#若是是mysql首先执行 yum install mysql-devel ####必定要注意选择本身用的数据库的命令 # PostgreSQL (note, the option says "without ... mysql") sudo -u git -H bundle install --deployment --without development test mysql aws kerberos # 若是使用 MySQL,执行下面的命令 (note, the option says "without ... postgres") sudo -u git -H bundle install --deployment --without development test postgres aws kerberos #这里可能中间会出错,多执行几回就能够了
GitLab Shell是专为GitLab开发的ssh访问和仓库管理的软件.
# 修改gitlab 安装 gitlab-shell的rake任务脚本 sudo -u git -H sed -i 's/https:\/\/gitlab.com\/gitlab-org\/gitlab-shell.git/https:\/\/git.oschina.net\/qiai365\/gitlab-shell.git/g' /home/git/gitlab/lib/tasks/gitlab/shell.rake # 运行安装gitlab shell的任务 (根据本身的redis安装状况修改`REDIS_URL`),这里若是你事先没有clone gitlab-shell的仓库,就会自动clone官方的仓库进行安装: sudo -u git -H bundle exec rake gitlab:shell:install REDIS_URL=unix:/var/run/redis/redis.sock RAILS_ENV=production # 默认状况下,gitlab-shell的配置是根据Gitlab的配置生产的. # 你能够运行下面的命令查看和修改gitlab-shell的配置: sudo -u git -H vim /home/git/gitlab-shell/config.yml
Note: Make sure your hostname can be resolved on the machine itself by either a proper DNS record or an additional line in /etc/hosts (“127.0.0.1 hostname”). This might be necessary for example if you set up GitLab behind a reverse proxy. If the hostname cannot be resolved, the final installation check will fail with “Check GitLab API access: FAILED. code: 401” and pushing commits will be rejected with “[remote rejected] master -> master (hook declined)”.
安装成功如图所示:
cd /home/git sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-workhorse.git cd gitlab-workhorse sudo -u git -H git checkout 0.7.2 sudo -u git -H make
cd /home/git/gitlab sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production # 输入 'yes' 以建立数据库表 # 当看到 'Administrator account created:' 表示已经安装完成 #在执行时可能最后会出错 #You have 1 pending migration: # 20160516174813 AddSendUserConfirmationEmailToApplicationSettings #Run `rake db:migrate` to update your database then try again. 此能够执行下面语句 sudo -u git -H bundle exec rake db:migrate RAILS_ENV=production 而后再从新执行 sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production #这里注意redis.socket权限问题
secrets.yml
文件为每一个会话和安全变量存储密钥.把这个文件备份到别的地方,可是不要和数据库备份放在一块,不然你的数据库备份损坏会致使这个文件丢失.
sudo cp lib/support/init.d/gitlab /etc/init.d/gitlab #复制下面这个配置文件,若是你的gitlab不是安装在/home/git/gitlab目录,根据本身状况修改这个文件。 sudo cp lib/support/init.d/gitlab.default.example /etc/default/gitlab
设置GItlab为自启动
chkconfig gitlab on
sudo cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab
sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production
效果如图
sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production
sudo service gitlab start # 或者 sudo /etc/init.d/gitlab restart
sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production # 若是上面的检查有错误,按照提示修复下,再重启GitLab便可
经过修改/home/git/gitlab/config/unicorn.rb
的listen端口,而后重启gitlab服务,就能够直接访问服务器ip加端口来访问gitlab了
# 复制gitlab的nginx配置文件到nginx的conf.d目录 cp /home/git/gitlab/lib/support/nginx/gitlab /etc/nginx/conf.d/gitlab.conf #修改gitlab的nginx配置文件 vim /etc/nginx/conf.d/gitlab.conf 找到server_name YOUR_SERVER_FQDN,将YOUR_SERVER_FQDN修改成你的域名,如demo.gitlab,cc; # 修改/home/git/目录的权限 sudo chmod 755 /home/git/