设为首页 收藏本站
查看: 1404|回复: 0

[经验分享] 在虚拟机中安装Gitlab

[复制链接]

尚未签到

发表于 2018-1-10 22:05:28 | 显示全部楼层 |阅读模式
  随着Github的盛行,social coding逐渐浮出水面,正好Gitlab刚发布了Gitlab 4.0,我今天边学习边记录安装Gitlab的过程,希望对大家有用。
  1. 我是在ubuntu server 10.4上安装的,首先要准备一个VitualBox并安装ubuntu server。
DSC0000.png

  2. Packages / Dependencies
  这里是Gitlab的安装说明:
  https://github.com/gitlabhq/gitlabhq/blob/stable/doc/install/installation.md
  我们先更新和安装Gitlab必须的依赖,以下操作请保持网络畅通:

# run as root

  

sudo apt-get update        // 会有些更新失败,不必管它  

sudo apt-get upgrade      // 这个比较慢,可以去喝杯茶  

  

# Install vim  

sudo apt-get install -y vim  

  

Install the required packages: // 下面这句比较长,不要打错了  

sudo apt-get install -y build-essential zlib1g-dev libyaml-dev libssl-dev libgdbm-dev libreadline-dev libncurses5-dev libffi-dev  wget curl git-core openssh-server redis-server postfix checkinstall libxml2-dev libxslt-dev libcurl4-openssl-dev libicu-dev  


  

# Install Python  

sudo apt-get install python  

  

# Make sure that Python is 2.5+ (3.x is not supported at the moment)  

python –version  // 我装上的版本是python 2.7.3  

  

# If it's Python 3 you might need to install Python 2 separately  

sudo apt-get install python2.7  

  

# Make sure you can access Python via python2  

python2 --version  

  

# If you get a "command not found" error create a link to the python binary  

sudo ln -s /usr/bin/python /usr/bin/python2 // 我的python2似乎已经存在了,不管它  


  2. 安装Ruby
  

mkdir /tmp/ruby && cd /tmp/ruby    // 建个临时目录下载ruby  

wget http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p327.tar.gz  // 下载并解压  

tar xfvz ruby-1.9.3-p327.tar.gz  

cd ruby-1.9.3-p327  

./configure      // configure & make有些慢,耐心等下  

make  

sudo make install  

  Install the Bundler Gem:
  

sudo gem install bundler  


3. 创建gitlab用户
  

// 创建Git账户  

sudo adduser \  

  --system \  

  --shell /bin/sh \  

  --gecos 'Git Version Control' \  

  --group \  

  --disabled-password \  

  --home /home/git \  

  Git  

  

// 创建Gitlab账户, 并禁止登录  

sudo adduser --disabled-login --gecos 'GitLab' gitlab  

  

# Add it to the git group  

sudo usermod -a -G git gitlab  

  

# Generate the SSH key  // 一定是用gitlab用户生成id_rsa  

sudo -u gitlab -H ssh-keygen -q -N '' -t rsa -f /home/gitlab/.ssh/id_rsa  

  


4. Gitolite
  克隆Gitolite并安装:
  

// 以下所有操作要在git用户下操作,所有命令前加”sudo –u git”  

cd /home/git        

sudo -u git -H git clone -b gl-v320 https://github.com/gitlabhq/gitolite.git /home/git/gitolite  

  

# Add Gitolite scripts to $PATH  

sudo -u git -H mkdir /home/git/bin  

sudo -u git -H sh -c 'printf "%b\n%b\n" "PATH=\$PATH:/home/git/bin" "export PATH" >> /home/git/.profile'  

sudo -u git -H sh -c 'gitolite/install -ln /home/git/bin'  

  

# Copy the gitlab user's (public) SSH key ...  

sudo cp /home/gitlab/.ssh/id_rsa.pub /home/git/gitlab.pub  

sudo chmod 0444 /home/git/gitlab.pub  

  

# ... and use it as the admin key for the Gitolite setup  

sudo -u git -H sh -c "PATH=/home/git/bin:$PATH; gitolite setup -pk /home/git/gitlab.pub"  

  

  Fix the directory permissions for theconfiguration directory:
  

# Make sure the Gitolite config dir is owned by git  

sudo chmod 750 /home/git/.gitolite/  

sudo chown -R git:git /home/git/.gitolite/  

  Fixthe directory permissions for the repositories:
  

# Make sure the repositories dir is owned by git and it stays that way  

sudo chmod -R ug+rwXs,o-rwx /home/git/repositories/  

sudo chown -R git:git /home/git/repositories/  


测试下git是否可以clone
  

# Clone the admin repo so SSH adds localhost to known_hosts ...  

# ... and to be sure your users have access to Gitolite  

sudo -u gitlab -H git clone git@localhost:gitolite-admin.git /tmp/gitolite-admin  

  

# If it succeeded without errors you can remove the cloned repo  

sudo rm -rf /tmp/gitolite-admin  

DSC0001.png

  到这里,基本算完成一半了。

安装数据库
  Gitlab 4.0 支持PostgreSQL,我们用PostgreSQL:
  

# Install the database packages  

sudo apt-get install -y postgresql-9.1 libpq-dev  

  

# Login to PostgreSQL  

sudo -u postgres psql -d template1  

  

# Create a user for GitLab. (change $password to a real password)  

template1=# CREATE USER gitlab WITH PASSWORD '$password';  

  

# Create the GitLab production database & grant all privileges on database  

template1=# CREATE DATABASE gitlabhq_production OWNER gitlab;  

  

# Quit the database session  

template1=# \q  

  

# Try connecting to the new database with the new user  

sudo -u gitlab -H psql -d gitlabhq_production  


安装Gitlab
  

# We'll install GitLab into home directory of the user "gitlab"  

cd /home/gitlab  

  

# Clone GitLab repository  

sudo -u gitlab -H git clone https://github.com/gitlabhq/gitlabhq.git gitlab  

  

# Go to gitlab dir   

cd /home/gitlab/gitlab  

  

# Checkout to stable>  

sudo -u gitlab -H git checkout 4-0-stable  

  


Configure it
cd /home/gitlab/gitlab  

  

# Copy the example GitLab config  

sudo -u gitlab -H cp config/gitlab.yml.example config/gitlab.yml  

  

# Make sure to change "localhost" to the fully-qualified domain name of your  

# host serving GitLab where necessary  

sudo -u gitlab -H vim config/gitlab.yml  

  

# Make sure GitLab can write to the log/ and tmp/ directories  

sudo chown -R gitlab log/  

sudo chown -R gitlab tmp/  

sudo chmod -R u+rwX  log/  

sudo chmod -R u+rwX  tmp/  

  

# Copy the example Unicorn config  

sudo -u gitlab -H cp config/unicorn.rb.example config/unicorn.rb  


Configure GitLab DB settings
  

# 我们用的是PostgreSQL,所以使用postgresql模板  

sudo -u gitlab cp config/database.yml.postgresql config/database.yml  

  

# 记得修改database.yml里的username为“gitlab”,密码为空  

sudo –u gitlab vi config/database.yml  


Install Gems
cd /home/gitlab/gitlab  

sudo gem install charlock_holmes --version '0.6.9'  

// 安装需要几分钟时间  

sudo -u gitlab -H bundle install --deployment --without development test mysql  


Configure Git
  

sudo -u gitlab -H git config --global user.name "GitLab"  

sudo -u gitlab -H git config --global user.email "gitlab@localhost"  


Setup GitLab Hooks
  

sudo cp ./lib/hooks/post-receive /home/git/.gitolite/hooks/common/post-receive  

sudo chown git:git /home/git/.gitolite/hooks/common/post-receive  


Initialise Database and Activate Advanced Features
  

sudo -u gitlab -H bundle exec rake gitlab:app:setup RAILS_ENV=production  


Install Init Script
  Downloadthe init script (will be /etc/init.d/gitlab):
  

sudo wget https://raw.github.com/gitlabhq/gitlab-recipes/master/init.d/gitlab -P /etc/init.d/  

sudo chmod +x /etc/init.d/gitlab  

  MakeGitLab start on boot:
  

sudo update-rc.d gitlab defaults 21  

  

// 重启系统后并测试  

# reboot  

sudo -u gitlab -H bundle exec rake gitlab:check RAILS_ENV=production  

  

  如果你也像下图一样,说明一切顺利:
DSC0002.png


Nginx
  最后一步,配置Nginx web service:
  

sudo apt-get install nginx  

sudo wget https://raw.github.com/gitlabhq/gitlab-recipes/master/nginx/gitlab -P /etc/nginx/sites-available/  

sudo ln -s /etc/nginx/sites-available/gitlab /etc/nginx/sites-enabled/gitlab  

  

# Change **YOUR_SERVER_IP** and **YOUR_SERVER_FQDN**  

# to the IP address and fully-qualified domain name  

# of your host serving GitLab  

sudo vim /etc/nginx/sites-enabled/gitlab  

  

// 稳妥些,重新系统  

reboot  

  系统重启后,直接输入你虚拟机的http://IP地址,It’s works!!
DSC0003.png

  不要忘了,初始用户密码是:
  

admin@local.host  

5iveL!fe  

  Good luck!

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-433703-1-1.html 上篇帖子: gitlab一键安装 笔记 下篇帖子: Centos7上安装Gitlab
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表