CentOS 7.0 源碼安裝 Gitlab

前言:源碼安裝Gitlab其實(shí)并不推薦评甜,既麻煩還容易出現(xiàn)問題灰粮,不是很推薦新手。推薦大家使用 docker 或者官方的一鍵包去安裝忍坷。這里只是記錄自己搭建的過程粘舟,親測好用。


一佩研、yum 安裝依賴

CentOS 7 默認(rèn)自帶了 EPEL 源柑肴,如果沒有的話請自行添加。

# run as root !!!
yum  update
yum install gcc ruby-devel libxml2 libxml2-devel libxslt libxslt-devel

二旬薯、安裝 Ruby

先卸載自帶的ruby

yum remove ruby

源碼安裝Ruby2.3.1版本

url --remote-name --progress https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.1.tar.gz
tar xvzf ruby-2.3.1.tar.gz
cd ruby-2.3.1
./configure --disable-install-rdoc
make
make install

安裝Bundler Gem (它是幫助管理ruby下的所有依賴的包嘉抒,相當(dāng)于yum的功能)

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

更換ruby源,自帶的源下載軟件包太慢袍暴。更換為淘寶的些侍。

gem sources --remove https://rubygems.org/
gem sources -a https://ruby.taobao.org/

三隶症、安裝GO(gitlab-workhorse需要用)

新版本的 gitlab 使用 HTTPS 方式去 clone 或者 push 代碼的時候,需要用到 workhorse

curl --remote-name --progress https://storage.googleapis.com/golang/go1.5.3.linux-amd64.tar.gz
tar -C /usr/local -xzf go1.5.3.linux-amd64.tar.gz
ln -sf /usr/local/go/bin/{go,godoc,gofmt} /usr/local/bin/

四岗宣、安裝數(shù)據(jù)庫

MySQL 已經(jīng)不再包含在 CentOS 7 的源中蚂会,而改用了 MariaDB,先搜索 MariaDB 現(xiàn)有的包:

rpm -qa | grep mariadb

卸載

rpm -e --nodeps mariadb-*

安裝MySQL

wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum install mysql-community-server
yum install mysql-community-devel

更改配置文件

vim /etc/my.cnf
[mysqld]
datadir=/data/mysql    //這個目錄是單獨(dú)創(chuàng)建的耗式,請注意

初始化

mysql_install_db --user=mysql --datadir=/data/mysql/

設(shè)置root的密碼和相關(guān)登錄信息

# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n] y                  [設(shè)置root用戶密碼]
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y                 [刪除匿名用戶]
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y       [禁止root遠(yuǎn)程登錄]
 ... Success!

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y          [刪除test數(shù)據(jù)庫]
 - Dropping test database...
ERROR 1008 (HY000) at line 1: Can't drop database 'test'; database doesn't exist
 ... Failed!  Not critical, keep moving...
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y            [刷新權(quán)限]
 ... Success!




All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!


Cleaning up...

創(chuàng)建一個gitlab用戶胁住,以及庫,用來存儲數(shù)據(jù)

mysql> CREATE USER 'gitlab'@'localhost' IDENTIFIED BY 'gitlab'; 
Query OK, 0 rows affected (0.00 sec) 
mysql> CREATE DATABASE IF NOT EXISTS `gitlab` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`; 
Query OK, 1 row affected (0.01 sec) 
mysql> GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlab`.* TO 'gitlab'@'localhost'; 
Query OK, 0 rows affected (0.00 sec) 
mysql> FLUSH PRIVILEGES; 
Query OK, 0 rows affected (0.00 sec)

啟動mysql

service mysqld start

四刊咳、安裝redis

先卸載自帶的redis

yum remove redis

源碼安裝彪见,安裝包網(wǎng)上自行下載

tar zxvf redis-3.0.3.tar.gz
cd redis-3.0.3
make
make install

執(zhí)行redis的安裝腳本(不要一路回車,看清楚)

[root@gitlab redis-3.0.3]# ./utils/install_server.sh  Welcome to the redis service installer This script will help you easily set up a running redis server Please select the redis port for this instance: [6379]     
Selecting default: 6379 
Please select the redis config file name [/etc/redis/6379.conf] /etc/redis.conf Please select the redis log file name [/var/log/redis_6379.log] /var/log/redis.log Please select the data directory for this instance [/var/lib/redis/6379] /var/lib/redis.pid    
Please select the redis executable path [/usr/local/bin/redis-server]            Selected config: Port           : 6379 
Config file    : /etc/redis.conf 
Log file       : /var/log/redis.log 
Data dir       : /var/lib/redis.pid 
Executable     : /usr/local/bin/redis-server 
Cli Executable : /usr/local/bin/redis-cli 
Is this ok? Then press ENTER to go on or Ctrl-C to abort. 
Copied /tmp/6379.conf => /etc/init.d/redis_6379 
Installing service... 
Successfully added to chkconfig! 
Successfully added to runlevels 345! 
Starting Redis server... 
Installation successful!

更改redis的啟動腳本娱挨,并啟動服務(wù)

mv /etc/init.d/redis_6379 /etc/init.d/redis
service redis start

創(chuàng)建git用戶

useradd --comment 'GitLab' git
echo "git ALL=(ALL)       NOPASSWD: ALL" >>/etc/sudoers

安裝gitlab-shell

切換到git用戶余指,clone新版gitlab-shell到git家目錄中

su - git
git clone https://github.com/gitlabhq/gitlab-shell.git -b v3.6.1 gitlab-shell

將分支切換為v3.6.1

cd gitlab-shell
git checkout -b v3.6.1

提供配置文件,修改gitlab的URL地址

cp config.yml.example config.yml
vim config.yml
gitlab_url: "http://192.168.100.100/"
或者 gitlab_url: "http://git.test.com/"

進(jìn)行安裝操作

[git@gitlab~ gitlab-shell]$ ./bin/install  
mkdir -p /home/git/repositories: true
mkdir -p /home/git/.ssh: true chmod 700 /home/git/.ssh: true 
touch /home/git/.ssh/authorized_keys: true 
chmod 600 /home/git/.ssh/authorized_keys: true 
chmod -R ug+rwX,o-rwx /home/git/repositories: true 
find /home/git/repositories -type d -print0 | xargs -0 chmod g+s: true

安裝gitlab

克隆gitlab的代碼到git家目錄

su - git 
cd
git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 8-10-stable gitlab

配置項(xiàng)目跷坝,提供配置文件

cd gitlab
cp config/gitlab.yml.example config/gitlab.yml

將localhost改為本機(jī)ip或者是域名

[git@gitlab ~]$ sed -i 's/localhost/192.168.100.100/g' config/gitlab.yml
或者
[git@gitlab ~]$ sed -i 's/localhost/git.test.com/g' config/gitlab.yml

修改目錄的相關(guān)權(quán)限

[git@gitlab ~]$ chown -R git log/
[git@gitlab ~]$ chown -R git tmp/
[git@gitlab ~]$ chmod -R u+rwx log/
[git@gitlab ~]$ chmod -R u+rwx tmp/

[git@gitlab ~]$ mkdir /home/git/gitlab-satellites

#可以視為臨時目錄酵镜,通過web ui的提交請求文件以及檢出版本庫都會存放在這個位置

提供unicorn的配置

[git@gitlab ~]$ cp config/unicorn.rb.example config/unicorn.rb

修改unicorn的配置,指明監(jiān)聽的端口和超時時間

[git@gitlab ~]$ vim config/unicorn.rb
listen "192.168.100.100:2486", :tcp_nopush => true
timeout 300

配置git的用戶和郵件

[git@gitlab ~]$ git config --global user.name "GitLab"
[git@gitlab ~]$ git config --global user.email "gitlab@test.com"
[git@gitlab ~]$ git config --global core.autocrlf input

配置數(shù)據(jù)庫柴钻,使gitlab將數(shù)據(jù)存入到MySQL數(shù)據(jù)庫中

[git@gitlab ~]$ cp config/database.yml.mysql config/database.yml
[git@gitlab ~]$ vim config/database.yml
production:
  adapter: mysql2
  encoding: utf8
  collation: utf8_general_ci
  reconnect: false
  database: gitlab
  pool: 10
  username: gitlab
  password: "gitlab"

這里注意一下淮韭,我的配置如下,如果host和socket的注釋不打開贴届,后面gem操作將會報錯靠粪,會提示無法連接數(shù)據(jù)庫。

image.png

修改目錄權(quán)限毫蚓,保證其他用戶不能訪問

[git@gitlab ~]$ chmod o-rwx config/database.yml

切回git用戶

[root@gitlab ~]# su - git
[git@gitlab ~]$ cd gitlab

修改Gemfile文件庇配,將gem源改成淘寶的源

[git@gitlab ~]$ vim Gemfile
source "https://ruby.taobao.org"

安裝一些依賴包

[git@gitlab ~]$ bundle install --deployment --without development test postgres puma aws
...
Remember to run generator to generate sample file and include mousetrap-rails with Rails Asset Pipeline

    $ rails generate mousetrap:install

Post-install message from rdoc:
Depending on your version of ruby, you may need to install ruby rdoc/ri data:

<= 1.8.6 : unsupported
= 1.8.7 : gem install rdoc-data; rdoc-data --install
= 1.9.1 : gem install rdoc-data; rdoc-data --install
>= 1.9.2 : nothing to do! Yay!    #顯示這個就代表安裝基本成功了。

初始化gitlab

[git@gitlab ~]$ bundle exec rake gitlab:setup RAILS_ENV=production 
... 
This will create the necessary database tables and seed the database. 
You will lose any previous data stored in the database. Do you want to continue (yes/no)? yes 

Administrator account created: 

login.........root 
password......5iveL!fe      #默認(rèn)的管理員密碼

為gitlab提供啟動腳本

# run as root  I苄@袒拧!
[root@gitlab ~]# wget -O /etc/init.d/gitlab https://raw.githubusercontent.com/gitlabhq/gitlab-recipes/master/init/sysvinit/centos/gitlab-unicorn --no-check-certificate
[root@gitlab ~]# chmod +x /etc/init.d/gitlab 
[root@gitlab ~]# chkconfig --add gitlab

啟動gitlab服務(wù)

[root@gitlab ~]# service gitlab start

這就可以使用了柬批,nginx配置一下 proxy_pass 反向代理啸澡,即可訪問。


錯誤解決

1. nginx報錯

2016/07/19 09:26:11 [crit] 3881#0: *10 connect() to unix:/home/git/gitlab/tmp/sockets/gitlab-workhorse.socket failed (13: Permission denied) while connecting to upstream, client: 192.168.1.180, server: www.gitlab810.com, request: "GET / HTTP/1.1", upstream: "http://unix:/home/git/gitlab/tmp/sockets/gitlab-workhorse.socket:/", host: "www.gitlab810.com"
2016/07/19 09:26:11 [error] 3881#0: *10 open() "/home/git/gitlab/public/502.html" failed (13: Permission denied), client: 192.168.1.180, server: www.gitlab810.com, request: "GET / HTTP/1.1", upstream: "http://unix:/home/git/gitlab/tmp/sockets/gitlab-workhorse.socket/", host: "www.gitlab810.com"

這是因?yàn)槲业?code>nginx使用的是www用戶運(yùn)行,而/home/git/gitlab/tmp/sockets/gitlab-workhorse.socket/用戶組是git,

解決方案:把git加入www用戶組,并賦予實(shí)行權(quán)限

usermod -a -G git www
chmod g+rx /home/git/

2. 在進(jìn)行到Install Gems時出錯:Make sure that gem install RedCloth -v '4.2.9' succeeds before bundling

gem install RedCloth -v '4.2.9'

又出現(xiàn)新問題:can’t find header files for ruby at /usr/lib/ruby/include/ruby.h

apt-get install ruby-dev

3. Make sure that gem install charlock_holmes -v '0.7.3' succeeds before

gem install charlock_holmes -v '0.7.3'

ERROR: Error installing charlock_holmes: ERROR: Failed to build gem native extension.

apt-get install libicu-dev

4. Make sure that gem install mysql2 -v '0.3.20' succeeds before bundling

gem install mysql2 -v '0.3.20'

libmysqlclient is missing. You may need to ‘a(chǎn)pt-get install libmysqlclient-dev’

aptitude install libmysqlclient-dev

參考文檔

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末氮帐,一起剝皮案震驚了整個濱河市嗅虏,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌上沐,老刑警劉巖皮服,帶你破解...
    沈念sama閱讀 210,914評論 6 490
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異,居然都是意外死亡龄广,警方通過查閱死者的電腦和手機(jī)硫眯,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 89,935評論 2 383
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來择同,“玉大人两入,你說我怎么就攤上這事∏貌牛” “怎么了裹纳?”我有些...
    開封第一講書人閱讀 156,531評論 0 345
  • 文/不壞的土叔 我叫張陵,是天一觀的道長紧武。 經(jīng)常有香客問我,道長阻星,這世上最難降的妖魔是什么朋鞍? 我笑而不...
    開封第一講書人閱讀 56,309評論 1 282
  • 正文 為了忘掉前任,我火速辦了婚禮迫横,結(jié)果婚禮上番舆,老公的妹妹穿的比我還像新娘酝碳。我一直安慰自己矾踱,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,381評論 5 384
  • 文/花漫 我一把揭開白布疏哗。 她就那樣靜靜地躺著呛讲,像睡著了一般。 火紅的嫁衣襯著肌膚如雪返奉。 梳的紋絲不亂的頭發(fā)上贝搁,一...
    開封第一講書人閱讀 49,730評論 1 289
  • 那天,我揣著相機(jī)與錄音芽偏,去河邊找鬼雷逆。 笑死,一個胖子當(dāng)著我的面吹牛污尉,可吹牛的內(nèi)容都是我干的膀哲。 我是一名探鬼主播,決...
    沈念sama閱讀 38,882評論 3 404
  • 文/蒼蘭香墨 我猛地睜開眼被碗,長吁一口氣:“原來是場噩夢啊……” “哼某宪!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起锐朴,我...
    開封第一講書人閱讀 37,643評論 0 266
  • 序言:老撾萬榮一對情侶失蹤兴喂,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體衣迷,經(jīng)...
    沈念sama閱讀 44,095評論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡畏鼓,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,448評論 2 325
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了蘑险。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片滴肿。...
    茶點(diǎn)故事閱讀 38,566評論 1 339
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖佃迄,靈堂內(nèi)的尸體忽然破棺而出泼差,到底是詐尸還是另有隱情,我是刑警寧澤呵俏,帶...
    沈念sama閱讀 34,253評論 4 328
  • 正文 年R本政府宣布堆缘,位于F島的核電站,受9級特大地震影響普碎,放射性物質(zhì)發(fā)生泄漏吼肥。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,829評論 3 312
  • 文/蒙蒙 一麻车、第九天 我趴在偏房一處隱蔽的房頂上張望缀皱。 院中可真熱鬧,春花似錦动猬、人聲如沸啤斗。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,715評論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽钮莲。三九已至,卻和暖如春彼水,著一層夾襖步出監(jiān)牢的瞬間崔拥,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 31,945評論 1 264
  • 我被黑心中介騙來泰國打工凤覆, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留链瓦,地道東北人。 一個月前我還...
    沈念sama閱讀 46,248評論 2 360
  • 正文 我出身青樓盯桦,卻偏偏與公主長得像慈俯,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子俺附,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,440評論 2 348

推薦閱讀更多精彩內(nèi)容