新聞中心
centos 7 安裝 Gitlab
安裝基本系統(tǒng)與依賴包
安裝 Gitlab 依賴的工具

創(chuàng)新互聯(lián)建站-專業(yè)網(wǎng)站定制、快速模板網(wǎng)站建設(shè)、高性價(jià)比天河網(wǎng)站開(kāi)發(fā)、企業(yè)建站全套包干低至880元,成熟完善的模板庫(kù),直接使用。一站式天河網(wǎng)站制作公司更省心,省錢,快速模板網(wǎng)站建設(shè)找我們,業(yè)務(wù)覆蓋天河地區(qū)。費(fèi)用合理售后完善,10年實(shí)體公司更值得信賴。
yum -y update
yum -y groupinstall 'Development Tools'
yum -y install readline readline-devel ncurses-devel gdbm-devel glibc-devel tcl-devel openssl-devel curl-devel expat-devel db4-devel byacc sqlite-devel libyaml libyaml-devel libffi libffi-devel libxml2 libxml2-devel libxslt libxslt-devel libicu libicu-devel system-config-firewall-tui git redis ruby sudo wget crontabs logwatch logrotate perl-Time-HiRes
安裝 Redis
訪問(wèn) http://www.redis.io/download,下載 Redis 源代碼。
wget http://download.redis.io/releases/redis-3.0.0.tar.gz
tar zxvf redis-3.0.0.tar.gz
cd redis-3.0.0
make
若在編譯過(guò)程中出錯(cuò),則可以執(zhí)行下面的命令:
sudo make test
安裝:
sudo make install
sudo ./utils/install_server.sh
配置
創(chuàng)建 /etc/init.d/redis 并使用下面的代碼作為啟動(dòng)腳本。
添加如下內(nèi)容:
###########################
PATH=/usr/local/bin:/sbin:/usr/bin:/bin
REDISPORT=6379
EXEC=/usr/local/bin/redis-server
REDIS_CLI=/usr/local/bin/redis-cli
PIDFILE=/var/run/redis.pid
CONF="/etc/redis/6379.conf"
case "$1" in
start)
if [ -f $PIDFILE ]
then
echo "$PIDFILE exists, process is already running or crashed"
else
echo "Starting Redis server..."
$EXEC $CONF
fi
if [ "$?"="0" ]
then
echo "Redis is running..."
fi
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
$REDIS_CLI -p $REDISPORT SHUTDOWN
while [ -x ${PIDFILE} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
fi
;;
restart|force-reload)
${0} stop
${0} start
;;
*)
echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2
exit 1
esac
##############################
保存后,添加可執(zhí)行權(quán)限:
sudo chmod +x /etc/init.d/redis
確保 redis 能隨系統(tǒng)啟動(dòng):
vi /etc/rc.d/rc.local
在文件末尾添加下面這行:
service redis start
然后使用上面同樣的命令啟動(dòng) redis 服務(wù):
service redis start
安裝郵件服務(wù)器
yum -y install postfix
安裝Git
先刪除系統(tǒng)中原有的老版本 git:
yum -y remove git
yum install zlib-devel perl-CPAN gettext curl-devel expat-devel gettext-devel openssl-devel
從官方網(wǎng)站下載源代碼進(jìn)行:
curl --progress https://www.kernel.org/pub/software/scm/git/git-2.4.0.tar.gz | tar xz
cd git-2.4.0/
./configure
make
make prefix=/usr/local install
然后使用下面這個(gè)命令檢測(cè)安裝是否有效:
which git
安裝 ruby
如果 ruby 的版本低于 2.0 的話,則需要重新安裝 ruby。
cd ~
curl --progress ftp://ftp.ruby-lang.org/pub/ruby/2.2/ruby-2.2.2.tar.gz | tar xz
cd ruby-2.2.2
./configure --disable-install-rdoc
make
make prefix=/usr/local install
為 Gitlab 添加系統(tǒng)用戶
adduser --system --shell /bin/bash --comment 'GitLab' --create-home --home-dir /home/git/ git
為了包含/usr/local/bin到git用戶的$PATH,一個(gè)方法是編輯超級(jí)用戶文件。以管理員身份運(yùn)行:
visudo
然后搜索:
Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin
將其改成:
Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
安裝數(shù)據(jù)庫(kù)
MySQL 已經(jīng)不再包含在 CentOS 7 的源中,而改用了 MariaDB,先搜索 MariaDB 現(xiàn)有的包:
rpm -qa | grep mariadb
然后全部刪除:
rpm -e --nodeps mariadb-*
然后創(chuàng)建 /etc/yum.repos.d/MariaDB.repo:
vi /etc/yum.repos.d/MariaDB.repo
將以下內(nèi)容添加至該文件中:
# MariaDB 10.0 CentOS repository list - created 2015-05-04 19:16 UTC
# http://mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.0/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
然后運(yùn)行下面命令安裝 MariaDB 10.0:
sudo yum install MariaDB-server MariaDB-client
然后啟動(dòng) MariaDB 服務(wù):
service mysql start
接著運(yùn)行 mysql_secure_installation:
mysql_secure_installation
登錄 MariaDB 并創(chuàng)建相應(yīng)的數(shù)據(jù)庫(kù)用戶與數(shù)據(jù)庫(kù):
mysql -uroot -p
CREATE USER 'git'@'localhost' IDENTIFIED BY '$password';
SET storage_engine=INNODB;
CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;
GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'git'@'localhost';
\q
嘗試使用新用戶連接數(shù)據(jù)庫(kù):
sudo -u git -H mysql -u git -p -D gitlabhq_production
\q
安裝 Gitlab
克隆源
sudo -u -git cd /home/git
sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 7-10-stable gitlab
配置
cd /home/git/gitlab
# Copy the example GitLab config
# 復(fù)制GitLab的示例配置文件
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 # 確保修改“l(fā)ocalhost”為你的GitLab主機(jī)的FQDN # # If you want to use https make sure that you set `https` to `true`. See #using-https for all necessary details. # 如果你想要使用https確保你設(shè)置了`https`為`true`。具體必要的細(xì)節(jié)參見(jiàn)#using-https # # If you installed Git from source, change the git bin_path to /usr/local/bin/git # 如果你從源代碼安裝了Git,修改git的bin_path為/usr/local/bin/git sudo -u git -H editor config/gitlab.yml # Make sure GitLab can write to the log/ and tmp/ directories # 確保GitLab可以寫入log/和temp/目錄 chown -R git {log,tmp} chmod -R u+rwX {log,tmp} # Create directory for satellites # 為衛(wèi)星(?)創(chuàng)建目錄 sudo -u git -H mkdir /home/git/gitlab-satellites chmod u+rwx,g+rx,o-rwx /home/git/gitlab-satellites # Make sure GitLab can write to the tmp/pids/ and tmp/sockets/ directories # 確保GitLab可以寫入tmp/pids/和temp/sockets/目錄 chmod -R u+rwX tmp/{pids,sockets} # Make sure GitLab can write to the public/uploads/ directory # 確保GitLab可以寫入public/uploads/目錄 chmod -R u+rwX public/uploads # Copy the example Unicorn config # 復(fù)制Unicorn的示例配置文件 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 # 啟用集群模式如果你期望擁有一個(gè)高負(fù)載實(shí)例 # 附:修改worker的數(shù)量到3用于2GB內(nèi)存的服務(wù)器 sudo -u git -H editor config/unicorn.rb # Copy the example Rack attack config # 復(fù)制Rack attack的示例配置文件 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 config/gitlab.yml # 為git用戶配置Git全局設(shè)定,當(dāng)通過(guò)web修改時(shí)有用 # 修改user.email根據(jù)config/gitlab.yml中的設(shè)定 sudo -u git -H git config --global user.name "GitLab" sudo -u git -H git config --global user.email "gitlab@localhost" sudo -u git -H git config --global core.autocrlf input
數(shù)據(jù)庫(kù)配置
# MySQL only:
# 僅限MySQL:
sudo -u git cp config/database.yml.mysql config/database.yml
# MySQL and remote PostgreSQL only:
# Update username/password in config/database.yml. # You only need to adapt the production settings (first part). # If you followed the database guide then please do as follows: # Change 'secure password' with the value you have given to $password # You can keep the double quotes around the password # 僅限MySQL和遠(yuǎn)程PostgreSQL: # 在config/database.yml中更新用戶名/密碼; # 你只需要適配生產(chǎn)設(shè)定(第一部分); # 如果你跟從數(shù)據(jù)庫(kù)向?qū)?,?qǐng)按以下操作: # 修改'secure password'使用你剛才設(shè)定的$password; # 你可以保留密碼兩端的雙引號(hào)。 sudo -u git -H editor config/database.yml # PostgreSQL and MySQL: # Make config/database.yml readable to git only # PostgreSQL和MySQL: # 設(shè)置config/database.yml僅對(duì)git可讀。 sudo -u git -H chmod o-rwx config/database.yml
安裝 Gems
cd /home/git/gitlab
# For users from China mainland only
# 僅限中國(guó)大陸用戶
nano /home/git/gitlab/Gemfile
source "http://ruby.taobao.org" // 原始 source "https://rubygems.org/"
# For MySQL (note, the option says "without ... postgres")
sudo -u git -H bundle install --deployment --without development test postgres aws
Install GitLab shell
安裝GitLab Shell
GitLab Shell是一個(gè)專門為GitLab開(kāi)發(fā)的SSH訪問(wèn)和源管理軟件。
# Go to the Gitlab installation folder:
# 轉(zhuǎn)到GitLab安裝目錄:
cd /home/git/gitlab
# For users from China mainland only
# 僅限中國(guó)大陸用戶
nano /home/git/gitlab/Gemfile
source "http://ruby.taobao.org" // 原始 source "https://rubygems.org/"
# Run the installation task for gitlab-shell (replace `REDIS_URL` if needed):
# 運(yùn)行g(shù)itlab-shell的安裝任務(wù)(替換`REDIS_URL`如果有需要的話):
sudo -u git -H bundle exec rake gitlab:shell:install[v1.9.6] REDIS_URL=redis://localhost:6379 RAILS_ENV=production
# By default, the gitlab-shell config is generated from your main gitlab config.
# 默認(rèn)的,gitlab-shell的配置文件是由你的gitlab主配置文件生成的。
#
# Note: When using GitLab with HTTPS please change the following:
# - Provide paths to the certificates under `ca_file` and `ca_path options.
# - The `gitlab_url` option must point to the https endpoint of GitLab.
# - In case you are using self signed certificate set `self_signed_cert` to `true`.
# See #using-https for all necessary details.
# 提示:當(dāng)通過(guò)HTTPS使用GitLab時(shí),請(qǐng)做出如下更改:
# - 提供證書的路徑在`ca_file`和`ca_path`選項(xiàng);
# - `gitlab_url`選項(xiàng)必須指向GitLab的https端點(diǎn);
# - 如果你使用自簽名的證書,設(shè)置`self-signed_cert`為`true`。
# 所有必需的具體細(xì)節(jié)參見(jiàn)#using-https
#
# You can review (and modify) it as follows:
# 你可以檢查(并修改該)通過(guò)以下方法:
sudo -u git -H editor /home/git/gitlab-shell/config.yml
# Ensure the correct SELinux contexts are set
# Read http://wiki.centos.org/HowTos/Network/SecuringSSH
# 確保正確的SELinux上下文被設(shè)置
# 閱讀http://wiki.centos.org/HowTos/Network/SecuringSSH
restorecon -Rv /home/git/.ssh
初始化數(shù)據(jù)庫(kù)和激活高級(jí)功能
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:'
提示:你可以設(shè)置管理員密碼通過(guò)在環(huán)境變量GITLAB_ROOT_PASSWORD中提供,例如:
sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production GITLAB_ROOT_PASSWORD=newpassword
安裝初始化腳本
下載初始化腳本(將放在/etc/init.d/gitlab):
sudo cp lib/support/init.d/gitlab /etc/init.d/gitlab
chmod +x /etc/init.d/gitlab
chkconfig --add gitlab
設(shè)置GitLab開(kāi)機(jī)啟動(dòng):
chkconfig gitlab on
設(shè)置日志翻轉(zhuǎn)
cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab
檢查應(yīng)用狀態(tài)
sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production
編譯靜態(tài)文件
sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production
啟動(dòng)實(shí)例
/etc/init.d/gitlab start 本文題目:CentOS7安裝Gitlab
本文URL:http://fisionsoft.com.cn/article/ccspjdp.html


咨詢
建站咨詢
