GitLab是利用 Ruby on Rails 一个开源的版本管理系统,实现一个自托管的Git项目仓库,可通过Web界面进行访问公开的或者私人项目。它拥有与Github类似的功能,能够浏览源代码,管理缺陷和注释。可以管理团队对仓库的访问,它非常易于浏览提交过的版本并提供一个文件历史库。团队成员可以利用内置的简单聊天程序(Wall)进行交流。它还提供一个代码片段收集功能可以轻松实现代码复用,便于日后有需要的时候进行查找。在线DEMO
1,安装必要软件包
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
2,安装git
// 查看当前git版本
git --version git version 1.7.1
// 如果小于1.8则先卸载
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/ git version git version 2.6.0.GIT
3,安装ruby
// 下载软件包
wget ftp://ftp.ruby-lang.org/pub/ruby/2.1/ruby-2.1.6.tar.gz
// 安装
tar xvf ruby-2.1.6.tar.gz cd ruby-2.1.6 ./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
// 安装bundle
gem install bundler --no-ri --no-rdoc
// 软连接
ln -s /usr/local/bin/bundle /usr/bin/bundle
4,安装配置mysql
//安装数据库
传送门:https://blog.espnlol.com/?p=82
//配置mysql用户及险关信息,mysql默认没有密码
// 登录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';
5,安装Redis
yum -y install redis /etc/init.d/redis start chkconfig redis on
6,配置gitlab
//创建git账户,配置sudo权限
useradd --comment 'GitLab' git echo "git ALL=(ALL) NOPASSWD: ALL" >>/etc/sudoers
//克隆配置
sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 8-0-stable gitlab cd /home/git/gitlab sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml
// 编辑git路径, gitlab的host:port
$ vim config/gitlab.yml // bin_path: /usr/bin/git // host: $your domain // port: 80 // email: $the send email
// 给文件夹添加相应的权限
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 vim config/database.yml $ vim config/database.yml // production: // username: gitlab // password: "gitlab"
7,安装gitlab-shell
cd /home/git sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-shell.git -b v2.6.5 cd gitlab-shell/ sudo -u git -H cp config.yml.example config.yml
// 编辑配置文件, 设置gitlab_url, redis-cli, log-level…
vim config.yml // gitlab_url: "http://localhost/" // /usr/bin/redis-cli
// 安装git-shell
sudo -u git -H ./bin/install
安装需要ruby的gems
cd /home/git/gitlab sudo -u git -H bundle install --deployment --without development test postgres
初始化数据库(创建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 "ae" sudo -u git -H git config --global user.email "ae@git.ae.club" sudo -u git -H git config --global core.autocrlf input
//验证gitlab
检测当前环境
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
8, nginx配置
//nginx安装
传送门:https://blog.espnlol.com/?p=84
//nginx主配置文件
vi /usr/local/nginx/conf/nginx.conf
user git www;
worker_processes auto;
error_log /home/data/wwwlogs/nginx_error.log crit;
pid /usr/local/nginx/logs/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 65535;
events
{
use epoll;
worker_connections 65535;
multi_accept on;
}
http
{
include mime.types;
default_type application/octet-stream;
# waf
#lua_need_request_body on;
#access_by_lua_file /usr/local/nginx/conf/waf/waf.lua;
#lua_shared_dict limit 10m;
#lua_package_path "/usr/local/nginx/conf/waf/?.lua";
#init_by_lua_file /usr/local/nginx/conf/waf/init.lua;
server_names_hash_bucket_size 128;
client_header_buffer_size 4k;
large_client_header_buffers 4 32k;
client_max_body_size 100m;
client_body_buffer_size 50m;
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
# tcp_nodelay on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 128k;
fastcgi_buffers 8 128k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml application/xml+rss;
gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
gzip_disable "MSIE [1-6]\.";
#limit_conn_zone $binary_remote_addr zone=perip:10m;
##If enable limit_conn_zone,add "limit_conn perip 10;" to server section.
server_tokens off;
#log format
log_format access '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
access_log off;
include vhost/*.conf;
}
//gitlab的虚拟头配置文件
vi /usr/local/nginx/conf/vhost/gitlab.conf
# GITLAB
# Maintainer: @randx
# App Version: 5.0
upstream gitlab {
server unix:/home/git/gitlab/tmp/sockets/gitlab.socket;
}
server {
listen 80;
listen 8090;
server_name git.espnlol.com;
server_tokens off;
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 /home/data/wwwlogs/gitlab/gitlab_access.log;
error_log /home/data/wwwlogs/gitlab/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;
}
}
//设置开机启动并启动
chkconfig nginx on service nginx start
9,设置邮件发送
//首先是拷贝Gitlab自带的example
cd /home/git/gitlab sudo -u git -H cp config/initializers/smtp_settings.rb.sample config/initializers/smtp_settings.rb
//然后用我们自己的邮箱替换example中的邮箱
sudo -u git -H vim config/initializers/smtp_settings.rb
//这里提供3种邮箱配置方法
//163
if Rails.env.production?
Gitlab::Application.config.action_mailer.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
address: "smtp.163.com",
port: 25,
user_name: "wpgitlab",
password: "123456",
domain: "163.com",
authentication: :plain,
enable_starttls_auto: true
}
end
//腾讯企业
if Rails.env.production?
Gitlab::Application.config.action_mailer.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
address: "smtp.exmail.qq.com",
port: 25,
user_name: "wangpeng@scnee.com",
password: "123456",
domain: "smtp.qq.com",
authentication: :plain,
enable_starttls_auto: true,
}
end
//139
if Rails.env.production?
Gitlab::Application.config.action_mailer.delivery_method = :smtp
ActionMailer::Base.smtp_settings = {
address: "smtp.139.com",
port: 25,
user_name: "13611225237@139.com",
password: "123456",
domain: "139.com",
authentication: :plain,
enable_starttls_auto: true
}
end
//修改gitlab.yml
cd /home/git/gitlab sudo -u git -H vim config/gitlab.yml ## Email settings # Email address used in the "From" field in mails sent by GitLab email_from: $EMAIL
10,登录网站
在ie栏输入nginx里配置的url就可以打开登录页面了,默认用户密码为:root/5iveL!fe
