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

[经验分享] GitLab Installation on Ubuntu Server 12.04

[复制链接]

尚未签到

发表于 2016-4-21 08:09:17 | 显示全部楼层 |阅读模式
For the people not knowing what GIT is or what it’s used for here’s a link to read about itWhat
is GIT. This post wouldn’t have been possible if it was not for the work done by the community atGitLab.
Please donate to this project.


Installation



This installation was done on a Ubuntu 12.04 server. A clean install was done with no extra packages installed with the baseinstallation. The server is setup on a VM running on VMWare ESX4.

The installation consists of 6 steps:

Install packages / dependencies

Install ruby

Install gitolite

Install and configure Gitlab.

Start the web front-end

Start a Resque worker (for background processing)


First 3 steps can be easily skipped with simply install script:


# Install curl and sudo
apt-get install curl sudo
# 3 steps in 1 command
curl https://raw.github.com/gitlabhq/gitlabhq/master/doc/debian_ubuntu.sh | sh


Now you can go to step 4″


1.
Install packages




Keep
in mind thatsudois not installed for debian by default. You should install it with as root (to gain root access on Ubuntu login with your username and sudo -i ):

apt-get update && apt-get upgrade && apt-get install sudo
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install -y git-core wget curl gcc checkinstall libxml2-dev libxslt-dev sqlite3 libsqlite3-dev libcurl4-openssl-dev libreadline-dev libc6-dev libssl-dev libmysql++-dev make build-essential zlib1g-dev libicu-dev redis-server openssh-server git-core python-dev python-pip libyaml-dev sendmail
# If you want to use MySQL:
sudo apt-get install -y mysql-server mysql-client libmysqlclient-dev


2. Install Ruby


wget <a href="http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.2-p290.tar.gz">http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.2-p290.tar.gz</a>
tar xzfv ruby-1.9.2-p290.tar.gz
cd ruby-1.9.2-p290
./configure
make
sudo make install


3. Install gitolite



Create user for git:

sudo adduser \
--system \
--shell /bin/sh \
--gecos 'git version control' \
--group \
--disabled-password \
--home /home/git \
git


Create user for gitlab:

# ubuntu/debian
sudo adduser --disabled-login --gecos 'gitlab system' gitlab


Add your user to git group:

sudo usermod -a -G git gitlab


Generate key:

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


Get gitolite source code:

cd /home/git
sudo -H -u git git clone git://github.com/gitlabhq/gitolite /home/git/gitolite


Setup:

sudo -u git sh -c 'echo -e "PATH=\$PATH:/home/git/bin\nexport PATH" > /home/git/.profile'
sudo -u git -i -H /home/git/gitolite/src/gl-system-install
sudo cp /home/gitlab/.ssh/id_rsa.pub /home/git/gitlab.pub
sudo chmod 777 /home/git/gitlab.pub
sudo -u git -H sed -i 's/0077/0007/g' /home/git/share/gitolite/conf/example.gitolite.rc
sudo -u git -H sh -c "PATH=/home/git/bin:$PATH; gl-setup -q /home/git/gitlab.pub"


Permissions:

sudo chmod -R g+rwX /home/git/repositories/
sudo chown -R git:git /home/git/repositories/


CHECK: Logout & login again to apply git group to your user


# clone admin repo to add localhost to known_hosts
# & be sure your user has access to gitolite
sudo -u gitlab -H git clone git@localhost:gitolite-admin.git /tmp/gitolite-admin
# if succeed you can remove it
sudo rm -rf /tmp/gitolite-admin


IMPORTANT!
If you cant clonegitolite-adminrepository
– DONT PROCEED INSTALLATION



4. Install gitlab and configuration. Check status configuration.


sudo gem install charlock_holmes
sudo pip install pygments
sudo gem install bundler
cd /home/gitlab
sudo -H -u gitlab git clone git://github.com/gitlabhq/gitlabhq.git gitlab
cd gitlab
# Rename config files
sudo -u gitlab cp config/gitlab.yml.example config/gitlab.yml


Select db you want to use


# SQLite
sudo -u gitlab cp config/database.yml.sqlite config/database.yml
# Or
# Mysql
sudo -u gitlab cp config/database.yml.example config/database.yml
# Change username/password of config/database.yml to real one


Install gems


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


Setup DB


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


Checking status:


sudo -u gitlab bundle exec rake gitlab:app:status RAILS_ENV=production
# OUTPUT EXAMPLE
Starting diagnostic
config/database.yml............exists
config/gitlab.yml............exists
/home/git/repositories/............exists
/home/git/repositories/ is writable?............YES
remote: Counting objects: 603, done.
remote: Compressing objects: 100% (466/466), done.
remote: Total 603 (delta 174), reused 0 (delta 0)
Receiving objects: 100% (603/603), 53.29 KiB, done.
Resolving deltas: 100% (174/174), done.
Can clone gitolite-admin?............YES
UMASK for .gitolite.rc is 0007? ............YES


If you got all YES – congrats! You can go to next step.


5. Server up



Application can be started with next command:

# For test purposes
sudo -u gitlab bundle exec rails s -e production
# As daemon
sudo -u gitlab bundle exec rails s -e production -d


6. Run resque process (for processing queue).


# Manually
sudo -u gitlab bundle exec rake environment resque:work QUEUE=* RAILS_ENV=production BACKGROUND=yes
# Gitlab start script
./resque.sh


*Ok
– we have a working application now. **But
keep going – there are some thing that should be done *


Nginx && Unicorn



Install Nginx


sudo apt-get install nginx


Unicorn


cd /home/gitlab/gitlab
sudo -u gitlab cp config/unicorn.rb.orig config/unicorn.rb
sudo -u gitlab bundle exec unicorn_rails -c config/unicorn.rb -E production -D


Edit /etc/nginx/nginx.conf. Add nextcode tohttpsection:

upstream gitlab {
server unix:/home/gitlab/gitlab/tmp/sockets/gitlab.socket;
}
server {
listen YOUR_SERVER_IP:80;
server_name gitlab.YOUR_DOMAIN.com;
root /home/gitlab/gitlab/public;
# individual nginx logs for this gitlab vhost
access_log /var/log/nginx/gitlab_access.log;
error_log /var/log/nginx/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_redirect off;
# you need to change this to "https", if you set "ssl" directive to "on"
proxy_set_header X-FORWARDED_PROTO http;
proxy_set_header Host gitlab.YOUR_SUBDOMAIN.com:80;
proxy_set_header X-Real-IP $remote_addr;
proxy_pass http://gitlab;
}
}


gitlab.YOUR_DOMAIN.com – change to your domain.

Restart nginx:

/etc/init.d/nginx restart


Create init script in /etc/init.d/gitlab

#! /bin/bash
### BEGIN INIT INFO
# Provides: gitlab
# Required-Start: $local_fs $remote_fs $network $syslog redis-server
# Required-Stop: $local_fs $remote_fs $network $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: GitLab git repository management
# Description: GitLab git repository management
### END INIT INFO
DAEMON_OPTS="-c /home/gitlab/gitlab/config/unicorn.rb -E production -D"
NAME=unicorn
DESC="Gitlab service"
PID=/home/gitlab/gitlab/tmp/pids/unicorn.pid
RESQUE_PID=/home/gitlab/gitlab/tmp/pids/resque_worker.pid
case "$1" in
start)
CD_TO_APP_DIR="cd /home/gitlab/gitlab"
START_DAEMON_PROCESS="bundle exec unicorn_rails $DAEMON_OPTS"
START_RESQUE_PROCESS="./resque.sh"
echo -n "Starting $DESC: "
if [ `whoami` = root ]; then
sudo -u gitlab sh -c "$CD_TO_APP_DIR > /dev/null 2>&1 && $START_DAEMON_PROCESS && $START_RESQUE_PROCESS"
else
$CD_TO_APP_DIR > /dev/null 2>&1 && $START_DAEMON_PROCESS && $START_RESQUE_PROCESS
fi
echo "$NAME."
;;
stop)
echo -n "Stopping $DESC: "
kill -QUIT `cat $PID`
kill -QUIT `cat $RESQUE_PID`
echo "$NAME."
;;
restart)
echo -n "Restarting $DESC: "
kill -USR2 `cat $PID`
kill -USR2 `cat $RESQUE_PID`
echo "$NAME."
;;
reload)
echo -n "Reloading $DESC configuration: "
kill -HUP `cat $PID`
kill -HUP `cat $RESQUE_PID`
echo "$NAME."
;;
*)
echo "Usage: $NAME {start|stop|restart|reload}" >&2
exit 1
;;
esac
exit 0


Adding permission:

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


When server is rebooted then gitlab must starting:

sudo insserv gitlab


*This step didn’t work for me so what I did was to edit the rc.local file.

nano /etc/rc.local


And added the following to the rc.local file to start the GitLab when the server reboots

cd /home/gitlab/gitlab
sudo -u gitlab bundle exec unicorn_rails -c config/unicorn.rb -E production -D
/etc/init.d/nginx restart
sudo /etc/init.d/gitlab restart


Now you can start/restart/stop gitlab like:

sudo /etc/init.d/gitlab restart


Test your installation



If all went well, you should be able to connect to your server at http://yoursevername. The default login info is as follows:

email: admin@local.host
password : 5ivel!fe


Enjoy your new GIT server!

Reference: GitLab


Tagged with:GIT,repository,ubuntu

Posted inGIT

运维网声明 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-206719-1-1.html 上篇帖子: ubuntu 下安装hudson, 集成Git 下篇帖子: 在ubuntu下安装git(转载)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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