用GitLab搭建自己的私有GitHub

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
云数据库 RDS MySQL,高可用系列 2核4GB
简介: 用GitLab搭建自己的私有GitHub
用GitLab搭建自己的私有GitHub
Gitlab是一个用Ruby on Rails开发的开源项目管理程序,可以通过WEB界面进行访问公开的或者私人项目。它和Github有类似的功能,能够浏览源代码,管理缺陷和注释。
下面介绍如何在 Debian/Ubuntu 和 Centos 下搭建配置 GitLab。
安装依赖
Debian/Ubuntu下:
sudo apt-get install -y build-essential zlib1g-dev libyaml-dev libssl-dev libgdbm-dev libreadline-dev libncurses5-dev libffi-dev curl openssh-server redis-server checkinstall libxml2-dev libxslt-dev libcurl4-openssl-dev libicu-dev logrotate
安装python(注意需要2.5以上版本):
sudo apt-get install -y python python-docutils
安装git(注意需要1.7.10以上版本):
sudo apt-get install -y git-core
Centos下官方仓库的软件比较老旧,推荐先添加epel源,然后再安装依赖:
sudo yum install git patch gcc-c++ readline-devel zlib-devel libffi-devel openssl-devel make autoconf automake libtool bison libxml2-devel libxslt-devel libyaml-devel git python python-docutils
安装 Ruby 2.0
需要安装Ruby2.0,软件仓库中的Ruby 1.8不支持:
mkdir /tmp/ruby && cd /tmp/ruby
curl --progress ftp://ftp.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p353.tar.gz | tar xz
cd ruby-2.0.0-p353
./configure --disable-install-rdoc
make
sudo make install
安装Bundler Gem:
sudo gem install bundler --no-ri --no-rdoc
配置gitlab-shell
创建git用户:
sudo adduser --system --create-home --comment 'GitLab' git  
配置gitlab-shell
su - git -c "git clone https://github.com/gitlabhq/gitlab-shell.git"  
su - git -c "cd gitlab-shell && git checkout v1.3.0"  
su - git -c "cp gitlab-shell/config.yml.example gitlab-shell/config.yml"  
sed -i "s/localhost/gitlab.51yip.com/g" /home/git/gitlab-shell/config.yml  
su - git -c "gitlab-shell/bin/install"  
chmod 600 /home/git/.ssh/authorized_keys  
chmod 700 /home/git/.ssh
数据库
GitLab支持 MySQL 和 PostgreSQL 数据库。下面以 MySQL为例,介绍安装方法:
Debian/Ubuntu下使用如下命令安装:
sudo apt-get install -y mysql-server mysql-client libmysqlclient-dev
Centos下使用如下命令:
sudo yum install mysql-server 
sudo chkconfig mysqld on
配置MySQL:
sudo echo "CREATE DATABASE IF NOT EXISTS gitlabhq_production DEFAULT CHARACTER SET 'utf8' COLLATE 'utf8_unicode_ci';" | mysql -u root 
sudo echo "UPDATE mysql.user SET Password=PASSWORD('123456') WHERE User='root'; FLUSH PRIVILEGES;" | mysql -u root 
注意,用你的密码替换123456。
安装配置 gitlab
su - git -c "git clone https://github.com/gitlabhq/gitlabhq.git gitlab"  
su - git -c "cd gitlab;git checkout 5-1-stable"  
su git -c "cp config/gitlab.yml.example config/gitlab.yml"  
su git -c "mkdir /home/git/gitlab-satellites"  
su git -c "mkdir public/uploads"  
su git -c "mkdir -p tmp/sockets/"  
su git -c "mkdir -p tmp/pids/"  
sed -i "s/ host: localhost/ host: gitlab.segmentfault.com/g" config/gitlab.yml  
sed -i "s/from: gitlab@localhost/from: gitlab@gitlab.segmentfault.com/g" config/gitlab.yml  
su git -c "cp config/puma.rb.example config/puma.rb"  
su git -c 'git config --global user.name "GitLab"'  
su git -c 'git config --global user.email "gitlab@abcde.com"'
注意将gitlab.segmentfault.com替换为你自己的内容。
配置数据库连接:
sudo su git -c "cp config/database.yml.mysql config/database.yml"
sudo sed -i "s/secure password/mysql的root密码/g" config/database.yml
安装MySQL需要的Gems
su - git
cd  gitlab
sudo -u git -H bundle install --deployment --without development test postgres aws
慢改成淘宝源
我把系统的 sources 改成了淘宝源
$ gem sources --remove https://rubygems.org/
$ gem sources -a http://ruby.taobao.org/
同时把 Gemfile 的第一行改成了
source "http://ruby.taobao.org"
初始化:
sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production
sudo cp lib/support/init.d/gitlab /etc/init.d/gitlab
sudo chmod +x /etc/init.d/gitlab
sudo update-rc.d gitlab defaults 21
查看是否配置妥当:
sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production
重启GitLab:
sudo service gitlab start
配置Nginx
Debian/Ubuntu下:
sudo apt-get install -y nginx
CentOS下:
sudo yum install nginx
下载配置文件样例:
sudo cp lib/support/nginx/gitlab /etc/nginx/sites-available/gitlab
sudo ln -s /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab
修改 /etc/nginx/sites-available/gitlab,特别留意将 YOUR_SERVER_FQDN 改成自己的。
重启nginx:
sudo service nginx restart
好了,你可以登录GitLab了,默认安装后的用户名:admin@local.host,密码5iveL!fe。
相关实践学习
如何在云端创建MySQL数据库
开始实验后,系统会自动创建一台自建MySQL的 源数据库 ECS 实例和一台 目标数据库 RDS。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助     相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
开发工具 git
git,github,gitlab,码云的区别
码云https://gitee.com/enterprises?from=tg-6-7是开源中国社区推出的基于git的代码托管服务平台,基于gitlab。目前招商银行,中国科学技术大学,CSDN等多家企业和机构都在使用码云平台
224 0
|
3月前
|
开发工具 git
idea中git替换,推送到新的github或者gitlab上面
idea中git替换,推送到新的github或者gitlab上面
270 2
|
4月前
|
安全 Shell 网络安全
Git学习---Git快速入门、Git基础使用、Git进阶使用、Git服务器使用(IDEA集成GitHub、Gitee、GitLab)、GitHub Desktop客户端
Git学习---Git快速入门、Git基础使用、Git进阶使用、Git服务器使用(IDEA集成GitHub、Gitee、GitLab)、GitHub Desktop客户端
179 0
|
4月前
|
程序员 开发工具 git
【实测】gitlab/github 如何过滤项目内的文件
【实测】gitlab/github 如何过滤项目内的文件
|
网络安全 开发工具 git
一个git如何同时绑定gitlab与github
一个git如何同时绑定gitlab与github
385 0
|
11月前
|
Linux 网络安全 开发工具
Git学习---Git快速入门、Git基础使用、Git进阶使用、Git服务器使用(IDEA集成GitHub、Gitee、GitLab)、GitHub Desktop客户端
Git学习---Git快速入门、Git基础使用、Git进阶使用、Git服务器使用(IDEA集成GitHub、Gitee、GitLab)、GitHub Desktop客户端
|
存储 Shell 开发工具
Windows系统下将代码上传至gitLab或gitHub
Windows系统下将代码上传至gitLab或gitHub
|
Shell 开发工具 数据安全/隐私保护
如何上传项目到github/gitlab?
如何上传项目到github/gitlab?
248 0
|
开发工具 git
如何将项目从Github、Gitlab同步到Gitee
有时候,我们项目使用Git工具上传到GitHub,并且完善好说明等之后,我们往往像同时推送到Gitee,毕竟有时候Gitee还挺有用,至少下载速度不错。
633 0
|
开发工具 git
GitHub/GitLab 为不同的项目修改提交名字 user.name 和邮箱 user.email(附:批量处理脚本)
大疫情的背景下,家里的电脑需要同时支撑自己和公司的项目,根据 GitHub/GitLab 网站的提交记录上看,其是根据邮箱来辨识用户的,所以有必要分别针对不同的项目设置不同的 Git 名字(user.name)和邮箱(user.email)。
541 1