官方文檔:https://docs.gitlab.com/ee/install/installation.html
推薦使用yum安裝:http://blog.51cto.com/qiangsh/1945313
概述
本帖針對Centos6/REHL6系統
Gitlab的安裝過程主要包括以下組件的配置:
關閉selinux
# 修改/etc/selinux/config 文件 將SELINUX=enforcing改爲SELINUX=disabled ,然後重啓電腦 # sestatus -v 查看selinux狀態 SELinux status: disabled #說明已關閉selinux
GitLab軟件包
所有GitLab軟件包都會發布到我們的軟件包服務器上,並且可以下載。我們維持五個回購:
GitLab EE:適用於官方企業版版本
GitLab CE:用於官方Community Edition版本
Unstable:適用於發佈候選版和其他不穩定版本
Nighty Builds:每晚製作
安裝軟件包及版本要求
Ubuntu/Debian/CentOS/RHEL**
ruby 2.0+
git 1.7.10+
redis 2.0+
MySQL or PostgreSQ
1.安裝軟件包及解決依賴項
添加EPEL源:
wget -O /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 https://mirrors.tuna.tsinghua.edu.cn/epel/RPM-GPG-KEY-EPEL-6 rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 # 安裝`epel-release-latest-6.noarch.rpm`包,啓用EPEL rpm -Uvh http://mirrors.ustc.edu.cn/epel/epel-release-latest-6.noarch.rpm yum groupinstall "Development tools" yum install autoconf automake bison build-essential byacc checkinstall cmake cpio crontabs curl curl-devel db4-devel expat-devel gcc-c++ gdbm-devel gettext gettext-devel glibc-devel libcurl4-openssl-dev libexpat1-dev libffi libffi-dev libffi-devel libgdbm-dev libicu libicu-dev libicu-devel libkrb5-dev libncurses5-dev libreadline-dev libssl-dev libtool libxml2 libxml2-dev libxml2-devel libxslt libxslt-dev libxslt-devel libyaml libyaml-dev libyaml-devel libz-dev logrotate logwatch make ncurses-devel openssh-server openssl-devel patch pcre-devel perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker perl-Time-HiRes pkg-config postfix python-devel python-docutils readline readline-devel sqlite-devel sudo system-config-firewall-tui tcl-devel vim wget zlib1g-dev zlib-devel
安裝git(不建議升級到最新版本,會報錯)
如果已經用yum安裝過git,並且版本低於2.7.4,要先卸載掉舊的版本
yum remove git
使用源碼編譯安裝git
mkdir /tmp/git && cd /tmp/git curl -O --progress https://www.kernel.org/pub/software/scm/git/git-2.8.5.tar.gz tar zxvf git-2.8.5.tar.gz cd git-2.8.5 ./configure make prefix=/usr/local all # 安裝到/usr/local/bin sudo make prefix=/usr/local install # 驗證git版本號 git --version #創建軟連接 ln -s /usr/local/bin/git /usr/bin/git
2.添加系統用戶
我們添加一個用來管理運行Gitlab的用戶git
adduser --system --shell /bin/bash --comment 'GitLab' --create-home --home-dir /home/git/ git # 修改git用戶的環境變量PATH,以root用戶運行 visudo # 找到下面一行 Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin #修改爲 Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin
3.安裝ruby環境
在Gitlab生產環境使用Ruby版本管理工具RVM,rbenv或者chruby常常會帶來很多疑難雜症.比如Gitlab-shell版本管理器調用OpenSSH的功能以防止越過ssh對倉庫進行pull和push操作.而前面提到的三個版本管理器不支持這樣的功能,所以我們強烈建議大家按照下面的方式來安裝Ruby.
Note: The current supported Ruby (MRI) version is 2.3.x. GitLab 9.0 dropped
support for Ruby 2.1.x.
如果系統上存在舊的Ruby1.8,先刪除掉:
yum remove ruby
下載Ruby源碼,編譯安裝:
mkdir /data/package # 這裏替換官方文檔的下載地址爲mirrors.ustc.edu.cn提供的鏡像地址 curl --remote-name --progress https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.7.tar.gz tar zxvf ruby-2.3.7.tar.gz cd ruby-2.3.7 ./configure --disable-install-rdoc make sudo make install 安裝完成後,重新登錄終端確保$PATH生效,檢測ruby的安裝成功與否: ruby -v ln -s /usr/local/bin/ruby /usr/bin/ruby
國內使用Ruby的Gem和Bundler必須要做的事情:
# 修改git用戶gem安裝源爲淘寶 sudo -u git -H gem sources --add https://ruby.taobao.org/ --remove https://rubygems.org/ # 確保git用戶當前gems源爲淘寶 sudo -u git -H gem sources -l *** CURRENT SOURCES *** 備:gems源中科大: https://gems.ruby-china.org/
安裝bundle包(root用戶)
sudo gem install bundler --no-ri --no-rdoc
4.安裝GO
從Gitlab8.0開始,Git的HTTP請求由gitlab-git-http-server來處理.我們需要Go編譯器來安裝gitlab-git-http-server.下面一系列的指令都將假定你用的是64位的Linux系統.你也可以在GoLang官方網站下載其他平臺的Go編譯器.
#刪除舊的文件夾 sudo rm -rf /usr/local/go cd /data/package curl --remote-name --progress https://storage.googleapis.com/golang/go1.8.3.linux-amd64.tar.gz tar -C /usr/local/ -xzf go1.8.3.linux-amd64.tar.gz sudo ln -sf /usr/local/go/bin/{go,godoc,gofmt} /usr/local/bin/ #驗證go是否安裝正確 # go version go version go1.8.3 linux/amd64
5.安裝Node
因爲 GitLab 9.X.X, GitLab 需要使用node >= v4.3.0 編譯javascript 資產和 yarn >= v0.17.0 to 管理 javascript
的依賴.在許多發行版的官方套件庫提供的版本已經過時了,所以我們需要通過以下命令安裝:
Node安裝文檔:http://blog.51cto.com/qiangsh/2095944
# install yarn npm install -g yarn #驗證安裝情況 yarn --version
6.安裝數據庫
Gitlab官方建議我們用PostgreSQL數據庫.如果喜歡用Mysql請前往Gitlab使用Mysql數據庫的安裝說明.
6-1.安裝數據庫-mysql
安裝mysql數據庫,設置數據庫管理員密碼
#下載yum倉庫文件: wget http://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm #下載完成後將Yum庫導入到你的本地: sudo yum localinstall mysql-community-release-el6-*.noarch.rpm #安裝MySQLServer: yum install mysql-server mysql-devel mysql-client libmysqlclient-dev #啓動mysql服務 /etc/init.d/mysqld start #MySQL安全配置嚮導 mysql_secure_installation --------------------------------------------------------------------------------- Enter current password for root (enter for none): <–初次運行直接回車 Set root password? [Y/n] <– 是否設置root用戶密碼,輸入y並回車或直接回車 Remove anonymous users? [Y/n] <– 是否刪除匿名用戶,生產環境建議刪除,所以直接回車 Disallow root login remotely? [Y/n] <–是否禁止root遠程登錄,根據自己的需求選擇Y/n並回車,建議禁止 Remove test database and access to it? [Y/n] <– 是否刪除test數據庫,直接回車 Reload privilege tables now? [Y/n] <– 是否重新加載權限表,直接回車
創建新用戶和數據庫給gitlab使用
# 登錄數據庫 $ mysql -u root -p # 輸入root密碼 # 爲gitlab創建使用用戶 mysql> CREATE USER 'git'@'localhost' IDENTIFIED BY 'gitlab賬號的密碼'; # 創建gitlaba使用的數據庫 mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`; # 給予gitlab用戶權限 mysql> GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'git'@'localhost' IDENTIFIED BY 'gitpasswd'; # 刷新權限 mysql> flush privileges; # 查看創建的用戶 mysql> select user,host,password from mysql.user;
#測試新建的用戶能否登陸mysql
mysql -u git -p -h localhost mysql> show databases; +---------------------+ | Database | +---------------------+ | information_schema | | gitlabhq_production | +---------------------+ 2 rows in set (0.00 sec)
6-2.安裝數據庫-postgresql
配置postgresql安裝源:
https://wiki.postgresql.org/wiki/YUM_Installation#Configure_your_YUM_repository
# 修改/etc/yum.repos.d/CentOS-Base.repo,在[base]和[update]段落添加下面的配置 exclude=postgresql* # 安裝postgresql源 yum localinstall http://mirrors.ustc.edu.cn/postgresql/repos/yum/9.5/redhat/rhel-6-x86_64/pgdg-centos95-9.5-3.noarch.rpm # 安裝postgresql yum install postgresql95-server postgresql95-devel postgresql95-contrib # 默認情況下,postgresql的數據庫文件存放在 /var/lib/pgsql/9.5/data # 初始化 mv /etc/init.d/{postgresql-9.5,postgresql} service postgresql initdb # 啓動postgresql service postgresql start # 配置postgresql自啓動 chkconfig postgresql on # 爲Gitlab創建一個用戶,用戶名爲git cd /home sudo -u postgres psql -d template1 -c "CREATE USER git CREATEDB;" #創建pg_trgm擴展 (required for GitLab 8.6+): sudo -u postgres psql -d template1 -c "CREATE EXTENSION IF NOT EXISTS pg_trgm;" # 創建Gitlab生產環境數據庫並賦予git用戶屬主權限 sudo -u postgres psql -d template1 -c "CREATE DATABASE gitlabhq_production OWNER git;" # 用git用戶測試下是否能登錄剛纔創建的數據庫 sudo -u git -H psql -d gitlabhq_production #檢查是否啓用 pg_trgm 擴展: SELECT true AS enabled FROM pg_available_extensions WHERE name = 'pg_trgm' AND installed_version IS NOT NULL; 如果啓用了擴展,這將產生以下輸出: enabled --------- t (1 row) # 退出數據庫會話 gitlabhq_production> \q # 創建pg_config的軟連接 ln -s /usr/pgsql-9.5/bin/pg_config /usr/bin/pg_config
7.Redis
版本要求: redis版本不低於2.8.
添加redis用戶和組
groupadd redis && useradd -g redis redis -s /sbin/nologin
編譯安裝redis
mkdir /tmp/redis && cd /tmp/redis curl -O --progress http://download.redis.io/releases/redis-3.2.9.tar.gz tar zxvf redis-3.2.9.tar.gz mv redis-3.2.9 /usr/local/redis cd /usr/local/redis make && make install mkdir -p /etc/redis cp redis.conf /etc/redis/
修改redis配置
sudo cp /etc/redis/redis.conf /etc/redis/redis.conf.bak # 讓redis以socket方式啓動 echo 'unixsocket /var/run/redis/redis.sock' | sudo tee -a /etc/redis/redis.conf #給所有成員或redis組賦予權限 echo 'unixsocketperm 770' | sudo tee -a /etc/redis/redis.conf # 啓動守護進程 sed -i 's/daemonize no/daemonize yes/g' /etc/redis/redis.conf # 創建存放socket的目錄 mkdir /var/run/redis sudo chown redis:redis /var/run/redis sudo chmod 755 /var/run/redis # Persist the directory which contains the socket, if applicable if [ -d /etc/tmpfiles.d ]; then echo 'd /var/run/redis 0755 redis redis 10d -' | sudo tee -a /etc/tmpfiles.d/redis.conf fi # 把git用戶加入redis組 sudo usermod -aG redis git
啓動Redis
# 下載redis init 腳本 curl -L http://packages.gitlab.cc/install/init-script/redis/cenots6/redis-server -o /etc/init.d/redis chmod +x /etc/init.d/redis # 啓動redis服務 service redis start # 將redis加入自啓動 chkconfig redis on # 查看redis進程是否啓動 ps aux |grep redis root 3404 0.0 0.0 103320 888 pts/2 S+ 18:00 0:00 grep redis root 6198 0.5 0.1 137764 10028 ? Ssl 10:29 2:20 /usr/local/bin/redis-server 127.0.0.1:6379
8.安裝GitLab-CE
# 我們將gitlab安裝到git用戶的HOME目錄 cd /home/git
克隆gitlab-ce源碼
sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 9-3-stable gitlab
Note: 你可以修改9-3-stable爲master,這樣就可以體驗到最新的版本,但是生產環境不要用master分支哦
配置GitLab-CE
# 進入gitlab目錄 cd /home/git/gitlab # 複製gitlab.yml(Gitlab的主配置文件) sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml # 修改gitlab.yml sudo -u git -H vim config/gitlab.yml host: gitlab.xxx.com ####修改第32行 爲你的域名或者ip port: 80 https: false # 複製 secrets 文件 sudo -u git -H cp config/secrets.yml.example config/secrets.yml sudo -u git -H chmod 0600 config/secrets.yml # 修改 log/ 和 tmp/ 文件夾權限 sudo chown -R git log/ sudo chown -R git tmp/ sudo chmod -R u+rwX,go-w log/ sudo chmod -R u+rwX tmp/ # 修改 tmp/pids/ 和 tmp/sockets/ 文件夾權限 sudo chmod -R u+rwX tmp/pids/ sudo chmod -R u+rwX tmp/sockets/ # 創建 public/uploads/ 文件夾 sudo -u git -H mkdir public/uploads/ # 修改 public/uploads/ 文件夾權限,只有git用戶有訪問權限 sudo chmod 0700 public/uploads # 修改 CI build traces are stored 文件夾的權限 sudo chmod -R u+rwX builds/ # 修改shared/artifacts/文件夾的權限 sudo chmod -R u+rwX shared/artifacts/ # 修改shared/pages/文件夾的權限 sudo chmod -R ug+rwX shared/pages/ # 複製 Unicorn 配置文件 sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb # 查詢CPU核心數 nproc # 如果你想搭建一個高負載的Gitlab實例,可啓用集羣模式. # 修改'worker_processes'參數,至少要跟cpu核心數一樣. # 修改監聽地址和端口,要和下文 gitlab-shell/config.yml 中配置一致 sudo -u git -H vim config/unicorn.rb worker_processes 3 listen "your_IP:8080", :tcp_nopush => true # 複製Rack attack 配置文件 sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb # 爲 git 用戶配置用戶和郵件 sudo -u git -H git config --global user.name "Gitlab" sudo -u git -H git config --global user.email "gitlab@your_domain_name" # 'autocrlf' 需要Web編輯器 sudo -u git -H git config --global core.autocrlf input # 禁止 'git gc --auto' 因爲需要時 GitLab 已經運行 'git gc' sudo -u git -H git config --global gc.auto 0 # Enable packfile bitmaps sudo -u git -H git config --global repack.writeBitmaps true # Enable push options sudo -u git -H git config --global receive.advertisePushOptions true # 複製 Redis 連接配置文件 sudo -u git -H cp config/resque.yml.example config/resque.yml # 如果之前修改過redis socket的路徑,在這個配置文件裏面修改爲當前的路徑. sudo -u git -H vim config/resque.yml ------------------------------------- development: redis://127.0.0.1:6379 test: redis://127.0.0.1:6379 production: unix:/var/run/redis/redis.sock 要說明:確保編輯gitlab.yml與unicorn.rb中設置一致。
注意:如果您想使用HTTPS,請參閱使用HTTPS獲取其他步驟。
修改GitLab DB 設置
# 僅限於Mysql: sudo -u git cp config/database.yml.mysql config/database.yml # 僅限於PostgreSQl: ###sudo -u git cp config/database.yml.postgresql config/database.yml # 以下修改針對MySQL和遠程PostgreSQL,修改username/password. # 修改'secure password' 爲你設置的密碼,沒單獨設置則不改 sudo -u git -H vim config/database.yml production: adapter: mysql2 encoding: utf8 collation: utf8_general_ci reconnect: false database: gitlabhq_production pool: 10 username: git password: "gitpasswd" #修改此處爲你設置的密碼 # host: localhost # socket: /tmp/mysql.sock socket: /var/lib/mysql/mysql.sock # PostgreSQL MySQL都適用: # 修改database.yml的權限,確保git用戶可以讀取該文件. sudo -u git -H chmod o-rwx config/database.yml
安裝Gems包
這個步驟是很多新手頭疼的問題,不過你只要嚴格按照本文關於Ruby環境的搭建來做.還是可以保證你順利的安裝下來的.
Note: 自bundler1.5.2起,你可以使用bundle install -jN(N就是cpu核心數)安裝Gems,速度比之前要快大約60%.詳細的內容可以點此處查看.不過首先要確保你的bundler版本>=1.5.2(運行bundle -v查看).
# 進入gitlab目錄 cd /home/git/gitlab gem sources --add https://ruby.taobao.org/ --remove https://rubygems.org/ # 修改 Gemfile 和 Gemfile.lock vim Gemfile(Gemfile.lock文件也要改,不然報錯) 更改 https://rubygems.org/ 爲: https://ruby.taobao.org/ # 確保只有 https://ruby.taobao.org/ gem sources -l https://ruby.taobao.org/ # 升級gem gem update --system gem -v ####一定要注意選擇自己用的數據庫的命令 # 如果使用 MySQL,執行下面的命令 (note, the option says "without ... postgres") sudo -u git -H bundle install --deployment --without development test postgres aws kerberos # PostgreSQL (note, the option says "without ... mysql") ###sudo -u git -H bundle install --deployment --without development test mysql aws kerberos 筆記: 如果你想去用 Kerberos 做用戶認證, 然後在--without選項中省略Kerberos -------------------------------------------------------------------------------------------- 如果提示下面的錯誤: >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> error occurred while installing charlock_holmes (0.7.3), and Bundler cannot continue. Make sure that `gem install charlock_holmes -v ‘0.7.3’` succeeds before bundling. brew install icu4c or apt-get install libicu-dev 解決辦法: # yum install libicu.x86_64 libicu-devel.x86_64 An error occurred while installing rugged (0.25.1.1), and Bundler cannot continue. Make sure that `gem install rugged -v '0.25.1.1'` succeeds before bundling. 解決辦法: # yum install cmake # gem install rugged -v '0.25.1.1' ERROR: Could not find a valid gem 'charlock_holmes' (= 0.6.9.4), here is why: Unable to download data from https://rubygems.org/ - Errno::ECONNRESET: Connection reset by peer - SSL_connect (https://api.rubygems.org/quick/Marshal.4.8/charlock_holmes-0.6.9.4.gemspec.rz) ERROR: Possible alternatives: charlock_holmes 解決辦法: #yum install libicu-devel An error occurred while installing mysql2 (0.3.20), and Bundler cannot continue. Make sure that `gem install mysql2 -v ‘0.3.20’` succeeds before bundling. #解決辦法 # yum install mysql-community-devel.x86_64 # gem install mysql2 -v '0.3.20 An error occurred while installing re2 (1.0.0), and Bundler cannot continue. Make sure that `gem install re2 -v '1.0.0'` succeeds before bundling. #解決辦法 # yum install -y re2-devel An error occurred while installing pg (0.18.4), and Bundler cannot continue. Make sure that `gem install pg -v ‘0.18.4’` succeeds before bundling. #解決辦法 # gem install pg -v '0.18.4' # yum install postgresql-devel.x86_64 An error occurred while installing sqlite3 (1.3.13), and Bundler cannot continue. Make sure that `gem install sqlite3 -v ‘1.3.13’` succeeds before bundling. # 解決辦法 # yum install sqlite-devel.x86_64 # gem install sqlite3 -v '1.3.13' Bundler::GemRequireError: There was an error while trying to load the gem ‘coffee-rails’. Gem Load Error is: Could not find a JavaScript runtime. See https://github.com/rails/execjs for a list of available runtimes. #解決辦法:因爲execjs需要javascript的支持 #參考這裏:NodeJs的安裝 --------------------------------------------------------------------------------------------
----------以下不需要設置,草稿--------------------------- gem sources --add https://gems.ruby-china.org/ --remove https://rubygems.org/ ----------以上不需要設置,草稿---------------------------
安裝Gitlab-shell
GitLab Shell是專爲GitLab開發的ssh訪問和倉庫管理的軟件.
# 修改gitlab 安裝 gitlab-shell的rake任務腳本 sudo -u git -H sed -i 's/https:\/\/gitlab.com\/gitlab-org\/gitlab-shell.git/https:\/\/git.oschina.net\/qiai365\/gitlab-shell.git/g' /home/git/gitlab/lib/tasks/gitlab/shell.rake # 運行安裝gitlab shell的任務 (根據自己的redis安裝情況修改`REDIS_URL`),這裏如果你事先沒有clone gitlab-shell的倉庫,就會自動clone官方的倉庫進行安裝: sudo -u git -H mkdir -p /home/git/repositories sudo chmod -R ug+rwX,o-rwx /home/git/repositories sudo chmod -R ug-s /home/git/repositories sudo find /home/git/repositories -type d -print0 | sudo xargs -0 chmod g+s # Run the installation task for gitlab-shell (replace `REDIS_URL` if needed): sudo -u git -H bundle exec rake gitlab:shell:install[v5.1.1] REDIS_URL=unix:/var/run/redis/redis.sock RAILS_ENV=production SKIP_STORAGE_VALIDATION=true # 默認情況下,gitlab-shell的配置是根據Gitlab的配置生產的. # 你可以運行下面的命令查看和修改gitlab-shell的配置, # 監聽端口要和/home/git/gitlab/config/unicorn.rb中配置一致 sudo -u git -H vim /home/git/gitlab-shell/config.yml --- user: git gitlab_url: https://localhost:8080/ #使用https http_settings: self_signed_cert: true #如果gitlab_url爲https,修改成true repos_path: "/home/git/repositories/" auth_file: "/home/git/.ssh/authorized_keys" redis: bin: "/usr/bin/redis-cli" namespace: resque:gitlab socket: "/var/run/redis/redis.sock" log_level: INFO audit_usernames: false
注意:如果您想使用HTTPS,請參閱使用HTTPS獲取其他步驟。
注意:請確保您的主機名可以通過適當的DNS記錄或/ etc / hosts中的附加行(“127.0.0.1 hostname”)在機器上解析。例如,如果您將GitLab設置在反向代理之後,這可能是必需的。如果主機名無法解析,最終安裝檢查將會失敗,並顯示“Check GitLab API access:FAILED。code:401”,推送提交將被拒絕,並顯示“[remote rejected] master - > master(hook refused)”。
注意:禁用RubyGems可以大大減少GitLab Shell應用程序的啓動時間。這可以通過幾種方式來完成:
導出
RUBYOPT=--disable-gems
進程的環境變量編譯Ruby以
configure --disable-rubygems
默認禁用RubyGems。不推薦用於系統範圍的Ruby。Omnibus GitLab 替換腳本的shebang行
gitlab-shell/bin/*
安裝成功如圖所示:
安裝gitlab-workhorse
#GitLab-Workhorse 使用 GNU Make. 下面的命令將GitLab-Workhorse 安裝在推薦的位置 /home/git/gitlab-workhorse . cd /home/git/gitlab sudo -u git -H bundle exec rake "gitlab:workhorse:install[/home/git/gitlab-workhorse]" RAILS_ENV=production
#你可以通過提供它作爲一個額外的參數來指定一個不同的Git倉庫: sudo -u git -H bundle exec rake "gitlab:workhorse:install[/home/git/gitlab-workhorse,https://example.com/gitlab-workhorse.git]" RAILS_ENV=production
------------------以下爲舊安裝方法------------------------------------------------ #cd /home/git #sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-workhorse.git #cd gitlab-workhorse #sudo -u git -H git checkout 0.6.5 #sudo -u git -H make ------------------以上爲舊安裝方法------------------------------------------------
初始化數據庫,激活高級特性
cd /home/git/gitlab sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production # 輸入 'yes' 以創建數據庫表 # 當看到以下內容,表示已經安裝完成 Administrator account created: login: root password: your_passwd == Seed from /home/git/gitlab/db/fixtures/production/010_settings.rb
Note: 你能通過提供環境變量設置 Administrator/root 密碼和郵箱, 分別爲GITLAB_ROOT_PASSWORD 和 GITLAB_ROOT_EMAIL , 如下所示。如果你不能設置密碼(它被設置爲默認的) 請等待曝光gitlab到公共互聯網直到安裝完成和你已經登錄到服務器的第一時間。 在第一次登錄時,您將被迫更改默認密碼。.
sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production GITLAB_ROOT_PASSWORD=yourpassword GITLAB_ROOT_EMAIL=youremail
安全設置 secrets.yml
secrets.yml
文件爲每個會話和安全變量存儲密鑰.把這個文件備份到別的地方,但是不要和數據庫備份放在一塊,否則你的數據庫備份損壞會導致這個文件丟失.
安裝Gitlab init腳本
sudo cp lib/support/init.d/gitlab /etc/init.d/gitlab #複製下面這個配置文件,如果你的gitlab不是安裝在/home/git/gitlab目錄,根據自己情況修改這個文件。 sudo cp lib/support/init.d/gitlab.default.example /etc/default/gitlab
設置GItlab爲自啓動
chkconfig gitlab on
安裝Gitaly
# 取用 Gitaly 源 用Git和Go一起編譯 sudo -u git -H bundle exec rake "gitlab:gitaly:install[/home/git/gitaly]" RAILS_ENV=production
你可以通過提供它作爲一個額外的參數來指定一個不同的Git倉庫: sudo -u git -H bundle exec rake "gitlab:gitaly:install[/home/git/gitaly,https://example.com/gitaly.git]" RAILS_ENV=production
接下來, 確保gitaly配置:
# 限制 Gitaly sockets訪問 sudo chmod 0700 /home/git/gitlab/tmp/sockets/private sudo chown git /home/git/gitlab/tmp/sockets/private # 如果你正在用non-default 設置 你必須升級config.toml cd /home/git/gitaly sudo -u git -H vim config.toml
For more information about configuring Gitaly see doc/administration/gitaly.
設置Logrotate
cd /home/git/gitlab sudo cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab
檢查GitLab環境配置
sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production
編譯GetText PO文件
sudo -u git -H bundle exec rake gettext:compile RAILS_ENV=production
生成GitLab前端資源
sudo -u git -H yarn install --production --pure-lockfile #我這步失敗了,先略過 sudo -u git -H bundle exec rake gitlab:assets:compile RAILS_ENV=production NODE_ENV=production
通過修改/home/git/gitlab/config/unicorn.rb
的listen端口,然後重啓gitlab服務,就可以直接訪問服務器ip加端口來訪問gitlab了
啓動GitLab
sudo service gitlab start # 或者 sudo /etc/init.d/gitlab restart
再檢查一次Gitlab的所有組件
sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production # 如果上面的檢查有錯誤,按照提示修復下,再重啓GitLab即可
ERR!測試頁面發現頁面加載不正常
#查看日誌信息: [root@localhost /home/git/gitlab]#tail -f /data/git/gitlab/log/production.log Processing by RootController#index as HTML Completed 200 OK in 14125ms (Views: 10108.5ms | ActiveRecord: 2021.7ms) Started GET "/assets/webpack/webpack_runtime.ec49ef50bd580f1196e6.bundle.js" for 192.168.137.1 at 2017-08-20 18:24:48 +0800 Processing by ApplicationController#route_not_found as JS Parameters: {"unmatched_route"=>"assets/webpack/webpack_runtime.ec49ef50bd580f1196e6.bundle"} Started GET "/assets/application-898ebef5c8f2218228603404f2aad91aa380408797ddc6050f4893b61bee9616.css" for 192.168.137.1 at 2017-08-20 18:24:54 +0800 Security warning: an embedded <script> tag on another site requested protected JavaScript. If you know what you're doing, go ahead and disable forgery protection on this action to permit cross-origin JavaScript embedding. Completed 422 Unprocessable Entity in 2698ms (ActiveRecord: 100.1ms) #解決方法: 1、編輯/home/git/gitlab/config/environments/production.rb ,將 config.serve_static_files = false 替換爲 true: config.serve_static_files = true 2、然後重啓下GITLAB sudo /etc/init.d/gitlab restart
8.安裝Nginx
Note: Nginx is the officially supported web server for GitLab. If you cannot or do not want to use Nginx as your web server, have a look at the GitLab recipes.
mkdir /tmp/nginx && cd /tmp/nginx wget http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm rpm -ivh nginx-release-centos-6-0.el6.ngx.noarch.rpm yum install nginx # 站點配置,複製示例站點配置 cd /home/git/gitlab sudo cp lib/support/nginx/gitlab /etc/nginx/conf.d/gitlab.conf # 編輯配置文件。如果其他用戶安裝Git,修改gitlab路徑 sudo vim /etc/nginx/nginx.conf user git; #修改爲git用戶 ---------------------------------------------------------------------------- sudo vim /etc/nginx/conf.d/gitlab.conf server_name YOUR_SERVER_FQDN; #修改你的域名地址 listen 80 default_server; #檢查nginx配置 sudo nginx -t #啓動nginx sudo service nginx restart
恭喜,安裝完成!
自定義SSH連接
如果您在非標準端口上運行SSH,則必須更改GitLab用戶的SSH配置。
您還需要改變相應的選項(例如ssh_user
,ssh_host
,admin_uri
中)config\gitlab.yml
的文件。
初始登錄
訪問您的Web瀏覽器中的YOUR_SERVER以獲取第一次GitLab登錄。
如果您在安裝過程中未提供root密碼,則會重定向到密碼重置屏幕以提供初始管理員帳戶的密碼。輸入您想要的密碼,然後您將被重定向回登錄屏幕。
默認帳戶的用戶名是root。提供您之前創建的密碼並登錄。登錄後,您可以根據需要更改用戶名。
請享用!
您可以使用sudo service gitlab start
並sudo service gitlab stop
啓動和停止GitLab。
高級設置提示
https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/install/installation.md