搭建git服务器之一:Gitlab

Gitlab适合内网开发,可以通过web界面方便地进行权限管理、代码审查等等;而gitosis可以搭建线上发布代码库,放在外网服务器上。


新发现了一个更方便安装的git服务器,用go开发的Gogs,官网是https://gogs.io/

参考github:

https://github.com/mattias-ohlsson/gitlab-installer/blob/master/gitlab-install-el6.sh
https://github.com/lubia/gitlab-recipes/tree/master/install/centos

  • 安装依赖包
rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
yum update
yum -y groupinstall 'Development Tools'
yum -y install vim-enhanced readline readline-devel ncurses-devel cmagdbm-devel glibc-devel tcl-devel openssl-devel curl-devel expat-devel db4-devel byacc sqlite-devel gcc-c++ libyaml libyaml-devel libffi libffi-devel libxml2 libxml2-devel libxslt libxslt-devel libicu libicu-devel system-config-firewall-tui python-devel redis sudo wget crontabs logwatch logrotate perl-Time-HiRes

yum -y install patch gcc-c++ readline-devel zlib-devel libffi-devel libicu-devel openssl-devel make autoconf automake libtool bison libxml2-devel libxslt-devel libyaml-devel postfix redis mysql-server mysql-devel nginx
  • 启动redis
chkconfig redis on
service redis start
  • 安装git, 这里采用源码编译安装
yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel
yum remove git
yum install perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker 
cd git-xxx
make prefix=/usr/local all
make prefix=/usr/local install
  • git使用前配置
git config --global user.name  "git"
git config --global user.email xxxxxxxxxxx
git config --global core.editor vim
git config --global merge.tool vimdiff
git config --global core.autocrlf input

若要使用gitk则必需安装tk软件包

  • 因为Gitlab是基于ROR开发,所以必须安装配置Ruby运行环境
#安装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 install
#配置ruby淘宝源
 gem sources #显示gem源
 gem sources -a  http://ruby.taobao.org/  #增加淘宝源
 gem sources -r  http://rubygems.org/  #移除官方源
 gem sources -u #更新缓存
gem install bundler --no-ri --no-rdoc
gem install charlock_holmes -v '0.6.9.4'
  • 添加用户
adduser --system --shell /bin/bash --comment 'GitLab' --create-home --home-dir /home/git/ git
su - git
git clone https://github.com/gitlabhq/gitlab-shell.git
cd gitlab-shell
git checkout v1.8.0
cp config.yml.example config.yml
# Edit config and replace gitlab_url with something like 'http://domain.com/'
./bin/install
  • 启动MySQL
  • 创建数据库表
CREATE USER 'gitlab'@'localhost' IDENTIFIED BY 'xxxxxx';
CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
SET storage_engine=INNODB;
GRANT all ON `gitlabhq_production`.* TO 'gitlab'@'localhost';
  • 准备安装
su - git
git clone https://github.com/gitlabhq/gitlabhq.git gitlab
cd ~/gitlab
git checkout 6-4-stable
cp config/gitlab.yml.example config/gitlab.yml
sed -i 's|localhost|your.domain.com|g' config/gitlab.yml
chown -R git log/
chown -R git tmp/
chmod -R u+rwX  log/
chmod -R u+rwX  tmp/
mkdir ~/gitlab-satellites
mkdir tmp/pids/
mkdir tmp/sockets/
chmod -R u+rwX  tmp/pids/
chmod -R u+rwX  tmp/sockets/
mkdir public/uploads
chmod -R u+rwX  public/uploads
cp config/unicorn.rb.example config/unicorn.rb
vim config/unicorn.rb
# Ex. change amount of workers to 3 for 2GB RAM server
cp config/database.yml{.mysql,}
vim config/database.yml
#开始安装:
vim Gemfile Gemfile.lock
#修改源为http://ruby.taobao.org
bundle install --deployment --without development test postgres puma aws

报错 Could not find modernizr-2.6.2 in any of the sources 的解决方法:

wget http://rubygems.org/downloads/modernizr-2.6.2.gem
gem install modernizr

然后将Gemfile和Gemfile.lock配置文件的modernizr版本更改成2.7.1:

vim Gemfile

gem "modernizr" "2.6.2" ===> gem "modernizr-rails", "2.7.1"

vim Gemfile.lock

modernizr (2.6.2) ===> modernizr-rails (2.7.1)

  • 初始化
bundle exec rake gitlab:setup RAILS_ENV=production
bundle exec rake gitlab:env:info RAILS_ENV=production
bundle exec rake gitlab:check RAILS_ENV=production
bundle exec rake assets:precompile RAILS_ENV=production
#安装启动脚本:
cp ~/gitlab/lib/support/init.d/gitlab /etc/init.d/gitlab
chmod +x /etc/init.d/gitlab
chkconfig --add gitlab
  • 配置Nginx
cp lib/support/nginx/gitlab /etc/nginx/conf.d/gitlab.conf
vim /etc/nginx/conf.d/gitlab.conf
# 这一步很重要,否则Nginx无法正常访问/home/git目录下面的文件
usermod -a -G git nginx
service nginx restart
  • 安装完成,登录

    login:
    login………[email protected]
    password……5iveL!fe

  • 配置邮件,让gitlab可以向用户发送各种邮件,这里面用qq邮箱发送为例

cd ~/gitlab/config/initializers
cp smtp_settings.rb.sample smtp_settings.rb
vim smtp_settings.rb
if Rails.env.production?
 Gitlab::Application.config.action_mailer.delivery_method = :smtp

 ActionMailer::Base.smtp_settings = { 
   ssl: true,
   address: "smtp.exmail.qq.com",
   port: 465,
   user_name: "your_user_name",
   password: "your_pass_word",
   domain: "exmail.qq.com",
   authentication: :login,
   enable_starttls_auto: true
 }
end

你可能感兴趣的:(服务器)