新聞中心
隨著企業(yè)級軟件的廣泛應用,越來越多的企業(yè)開始轉(zhuǎn)向GitLab作為其代碼倉庫管理平臺。而GitLab不僅提供了代碼倉庫管理的功能,還支持CI/CD流水線、集成測試等一系列功能。但是,在安裝GitLab的過程中,配置數(shù)據(jù)庫往往是最困難的一步。

網(wǎng)站建設哪家好,找成都創(chuàng)新互聯(lián)!專注于網(wǎng)頁設計、網(wǎng)站建設、微信開發(fā)、微信平臺小程序開發(fā)、集團企業(yè)網(wǎng)站建設等服務項目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了福安免費建站歡迎大家使用!
該教程旨在提供一個輕松搭建數(shù)據(jù)庫的方法,演示如何在Linux系統(tǒng)上搭建GitLab所需的PostgreSQL數(shù)據(jù)庫。
步驟一:安裝PostgreSQL
在開始之前,請確保您所使用的Linux系統(tǒng)已正確地配置了軟件包管理器。此教程的示例基于CentOS 7,使用yum軟件包管理器。
要安裝PostgreSQL,請打開終端并輸入以下命令:
“`
sudo yum install postgresql-server postgresql-contrib -y
“`
安裝過程中,您可能會看到一些安裝腳本和進程的輸出信息。在安裝完成后,請運行以下命令對PostgreSQL數(shù)據(jù)庫進行初始化:
“`
sudo postgresql-setup initdb
“`
初始化完成后,您可以啟動PostgreSQL服務并將其設置為開機自啟。運行以下命令:
“`
sudo systemctl start postgresql
sudo systemctl enable postgresql
“`
步驟二:創(chuàng)建GitLab數(shù)據(jù)庫
在安裝并啟動PostgreSQL后,我們需要進入PostgreSQL Shell并創(chuàng)建一個名為gitlabhq_production的數(shù)據(jù)庫。我們可以使用以下命令連接到PostgreSQL Shell:
“`
sudo -u postgres psql
“`
連接成功后,您將看到一個提示符,指示您連接后繼續(xù)執(zhí)行的操作。請在此提示符下輸入以下命令以創(chuàng)建gitlabhq_production數(shù)據(jù)庫:
“`
CREATE DATABASE gitlabhq_production;
“`
創(chuàng)建完畢后,請退出PostgreSQL Shell:
“`
\q
“`
步驟三:創(chuàng)建GitLab數(shù)據(jù)庫用戶
我們成功地創(chuàng)建了GitLab所需的數(shù)據(jù)庫,但是我們還需要創(chuàng)建一個用戶才能成功地連接到該數(shù)據(jù)庫。為此,請運行以下命令連接到PostgreSQL Shell:
“`
sudo -u postgres psql
“`
提示符下,運行以下命令以創(chuàng)建名為gitlab的由PostgreSQL管理的用戶:
“`
CREATE USER gitlab CREATEDB;
“`
請記下此用戶的密碼,我們稍后會用到。
成功創(chuàng)建用戶后,請使用以下命令為該用戶授予權(quán)限:
“`
GRANT ALL PRIVILEGES ON DATABASE gitlabhq_production TO gitlab;
“`
現(xiàn)在,我們已經(jīng)成功地創(chuàng)建了一個數(shù)據(jù)庫和用戶,可以繼續(xù)安裝GitLab。
結(jié)論
將GitLab部署在服務器上是為團隊提供一個集成解決方案的絕佳方式,幫助項目團隊更好地管理和維護其代碼版本。在搭建GitLab之前,安裝和設置PostgreSQL數(shù)據(jù)庫可能非常棘手,但是有了上面的簡單三個步驟,您現(xiàn)在可以輕松對GitLab進行快速部署。
相關(guān)問題拓展閱讀:
- centos5.5怎么安裝gitlab
centos5.5怎么安裝gitlab
#gitlab基于ruby開發(fā)模仿Github的版本控制軟件,因為信知是開源的,,但是我們確實有這樣的需求,相比Gtihub來說可以減少很多成本.
#從安裝ruby、git、數(shù)據(jù)庫、web、和gitlab到訪問,一定要有耐心.
#安裝環(huán)境
### uname -r
##2.6.32-279.el6.x86_64
### cat /etc/redhat-release
##CentOS release 6.3 (Final)
一.安裝依賴
## 安裝epel-release
yum -y install
#安裝ruby依賴包
## packages (from rvm install message):
yum -y install libicu-devel patch gcc-c++ readline-devel zlib-devel libffi-devel openssl-devel make autoconf automake libtool bison libxml2-devel libxslt-devel libyaml-devel mysql-devel
#安裝或者歲咐更新git
yum -y remove git
yum -y install zlib-devel openssl-devel cpio expat-devel gettext-devel curl-devel perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker
wget
tar -zxf git-1.8.3.4.tar.gz
cd git-1.8.3.4
make prefix=/usr all
make prefix=/usr install
cd ..
#安裝前版本
# git –version
git version 1.7.1
#安裝后版本
# git –version
git version 1.8.3.4
二.安裝RVM
#RVM工具
curl -L get.rvm.io | bash -s stable
#出現(xiàn)以下信息為安裝成功
# Administrator,
#
# Thank you for using RVM!
# We sincerely hope that RVM helps to make your life easier and more enjoyable!!!
#
# ~Wayne, Michal & team.
#加載RVM,改名(使用淘寶源)
source /etc/profile.d/rvm.sh
cp /usr/local/rvm/config/db /usr/local/rvm/config/db.bk
sed -i ‘s#ftp.ruby-lang.org/pub/ruby#ruby.taobao.org/mirrors/ruby#’ /usr/local/rvm/config/db
sed -i ‘s#cache.ruby-lang.org/pub/ruby#ruby.taobao.org/mirrors/ruby#’ /usr/local/rvm/config/db
#安裝libyaml(防止后期報錯,可不滑雀消裝)
rvm pkg install libyaml
三.安裝ruby
#安裝ruby
#rvm install 2.0.0-p247 –with-libyaml-dir=/usr/local/rvm/usr
#rvm –default use 2.0.0-p247
rvm install 2.0.0-p353 –with-libyaml-dir=/usr/local/rvm/usr
rvm –default use 2.0.0-p353
#引用淘寶ruby源
gem sources –remove
gem sources -a
gem sources -l
#安undler
gem install bundler –no-ri –no-rdoc
四.安裝gitlab-shell
#創(chuàng)建用戶git
adduser –system –create-home –comment ‘GitLab’ git
#復制gitlab-shell到本地
su – git -c “git clone
“
su – git -c “cd gitlab-shell;git checkout v1.7.0”
##修改配置文件
su – git -c “cp gitlab-shell/config.yml.example gitlab-shell/config.yml”
##安裝
su – git -c “gitlab-shell/bin/install”
五.安裝Redis和mysql
#安裝Redis,據(jù)說高級特性需要
yum -y install redis ;service redis start ; chkconfig redis on
#安裝mysql
#安裝Mysql數(shù)據(jù)庫.略過,以及數(shù)據(jù)庫操作
##yum install -y mysql-server mysql-devel ; chkconfig mysqld on ; service mysqld start
#編譯安裝宣告下變量
##export PATH=”/opt/mysql/bin:$PATH”
##echo “export PATH=”/opt/mysql/bin:$PATH””>>/etc/profile
##修改root密碼
#echo “UPDATE mysql.user SET Password=PASSWORD(‘$MYSQL_ROOT_PW’) WHERE User=’root’; FLUSH PRIVILEGES;” | mysql -u root
##創(chuàng)建gitlab數(shù)據(jù)庫
#echo “CREATE DATABASE IF NOT EXISTS gitlabhq_production DEFAULT CHARACTER SET ‘utf8’ COLLATE ‘utf8_unicode_ci’;” | mysql -u root
CREATE DATABASE IF NOT EXISTS gitlabhq_production DEFAULT CHARACTER SET ‘utf8’ COLLATE ‘utf8_unicode_ci’;
##創(chuàng)建連接數(shù)據(jù)庫用戶
grant all on gitlabhq_production.* to gitlab@localhost identified by ‘123456’;
六.安裝gitlab
#復制GitLab到本地
su – git -c “git clone
gitlab”
## 檢查
su – git -c “cd gitlab;git checkout 5-4-stable”
#以下操作在/home/git/gitlab
cd /home/git/gitlab
### 復制配置文件
su git -c “cp config/gitlab.yml.example config/gitlab.yml”
### 修改配置文件主機名(可以不做)
sed -i “s/ host: localhost/ host: gitlab.test/g” config/gitlab.yml
### 修改郵件地址
sed -i “s/from: gitlab@localhost/from: /g” config/gitlab.yml
#修改puma.rb文件
su git -c “cp config/puma.rb.example config/puma.rb”
sed -i “s/0.0.0.0:9292/127.0.0.1:3000/g” /home/git/gitlab/config/puma.rb
sed -i “s/# bind/bind/g” /home/git/gitlab/config/puma.rb
#為git用戶授權(quán)
su git -c “chown -R git /home/git/gitlab/log/;chmod -R u+rwx /home/git/gitlab/log/;chown -R git /home/git/gitlab/tmp/;chmod -R u+rwx /home/git/gitlab/tmp/;mkdir /home/git/gitlab-satellites;mkdir /home/git/gitlab/tmp/pids/;chmod -R u+rwx /home/git/gitlab/tmp/pids/;mkdir /home/git/gitlab/tmp/sockets/;chmod -R u+rwx /home/git/gitlab/tmp/sockets/;mkdir /home/git/gitlab/public/uploads;chmod -R u+rwX /home/git/gitlab/public/uploads”
### 復制數(shù)據(jù)配置文件
su git -c “cp config/database.yml.mysql config/database.yml”
### 設置mysql用戶和密碼
sed -i “s/root/gitlab/g” config/database.yml
sed -i “s/secure password/123456/g” config/database.yml
### 配置git用戶
su git -c ‘git config –global user.name “GitLab”‘
su git -c ‘git config –global user.email “gitlab@$GL_HOSTNAME”‘
七.安裝 Gems
## 安裝
gem install charlock_holmes –version ‘0.6.9’
#bundle使用淘寶源,并且安裝(時間長.)
sed -i ‘1s/https/http/g’ /home/git/gitlab/Gemfile
sed -i ‘1s/rubygems/ruby.taobao/g’ /home/git/gitlab/Gemfile
#安undle
su git -c “bundle install –deployment –without development test postgres”
八.初始化數(shù)據(jù)庫
#初始化數(shù)據(jù)庫
export force=yes
su git -c “bundle exec rake gitlab:start RAILS_ENV=production”
su git -c “bundle exec rake gitlab:setup RAILS_ENV=production”
#初始化在數(shù)據(jù)庫里添加數(shù)據(jù),最后后會出現(xiàn):
#用戶名:
#密 碼:5iveL!fe
#su git -c “bundle exec rake gitlab:env:info RAILS_ENV=production”
九.啟動腳本
#curl –output /etc/init.d/gitlab
#chmod +x /etc/init.d/gitlab
curl –output /etc/init.d/gitlab
chmod +x /etc/init.d/gitlab
#在17行后添加2行內(nèi)容
sed -i “17 a source /etc/profile.d/rvm.shnrvm use 1.9.3-p448” /etc/init.d/gitlab
#或者復制
##cp /home/git/gitlab/lib/support/init.d/gitlab /etc/init.d/
#添加到開機啟動項
chkconfig gitlab on
#啟動
/etc/init.d/gitlab start
十.配置web站點
#配置nginx
#安裝nginx,(編譯安裝和rpm都能實現(xiàn))
# yum -y install nginx
#下載nginx下的gitlab.conf文件
curl –output /etc/nginx/conf.d/gitlab.conf
#修改下server標簽監(jiān)聽端口和域名
vim /etc/nginx/conf.d/gitlab.conf
server {
listen 80;
server_name gitlab.wine.cn;
#..略..
}
更改安裝目錄權(quán)限
# chown -R git:git /etc/nginx
#更改nginx所屬用戶
#注意:
#需要nginx用戶改為git,否則會出現(xiàn)502訪問錯誤.
vim /etc/nginx/nginx.conf
#usernginx;
usergit;
/etc/init.d/gitlab start
/etc/init.d/nginx start
#然后訪問
gitlab.wine.cn
#####以下是報錯環(huán)節(jié),沒怎么整理很亂###################
# sh gitlab start
Could not find mysql2-0.3.11 in any of the sources
Run `bundle install` to install missing gems.
關(guān)于gitlab 部署 數(shù)據(jù)庫的介紹到此就結(jié)束了,不知道你從中找到你需要的信息了嗎 ?如果你還想了解更多這方面的信息,記得收藏關(guān)注本站。
香港服務器選創(chuàng)新互聯(lián),2H2G首月10元開通。
創(chuàng)新互聯(lián)(www.cdcxhl.com)互聯(lián)網(wǎng)服務提供商,擁有超過10年的服務器租用、服務器托管、云服務器、虛擬主機、網(wǎng)站系統(tǒng)開發(fā)經(jīng)驗。專業(yè)提供云主機、虛擬主機、域名注冊、VPS主機、云服務器、香港云服務器、免備案服務器等。
本文題目:GitLab部署教程:輕松搭建數(shù)據(jù)庫(gitlab部署數(shù)據(jù)庫)
標題路徑:http://www.fisionsoft.com.cn/article/ccohhip.html


咨詢
建站咨詢
