在 CentOS 6.5 上安装 GitLab
GitLab,是一个利用 Ruby on Rails 开发的开源应用程序,实现一个自托管的Git项目仓库,可通过Web界面进行访问公开的或者私人项目。
它拥有与Github类似的功能,能够浏览源代码,管理缺陷和注释。可以管理团队对仓库的访问,它非常易于浏览提交过的版本并提供一个文件历史库。团队成员可以利用内置的简单聊天程序(Wall)进行交流。它还提供一个代码片段收集功能可以轻松实现代码复用,便于日后有需要的时候进行查找。
系统需求与安装前的准备
添加必要的软件仓库
wget -O /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 https://www.fedoraproject.org/static/0608B895.txt
rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
wget -O /etc/yum.repos.d/PUIAS_6_computational.repo https://gitlab.com/gitlab-org/gitlab-recipes/raw/master/install/centos/PUIAS_6_computational.repo
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 update -y
yum remove git httpd sendmail -y
yum -y install nginx zlib-devel openssl-devel git redis perl-CPAN ncurses-devel gdbm-devel glibc-devel tcl-devel curl-devel byacc db4-devel sqlite-devel libxml2 libxml2-devel libffi libffi-devel libxslt libxslt-devel libyaml libyaml-devel libicu libicu-devel system-config-firewall-tui sudo wget crontabs gettext perl-Time-HiRes cmake gettext-devel readline readline-devel libcom_err-devel.i686 libcom_err-devel.x86_64 expat-devel logwatch logrotate patch
添加 Gitlab 的用户 git
adduser --shell /bin/bash --home-dir /home/git/ git
其它准备工作
编辑 /etc/sudoers 文件,添加 /usr/local/bin 至文件中下面这一行的末端:
Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin
编辑完成后的文件看上去像下面这样的:
Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
安装最新版本的Git
mkdir /tmp/git
cd /tmp/git
wget https://www.kernel.org/pub/software/scm/git/git-2.1.3.tar.gz
tar -xzvf git-2.1.3.tar.gz
cd git-2.1.3/
./configure
make
make prefix=/usr/local install
安装最新版本的 Ruby
mkdir /tmp/ruby
cd /tmp/ruby
wget ftp://ftp.ruby-lang.org/pub/ruby/2.1/ruby-2.1.5.tar.gz
tar -xzvf ruby-2.1.5.tar.gz
cd ruby-2.1.5
./configure --disable-install-rdoc
make
make prefix=/usr/local install
创建 GitLab 使用的数据库
mysql -u root -p
CREATE USER 'git'@'localhost' IDENTIFIED BY 'PaSsWoRd';
CREATE DATABASE `gitlabdb` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
GRANT ALL ON `gitlabdb`.* TO 'git'@'localhost';
安装并配置 redis
yum install redis
编辑 /etc/redis.conf:
port 0
同时添加下面两行:
unixsocket /var/run/redis/redis.sock
unixsocketperm 0775
然后重新启动:
service redis restart
usermod -aG redis git
安装 Gitlab
克隆 gitlab 代码至服务器
cd /home/git
sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 7-4-stable gitlab
cd /home/git/gitlab
sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml
编辑 config/gitlab.yml 配置文件:
sudo -u git -H nano config/gitlab.yml
编辑 config/unicorn.rb 文件:
sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb
sudo -u git -H nano config/unicorn.rb
编辑 config/database.yml 文件:
sudo -u git cp config/database.yml.mysql config/database.yml
sudo -u git -H nano config/database.yml
sudo -u git -H chmod o-rwx config/database.yml
安装 bundlers 与 gems :
gem install bundler
cd /home/git/gitlab
sudo -u git -H bundle install --deployment --without development test postgres aws
sudo -u git -H bundle exec rake gitlab:shell:install[v2.1.0] REDIS_URL=unix:/var/run/redis/redis.sock RAILS_ENV=production
restorecon -Rv /home/git/.ssh
sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production GITLAB_ROOT_PASSWORD=YourPassword
安装 init 脚本:
wget -O /etc/init.d/gitlab https://gitlab.com/gitlab-org/gitlab-recipes/raw/master/init/sysvinit/centos/gitlab-unicorn
chmod +x /etc/init.d/gitlab
chkconfig --add gitlab
设置 logrotate
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
service gitlab start
设置 nginx:
get -O /etc/nginx/conf.d/gitlab.conf https://gitlab.com/gitlab-org/gitlab-ce/raw/master/lib/support/nginx/gitlab-ssl
生成 SSL
mkdir /etc/nginx/ssl
cd /etc/nginx/ssl/
openssl genrsa -des3 -out gitlab.key 1024
openssl req -new -key gitlab.key -out gitlab.csr
cp gitlab.key gitlab.key.org
openssl rsa -in gitlab.key.org -out gitlab.key
openssl x509 -req -days 365 -in gitlab.csr -signkey gitlab.key -out gitlab.crt
评论已关闭