天天看點

GitLub環境部署

https://github.com/gitlabhq/gitlabhq/blob/6-7-stable/doc/install/installation.md#important-notes



系統,ubuntu 14.01/64



概述:

gitlab安裝包括安裝下列元件

1、Packages / Dependencies

2、Ruby

3、System Users

4、GitLab shell

5、Database

6、GitLab

7、Nginx



首先修改ubuntu 更新源URL

将 /etc/apt/sources.list 檔案的 所有URL 改為: http://old-releases.ubuntu.com/ubuntu/



1、依賴包/更新下。

# run as root!

apt-get update -y

apt-get upgrade -y

apt-get install sudo -y



2、安裝vim

sudo apt-get install -y vim

sudo update-alternatives --set editor /usr/bin/vim.basic



3、安裝所需要的包:

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



4、確定你已經正确安裝git

# Install Git

sudo apt-get install -y git-core



# Make sure Git is version 1.7.10 or higher, for example 1.7.12 or 1.8.4

git --version



5、删除它、編譯源代碼。



# Remove packaged Git

sudo apt-get remove git-core



# Install dependencies

sudo apt-get install -y libcurl4-openssl-dev libexpat1-dev gettext libz-dev libssl-dev build-essential



# Download and compile from source

cd /tmp

curl --progress https://git-core.googlecode.com/files/git-1.8.5.2.tar.gz | tar xz

cd git-1.8.5.2/

make prefix=/usr/local all



# Install into /usr/local/bin

sudo make prefix=/usr/local install



# When editing config/gitlab.yml (Step 6), change the git bin_path to /usr/local/bin/git



6、為了接收郵件通知,請確定安裝郵件伺服器。



sudo apt-get install -y postfix



7、 安裝 ruby

sudo apt-get remove ruby1.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



sudo gem install bundler --no-ri --no-rdoc

這步可能報錯,使用淘寶源



8、建立git使用者

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



9、gitlab Shell是一個SSH通路和存儲管理軟體的開發,專門為gitlab提供。

# Go to home directory

cd /home/git



# Clone gitlab shell

sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-shell.git -b v1.9.1



cd gitlab-shell



sudo -u git -H cp config.yml.example config.yml



# Edit config and replace gitlab_url

# with something like 'http://domain.com/'

sudo -u git -H editor config.yml



# Do setup

sudo -u git -H ./bin/install



10、 資料庫安裝,官網建議用的資料庫是 PostgreSQL 我用的是mysql資料庫

mysql資料庫安裝



# Install the database packages

sudo apt-get install -y mysql-server mysql-client libmysqlclient-dev



# Pick a database root password (can be anything), type it and press enter

# Retype the database root password and press enter



# Secure your installation.

sudo mysql_secure_installation



# Login to MySQL

mysql -u root -p



# Type the database root password



# Create a user for GitLab

# do not type the 'mysql>', this is part of the prompt

# change $password in the command below to a real password you pick

mysql> CREATE USER 'git'@'localhost' IDENTIFIED BY '$password';



# Create the GitLab production database

mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;



# Grant the GitLab user necessary permissions on the table.

mysql> GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'git'@'localhost';



# Quit the database session

mysql> \q



# Try connecting to the new database with the new user

sudo -u git -H mysql -u git -p -D gitlabhq_production



# Type the password you replaced $password with earlier



# You should now see a 'mysql>' prompt



# Quit the database session

mysql> \q



# You are done installing the database and can go back to the rest of the installation.



啟動資料庫 ,看下是否啟動



11、進入git home目錄

cd /home/git

克隆GitLab 庫

sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 6-7-stable gitlab 期間有些慢



cd /home/git/gitlab

配置

cd /home/git/gitlab



# Copy the example GitLab config

sudo -u git -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

#

# If you installed Git from source, change the git bin_path to /usr/local/bin/git

sudo -u git -H editor config/gitlab.yml



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

sudo chown -R git log/

sudo chown -R git tmp/

sudo chmod -R u+rwX log/

sudo chmod -R u+rwX tmp/



# Create directory for satellites

sudo -u git -H mkdir /home/git/gitlab-satellites



# Create directories for sockets/pids and make sure GitLab can write to them

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/



# Create public/uploads directory otherwise backup will fail

sudo -u git -H mkdir public/uploads

sudo chmod -R u+rwX public/uploads



# Copy the example Unicorn config

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



# Enable cluster mode if you expect to have a high load instance

# Ex. change amount of workers to 3 for 2GB RAM server

sudo -u git -H editor config/unicorn.rb



# Copy the example Rack attack config

sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb



# Configure Git global settings for git user, useful when editing via web

# Edit user.email according to what is set in gitlab.yml

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

sudo -u git -H git config --global user.email "[email protected]"

sudo -u git -H git config --global core.autocrlf input



配置GitLab DB 進行設定



# Mysql

sudo -u git cp config/database.yml.mysql config/database.yml



# Make config/database.yml readable to git only

sudo -u git -H chmod o-rwx config/database.yml



12、安裝Gems

cd /home/git/gitlab

# Or if you use MySQL (note, the option says "without ... postgres")

sudo -u git -H bundle install --deployment --without development test postgres aws



成功後,最下端會顯示 登入gitlab的賬号和密碼 如下



Administrator account created:



login...[email protected]

password..........5iveL!fe



13、初始化資料庫,

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



# Type 'yes' to create the database tables.



# When done you see 'Administrator account created:'



13、安裝腳本



啟動腳本

sudo cp lib/support/init.d/gitlab /etc/init.d/gitlab



sudo cp lib/support/init.d/gitlab.default.example /etc/default/gitlab



14、gitlab開機啟動:

sudo update-rc.d gitlab defaults 21



建立logrotate

sudo cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab

檢查應用程式的狀态

檢查gitlab及其環境的配置是正确的:

sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production



開始你的gitlab執行個體

啟動 gitlab

sudo service gitlab start

# or

sudo /etc/init.d/gitlab restart



sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production





15、nginx安裝使用部署



sudo apt-get install -y 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



# Change YOUR_SERVER_FQDN to the fully-qualified

# domain name of your host serving GitLab.

sudo editor /etc/nginx/sites-available/gitlab



啟動nginx

sudo service nginx restart

完成



確定你沒有錯過任何運作更徹底的檢查



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

如果所有的項目都是綠色的,那麼恭喜你成功安裝gitlab!



16、更改gitlab端口

預設web端口為80:,

為了便于開放到外部通路,肯定需要把端口改為其他的,比如3000

[email protected]:/home/git/gitlab# vim /home/git/gitlab-shell/config.yml

更改第四行URL gitlab_url: "http://192.168.83.113:3000/"



[email protected]:/home/git/gitlab# vim /home/git/gitlab/config/gitlab.yml

更改 host、port 為:

host: 192.168.83.113

port: 3000

./gitlab 配置檔案的listen 192.168.1.80:99 的端口設定為一緻 .









18、初始登入

[email protected]:/home/git/gitlab# vim /etc/nginx/sites-available/default

更改端口

listen 3000 default_server;

listen [::]:3000 default_server ipv6only=on;



[email protected]:/home/git/gitlab# vim /etc/nginx/sites-available/gitlab

listen 192.168.83.113:3000 default_server;



檢查端口被監聽起來沒有

[email protected]:/home/git/gitlab# netstat -ano |grep 3000

tcp 0 0 0.0.0.0:3000 0.0.0.0:* LISTEN off (0.00/0/0)

tcp6 0 0 :::3000 :::* LISTEN off (0.00/0/0)

[email protected]:/home/git/gitlab# netstat -ano |grep 80

tcp 0 0 127.0.0.1:8080 0.0.0.0:* LISTEN off (0.00/0/0)

unix 3 [ ] STREAM CONNECTED 148056

unix 3 [ ] STREAM CONNECTED 148083 /var/run/mysqld/mysqld.sock

unix 3 [ ] STREAM CONNECTED 148055

unix 3 [ ] STREAM CONNECTED 148052

unix 3 [ ] STREAM CONNECTED 148058

unix 3 [ ] STREAM CONNECTED 148053

unix 3 [ ] STREAM CONNECTED 148059

unix 3 [ ] STREAM CONNECTED 148068 /var/run/mysqld/mysqld.sock

unix 3 [ ] STREAM CONNECTED 10580

unix 3 [ ] STREAM CONNECTED 148067

unix 3 [ ] STREAM CONNECTED 148054

unix 3 [ ] STREAM CONNECTED 148082

unix 3 [ ] STREAM CONNECTED 148057



然後浏覽器打開通路 http://192.168.83.113:3000/























































           

轉載于:https://my.oschina.net/u/3170201/blog/812190