Git是一个分布式版本控制/软件配置管理软件
github是一个基于git的代码托管平台,付费用户可以建私人仓库,我们一般的免费用户只能使用公共仓库,也就是代码要公开。(所以自己搭建一个gitlab)
GitLab,是一个利用 Ruby on Rails 开发的开源应用程序,实现一个自托管的Git项目仓库,可通过Web界面进行访问公开的或者私人项目,它拥有与Github类似的功能,能够浏览源代码,管理缺陷和注释。可以管理团队对仓库的访问,它非常易于浏览提交过的版本并提供一个文件历史库。团队成员可以利用内置的简单聊天程序(Wall)进行交流。它还提供一个代码片段收集功能可以轻松实现代码复用,便于日后有需要的时候进行查找。
参考 https://github.com/gitlabhq/gitlab-recipes/tree/master/install/centos
https://github.com/gitlabhq/gitlabhq/blob/master/doc/install/installation.md //比较全面,比如环境等安装要求
环境:centos 6.3 x86_64 内存最好1G
//表示可以不必执行
1.系统初始化
Add EPEL repository
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
Verify that the key got installed successfully:
//rpm -qa gpg*
Now install the epel-release-6-8.noarch package, which will enable EPEL repository on your system:
rpm -Uvh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
Add PUIAS Computational repository
centos6默认yum安装的git版本是1.7.1,是不兼容gitlab的,至少要1.7.10,可以下git最新版本编译或者
Create /etc/yum.repos.d/PUIAS_6_computational.repo and add the following lines:
[PUIAS_6_computational]
name=PUIAS computational Base $releasever - $basearch
mirrorlist=http://puias.math.ias.edu/data/puias/computational/$releasever/$basearch/mirrorlist
#baseurl=http://puias.math.ias.edu/data/puias/computational/$releasever/$basearch
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-puias
Next download and install the gpg key.
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
Verify that the key got installed successfully:
//rpm -qa gpg*
Verify that the EPEL and PUIAS Computational repositories are enabled as shown below:
yum repolist
If you can't see them listed, use the folowing command (from yum-utils package) to enable them:
//yum-config-manager --enable epel --enable PUIAS_6_computational //启用指定的repos (yum-config-manager is part of the yum-utils)
Install the required tools for GitLab
//yum -y update
yum -y groupinstall 'Development Tools'
yum -y install vim-enhanced readline readline-devel ncurses-devel gdbm-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 python-devel redis sudo \
wget crontabs logwatch logrotate perl-Time-HiRes git
RHEL Notes
If some packages (eg. gdbm-devel, libffi-devel and libicu-devel) are NOT installed, add the rhel6 optional packages repo to your server to get those packages:
yum-config-manager --enable rhel-6-server-optional-rpms
Configure redis
Make sure redis is started on boot:
chkconfig redis on
service redis start
Configure sendmail
未配置
2. Ruby
Download and compile it:
mkdir /tmp/ruby && cd /tmp/ruby
wget -c http://ruby.taobao.org/mirrors/ruby/ruby-2.1.0.tar.gz
tar zxvf ruby-2.0.0-p353.tar.gz
cd ruby-2.0.0-p353/
./configure --prefix=/usr/local/
make && make install
Install the Bundler Gem:
gem install bundler --no-ri --no-rdoc
3. System Users
Create user for Git
adduser --system --shell /bin/bash --comment 'GitLab' --create-home --home-dir /home/git/ git
We do NOT set the password so this user cannot login.
Forwarding all emails
未配置
4. GitLab shell
GitLab Shell is a ssh access and repository management software developed specially for GitLab.
# Login as git
su - git
# Clone gitlab shell
git clone https://github.com/gitlabhq/gitlab-shell.git
cd gitlab-shell
# Switch to right version
git checkout v1.8.0
cp config.yml.example config.yml
# Edit config and replace gitlab_url with something like 'http://domain.com/'
#
# Note, 'gitlab_url' is used by gitlab-shell to access GitLab API. Since
# 1. the whole communication is locally
# 2. next steps will explain how to expose GitLab over HTTPS with custom cert
# it's a good solution is to set gitlab_url as "http://localhost:8080/"
# Do setup
./bin/install
5. Database
这里我使用的是mysql
yum install -y mysql-server mysql-devel
chkconfig mysqld on
service mysqld start
Secure MySQL by entering a root password and say "Yes" to all questions:
/usr/bin/mysql_secure_installation
Create a new user and database for GitLab:
# Login to MySQL
mysql -u root -p
# Type the database root password
# Create a user for GitLab. (change supersecret to a real password)
CREATE USER 'gitlab'@'localhost' IDENTIFIED BY 'supersecret';
# Create the GitLab production database
CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
# Grant the GitLab user necessary permissopns on the table.
GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'localhost';
退出来用新建的用户登录测试下
6. GitLab
su - git
Clone the Source
# Clone GitLab repository
git clone https://github.com/gitlabhq/gitlabhq.git gitlab
# Go to gitlab directory
cd /home/git/gitlab
# Checkout to stable release
git checkout 6-4-stable
Configure it
# Copy the example GitLab config
cp config/gitlab.yml.example config/gitlab.yml
# Replace your_domain_name with the fully-qualified domain name of your host serving GitLab
sed -i 's|localhost|your_domain_name|g' config/gitlab.yml
# Make sure GitLab can write to the log/ and tmp/ directories
chown -R git log/
chown -R git tmp/
chmod -R u+rwX log/
chmod -R u+rwX tmp/
# Create directory for satellites
mkdir /home/git/gitlab-satellites
# Create directories for sockets/pids and make sure GitLab can write to them
mkdir tmp/pids/
mkdir tmp/sockets/
chmod -R u+rwX tmp/pids/
chmod -R u+rwX tmp/sockets/
# Create public/uploads directory otherwise backup will fail
mkdir public/uploads
chmod -R u+rwX public/uploads
# Copy the example Unicorn config
cp config/unicorn.rb.example config/unicorn.rb
# Enable cluster mode if you expect to have a high load instance
# E.g. change amount of workers to 3 for 2GB RAM server
vi config/unicorn.rb //timeout 120
# Configure Git global settings for git user, useful when editing via web
# Edit user.email according to what is set in gitlab.yml
git config --global user.name "GitLab"
git config --global user.email "gitlab@your_domain_name"
git config --global core.autocrlf input
Important: Make sure to edit both gitlab.yml and unicorn.rb to match your setup.
vi config/gitlab.yml
## GitLab settings
gitlab:
## Web server settings
host: localhost
port: 80
https: true
port: 443
Configure GitLab DB settings
# MySQL
cp config/database.yml{.mysql,}
Make config/database.yml readable to git only
chmod o-rwx config/database.yml
vi config/database.yml
production:
adapter: mysql2
encoding: utf8
reconnect: false
database: gitlabhq_production
pool: 10
username: gitlab
password: "supersecret"
# host: localhost
# socket: /tmp/mysql.sock
Install Gems
su -
gem install charlock_holmes --version '0.6.9.4'
exit
For MySQL (note, the option says "without ... postgres"):
cd /home/git/gitlab/ //vi Gemfile 淘宝源
bundle install --deployment --without development test postgres puma aws
Initialize Database and Activate Advanced Features
bundle exec rake gitlab:setup RAILS_ENV=production //yes
Administrator account created:
login.........admin@local.host
password......5iveL!fe
Install Init Script
Download the init script (will be /etc/init.d/gitlab):
su -
wget -O /etc/init.d/gitlab https://raw.github.com/gitlabhq/gitlab-recipes/master/init/sysvinit/centos/gitlab-unicorn
chmod +x /etc/init.d/gitlab
chkconfig --add gitlab
Make GitLab start on boot:
chkconfig gitlab on
Check Application Status
Check if GitLab and its environment are configured correctly:
cd gitlab/
bundle exec rake gitlab:env:info RAILS_ENV=production
Start your GitLab instance:
service gitlab start
Double-check Application Status
To make sure you didn't miss anything run a more thorough check with:
su - git
cd gitlab/
bundle exec rake gitlab:check RAILS_ENV=production //没事多检测
7. Configure the web server
Use either Nginx or Apache, not both. Official installation guide recommends nginx.
Nginx
su -
yum -y install nginx
chkconfig nginx on
mkdir /etc/nginx/sites-{available,enabled}
wget -O /etc/nginx/sites-available/gitlab https://raw.github.com/gitlabhq/gitlab-recipes/master/web-server/nginx/gitlab-ssl
ln -sf /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab
Edit /etc/nginx/nginx.conf and replace include /etc/nginx/conf.d/*.conf; with include /etc/nginx/sites-enabled/*;
Edit /etc/nginx/sites-available/gitlab and replace git.example.com with your FQDN.
Add nginx user to git group.
usermod -a -G git nginx
chmod g+rx /home/git/
Note: Don't forget to add a SSL certificate or generate a Self Signed Certificate
cd /etc/nginx
openssl req -new -x509 -nodes -days 3560 -out gitlab.crt -keyout gitlab.key
Finally start nginx with:
service nginx start
注意:
添加淘宝源可能更快点
gem sources --remove https://rubygems.org/
gem sources -a http://ruby.taobao.org/
vi /home/git/gitlab/Gemfile //首行替换
问题一:
You are trying to install in deployment mode after changing
your Gemfile. Run `bundle install` elsewhere and add the
updated Gemfile.lock to version control.
You have added to the Gemfile:
* gon (~> 5.0.0)
You have deleted from the Gemfile:
* gon
You have changed in the Gemfile:
* gon from `no specified source` to `rubygems repository https://rubygems.org/`
vi /home/git/gitlab/Gemfile.lock gon! 替换 gon (~> 5.0.0)
问题二:
使用nginx做http server时,访问出现502 bad gateway,同时/var/log/nginx/gitlab_error.log显示upstream prematurely closed connection while reading response header from upstream
检查gitlab/log下的unicorn.stderr.log,一般会发现timeout (31s > 30s), killing.原因是第一次访问时,gitlab需要初始化,机器太次时初始化所需时间超过了gitlab/config/unicorn.rb中的timeout,只需调大timeout即可. 【120S/1G内存】
问题三:
Could not find 'bundler' (>= 0) among 9 total gem(s) (Gem::LoadError)
gem install bundle