本帖針對Centos6/REHL6系統
Gitlab的安裝過程主要包括以下元件的配置:
關閉selinux
安裝軟體包及版本要求
Ubuntu/Debian/CentOS/RHEL**
ruby 2.0+
git 1.7.10+
redis 2.0+
MySQL or PostgreSQL
添加EPEL源:
<code>wget -O /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6 https://mirrors.tuna.tsinghua.edu.cn/epel/RPM-GPG-KEY-EPEL-6</code>
<code>rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6</code>
<code># 安裝`epel-release-latest-6.noarch.rpm`包,啟用EPEL</code>
<code>rpm -Uvh http://mirrors.ustc.edu.cn/epel/epel-release-latest-6.noarch.rpm</code>
<code>yum groupinstall "Development tools"</code>
<code>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</code>
安裝git
如果已經用yum安裝過git,要先解除安裝掉舊的版本
<code>yum remove git</code>
使用源碼編譯安裝git
<code>mkdir /tmp/git && cd /tmp/git</code>
<code>curl -O --progress https://www.kernel.org/pub/software/scm/git/git-2.8.5.tar.gz</code>
<code>tar zxvf git-2.8.5.tar.gz</code>
<code>cd git-2.8.5</code>
<code>./configure</code>
<code>make prefix=/usr/local all</code>
<code># 安裝到/usr/local/bin</code>
<code>sudo make prefix=/usr/local install</code>
<code># 驗證git版本号</code>
<code>git --version</code>
<code>#建立軟連接配接</code>
<code>ln -s /usr/local/bin/git /usr/bin/git</code>
我們添加一個用來管理運作Gitlab的使用者<code>git</code>
<code>adduser --system --shell /bin/bash --comment 'GitLab' --create-home --home-dir /home/git/ git</code>
<code># 修改git使用者的環境變量PATH,以root使用者運作</code>
<code>visudo</code>
<code># 找到下面一行</code>
<code>Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin</code>
<code>#修改為</code>
<code>Defaults secure_path = /sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin</code>
在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,先删除掉:
<code>yum remove ruby</code>
下載下傳Ruby源碼,編譯安裝:
<code>mkdir /tmp/ruby && cd /tmp/ruby</code>
<code># 這裡替換官方文檔的下載下傳位址為mirrors.ustc.edu.cn提供的鏡像位址</code>
<code>curl -O --progress https://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.5.tar.gz</code>
<code>tar zxvf ruby-2.1.5.tar.gz</code>
<code>cd ruby-2.1.5</code>
<code>./configure --disable-install-rdoc</code>
<code>make</code>
<code>sudo make install</code>
<code>安裝完成後,重新登入終端確定$PATH生效,檢測ruby的安裝成功與否:</code>
<code>ruby -v</code>
<code>ln -s /usr/local/bin/ruby /usr/bin/ruby</code>
國内使用Ruby的Gem和Bundler必須要做的事情:
<code># 修改git使用者gem安裝源為淘寶</code>
<code>gem sources --add https://ruby.taobao.org/ --remove https://rubygems.org/ </code>
<code># 確定git使用者目前gems源為淘寶</code>
<code>gem sources -l</code>
<code>*** CURRENT SOURCES ***</code>
<code> </code>
<code>備:gems源中科大: https://gems.ruby-china.org/</code>
安裝bundle包(root使用者)
<code>sudo gem install bundler --no-ri --no-rdoc</code>
安裝mysql資料庫,設定資料庫管理者密碼
<code>#下載下傳yum倉庫檔案:</code>
<code>wget http://dev.mysql.com/get/mysql-community-release-el6-5.noarch.rpm</code>
<code>#下載下傳完成後将Yum庫導入到你的本地:</code>
<code>sudo yum localinstall mysql-community-release-el6-*.noarch.rpm </code>
<code>#安裝MySQLServer:</code>
<code>yum install mysql-server mysql-devel mysql-client libmysqlclient-dev</code>
<code>#啟動mysql服務</code>
<code>/etc/init.d/mysqld start</code>
<code>#MySQL安全配置向導</code>
<code>mysql_secure_installation </code>
<code>---------------------------------------------------------------------------------</code>
<code> </code><code>Enter current password for root (enter for none): <–初次運作直接回車</code>
<code> </code><code>Set root password? [Y/n] <– 是否設定root使用者密碼,輸入y并回車或直接回車</code>
<code> </code><code>Remove anonymous users? [Y/n] <– 是否删除匿名使用者,生産環境建議删除,是以直接回車</code>
<code> </code><code>Disallow root login remotely? [Y/n] <–是否禁止root遠端登入,根據自己的需求選擇Y/n并回車,建議禁止</code>
<code> </code><code>Remove test database and access to it? [Y/n] <– 是否删除test資料庫,直接回車</code>
<code> </code><code>Reload privilege tables now? [Y/n] <– 是否重新加載權限表,直接回車</code>
建立新使用者和資料庫給gitlab使用
<code># 登入資料庫</code>
<code>$ mysql -u root -p</code>
<code># 輸入root密碼</code>
<code># 為gitlab建立使用使用者</code>
<code>mysql> CREATE USER 'gitlab'@'localhost' IDENTIFIED BY 'gitlab賬号的密碼';</code>
<code># 建立gitlaba使用的資料庫</code>
<code>mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`;</code>
<code># 給予gitlab使用者權限</code>
<code>mysql> GRANT SELECT, LOCK TABLES, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'git'@'localhost' IDENTIFIED BY 'gitpasswd';</code>
<code># 重新整理權限</code>
<code>mysql> flush privileges;</code>
<code># 檢視建立的使用者</code>
<code>mysql> select user,host,password from mysql.user;</code>
<code>#測試建立的使用者能否登陸mysql</code>
<code>mysql -u git -p -h localhost</code>
<code>mysql> show databases;</code>
<code>+---------------------+</code>
<code>| Database |</code>
<code>| information_schema |</code>
<code>| gitlabhq_production |</code>
<code>2 rows in set (0.00 sec)</code>
配置postgresql安裝源:
<a href="https://wiki.postgresql.org/wiki/YUM_Installation#Configure_your_YUM_repository" target="_blank">https://wiki.postgresql.org/wiki/YUM_Installation#Configure_your_YUM_repository</a>
<code># 修改/etc/yum.repos.d/CentOS-Base.repo,在[base]和[update]段落添加下面的配置</code>
<code>exclude=postgresql*</code>
<code># 安裝postgresql源</code>
<code>yum localinstall http://mirrors.ustc.edu.cn/postgresql/repos/yum/9.5/redhat/rhel-6-x86_64/pgdg-centos95-9.5-3.noarch.rpm</code>
<code>#yum localinstall http://mirrors.ustc.edu.cn/postgresql/repos/yum/9.2/redhat/rhel-6-x86_64/pgdg-redhat92-9.2-8.noarch.rpm</code>
<code># 安裝postgresql</code>
<code>yum install postgresql95-server postgresql95-devel postgresql95-contrib</code>
<code># 預設情況下,postgresql的資料庫檔案存放在</code>
<code>/var/lib/pgsql/9.5/data</code>
<code># 初始化</code>
<code>mv /etc/init.d/{postgresql-9.5,postgresql}</code>
<code>service postgresql initdb</code>
<code># 啟動postgresql</code>
<code>service postgresql start</code>
<code># 配置postgresql自啟動</code>
<code>chkconfig postgresql on</code>
<code># 為Gitlab建立一個使用者,使用者名為git</code>
<code>cd /home</code>
<code>sudo -u postgres psql -d template1 -c "CREATE USER git CREATEDB;"</code>
<code>#建立pg_trgm擴充 (required for GitLab 8.6+):</code>
<code>sudo -u postgres psql -d template1 -c "CREATE EXTENSION IF NOT EXISTS pg_trgm;"</code>
<code># 建立Gitlab生産環境資料庫并賦予git使用者屬主權限</code>
<code>sudo -u postgres psql -d template1 -c "CREATE DATABASE gitlabhq_production OWNER git;"</code>
<code># 用git使用者測試下是否能登入剛才建立的資料庫</code>
<code>sudo -u git -H psql -d gitlabhq_production</code>
<code>#檢查是否啟用 pg_trgm 擴充:</code>
<code>SELECT true AS enabled</code>
<code>FROM pg_available_extensions</code>
<code>WHERE name = 'pg_trgm'</code>
<code>AND installed_version IS NOT NULL;</code>
<code>如果啟用了擴充,這将産生以下輸出:</code>
<code> </code><code>enabled</code>
<code>---------</code>
<code> </code><code>t</code>
<code>(1 row)</code>
<code># 退出資料庫會話</code>
<code>gitlabhq_production> \q</code>
<code># 建立pg_config的軟連接配接</code>
<code>ln -s /usr/pgsql-9.5/bin/pg_config /usr/bin/pg_config</code>
<code>#此處redis是yum安裝,為了省事。</code>
<code>yum install -y redis</code>
<code># Disable Redis listening on TCP by setting 'port' to 0</code>
<code>sed 's/^port .*/port 0/' /etc/redis/redis.conf.orig | sudo tee /etc/redis/redis.conf</code>
<code>#添加redis.sock檔案資訊</code>
<code>echo 'unixsocket /var/run/redis/redis.sock' |tee -a /etc/redis.conf</code>
<code>echo -e 'unixsocketperm 0770' |tee -a /etc/redis.conf</code>
<code>#建立檔案并賦予權限</code>
<code>mkdir -p /var/run/redis</code>
<code>sudo chown redis:redis /var/run/redis</code>
<code>sudo chmod 755 /var/run/redis</code>
<code># Persist the directory which contains the socket, if applicable</code>
<code>if [ -d /etc/tmpfiles.d ]; then</code>
<code> </code><code>echo 'd /var/run/redis 0755 redis redis 10d -' | sudo tee -a /etc/tmpfiles.d/redis.conf</code>
<code>fi</code>
<code>#将redis使用者添加到git組</code>
<code>sudo usermod -aG redis git</code>
<code>#配置redis使其在開機時啟動:</code>
<code>sudo chkconfig redis on</code>
<code>sudo service redis start</code>
<code>#将GitLab安裝在git的家目錄下:</code>
<code>cd /home/git/</code>
<code>sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 7-6-stable gitlab</code>
<code>cd /home/git/gitlab</code>
<code># 複制gitlab.yml(Gitlab的主配置檔案)</code>
<code>sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml</code>
<code># 修改gitlab.yml</code>
<code>sudo -u git -H vim config/gitlab.yml</code>
<code> </code><code>host: localhost為 ####修改第32行 你的域名或者ip</code>
<code> </code><code>port: 80</code>
<code> </code><code>https: false</code>
<code># 修改 log/ 和 tmp/ 檔案夾權限</code>
<code>sudo chown -R git log/</code>
<code>sudo chown -R git tmp/</code>
<code>sudo chmod -R u+rwX,go-w log/</code>
<code>sudo chmod -R u+rwX tmp/</code>
<code>#建立檔案夾gitlab-satellites</code>
<code>sudo -u git -H mkdir /home/git/gitlab-satellites</code>
<code>sudo chmod u+rwx,g=rx,o-rwx /home/git/gitlab-satellites</code>
<code># 修改 tmp/pids/ 和 tmp/sockets/ 檔案夾權限</code>
<code>sudo chmod -R u+rwX tmp/pids/</code>
<code>sudo chmod -R u+rwX tmp/sockets/</code>
<code># 建立 public/uploads/ 檔案夾</code>
<code>sudo -u git -H mkdir public/uploads/</code>
<code># 修改 public/uploads/ 檔案夾權限,隻有git使用者有通路權限</code>
<code>sudo chmod -R u+rwX public/uploads</code>
<code># 複制 Unicorn 配置檔案</code>
<code>sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb</code>
<code># 查詢CPU核心數</code>
<code>nproc</code>
<code># 如果你想搭建一個高負載的Gitlab執行個體,可啟用叢集模式.</code>
<code># 修改'worker_processes'參數,至少要跟cpu核心數一樣.</code>
<code># 修改監聽位址和端口,要和下文 gitlab-shell/config.yml 中配置一緻</code>
<code>sudo -u git -H vim config/unicorn.rb</code>
<code> </code><code>worker_processes 3</code>
<code> </code><code>listen "your_IP:8080", :tcp_nopush => true</code>
<code># 複制Rack attack 配置檔案</code>
<code>sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb</code>
<code># 為 git 使用者配置使用者和郵件</code>
<code>sudo -u git -H git config --global user.name "GitLab"</code>
<code>sudo -u git -H git config --global user.email "[email protected]" </code>
<code> </code>
<code># 'autocrlf' 需要Web編輯器</code>
<code>sudo -u git -H git config --global core.autocrlf input</code>
<code># 複制 Redis 連接配接配置檔案</code>
<code>sudo -u git -H cp config/resque.yml.example config/resque.yml</code>
<code># 如修改過redis socket的路徑,在這個配置檔案裡面修改,确認redis端口和ip.</code>
<code>sudo -u git -H vim config/resque.yml</code>
<code>-------------------------------------</code>
<code>development: redis://127.0.0.1:6379</code>
<code>test: redis://127.0.0.1:6379</code>
<code>production: unix:/var/run/redis/redis.sock</code>
<code># 僅限于Mysql:</code>
<code>sudo -u git cp config/database.yml.mysql config/database.yml</code>
<code># 僅限于PostgreSQl:</code>
<code>sudo -u git cp config/database.yml.postgresql config/database.yml</code>
<code># 以下修改針對MySQL,修改username/password.</code>
<code>sudo -u git -H vim config/database.yml</code>
<code>production:</code>
<code> </code><code>adapter: mysql2</code>
<code> </code><code>encoding: utf8</code>
<code> </code><code>collation: utf8_general_ci</code>
<code> </code><code>reconnect: false</code>
<code> </code><code>database: gitlabhq_production</code>
<code> </code><code>pool: 10</code>
<code> </code><code>username: git</code>
<code> </code><code>password: "gitpasswd"</code>
<code> </code><code># host: localhost</code>
<code> </code><code># socket: /tmp/mysql.sock</code>
<code> </code><code>socket: /var/lib/mysql/mysql.sock</code>
<code># 以下修改針對PostgreSQL,修改username/password.</code>
<code># 修改'secure password' 為你設定的密碼,沒單獨設定則不改 </code>
<code> </code><code>adapter: postgresql</code>
<code> </code><code>encoding: unicode</code>
<code> </code><code># username: git</code>
<code> </code><code># password: #未設定不用修改</code>
<code> </code><code># port: 5432</code>
<code># 修改database.yml的權限,確定git使用者可以讀取該檔案.</code>
<code>sudo -u git -H chmod o-rwx config/database.yml</code>
<code># 進入gitlab目錄</code>
<code>--------------------------------------------------------------</code>
<code>gem sources --add https://ruby.taobao.org/ --remove https://rubygems.org/</code>
<code># 修改 Gemfile 和 Gemfile.lock</code>
<code>vim Gemfile(Gemfile.lock)</code>
<code>更改</code>
<code>source https://rubygems.org/ </code>
<code>為: </code>
<code>source 'https://ruby.taobao.org/'</code>
<code>-------------------------------------------------------------- </code>
<code># 確定隻有 https://ruby.taobao.org/</code>
<code> </code><code>https://ruby.taobao.org/</code>
<code>ln -s /usr/local/bin/bundle /usr/bin/ </code>
<code>####一定要注意選擇自己用的資料庫的指令</code>
<code>###PostgreSQL (note, the option says "without ... mysql")</code>
<code>sudo -u git -H bundle install --deployment --without development test mysql aws</code>
<code># 如果使用 MySQL,執行下面的指令 (note, the option says "without ... postgres")</code>
<code>sudo -u git -H bundle install --deployment --without development test postgres aws </code>
<code>筆記: 如果你想去用 Kerberos 做使用者認證, 然後在--without選項中省略Kerbero</code>
<code># Run the installation task for gitlab-shell (replace `REDIS_URL` if needed):</code>
<code>sudo -u git -H bundle exec rake gitlab:shell:install[v2.4.0] REDIS_URL=unix:/var/run/redis/redis.sock RAILS_ENV=production</code>
<code># 預設情況下,gitlab-shell的配置是根據Gitlab的配置生産的.</code>
<code># 你可以運作下面的指令檢視和修改gitlab-shell的配置,</code>
<code># 監聽端口要和/home/git/gitlab/config/unicorn.rb中配置一緻</code>
<code>sudo -u git -H vim /home/git/gitlab-shell/config.yml</code>
<code>---</code>
<code>user: git</code>
<code>gitlab_url: https://localhost:8080/ #使用https </code>
<code>http_settings:</code>
<code> </code><code>self_signed_cert: false #如果gitlab_url為https,修改成true</code>
<code>repos_path: "/home/git/repositories/"</code>
<code>auth_file: "/home/git/.ssh/authorized_keys"</code>
<code>redis:</code>
<code> </code><code>bin: "/usr/bin/redis-cli"</code>
<code> </code><code>namespace: resque:gitlab</code>
<code> </code><code>socket: "/var/run/redis/redis.sock"</code>
<code>log_level: INFO</code>
<code>audit_usernames: false</code>
<code>sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production</code>
<code># 輸入 'yes' 以建立資料庫表</code>
<code># 當看到以下内容,表示已經安裝完成</code>
<code>Administrator account created:</code>
<code>login: root</code>
<code>password: your_passwd</code>
<code>== Seed from /home/git/gitlab/db/fixtures/production/010_settings.rb</code>
Note: 你能通過提供環境變量設定 Administrator/root 密碼和郵箱, 分别為GITLAB_ROOT_PASSWORD 和 GITLAB_ROOT_EMAIL , 如下所示。如果你不能設定密碼(它被設定為預設的) 請等待曝光gitlab到公共網際網路直到安裝完成和你已經登入到伺服器的第一時間。 在第一次登入時,您将被迫更改預設密碼。.
<code>sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production GITLAB_ROOT_PASSWORD=yourpassword GITLAB_ROOT_EMAIL=youremail</code>
<code>wget -O /etc/init.d/gitlab https://gitlab.com/gitlab-org/gitlab-recipes/raw/master/init/sysvinit/centos/gitlab-unicorn</code>
<code># 配置gitlab的啟動級别 </code>
<code>chmod +x /etc/init.d/gitlab</code>
<code>chkconfig --add gitlab</code>
<code>chkconfig gitlab on </code>
<code>設定Logrotate</code>
<code>sudo cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab </code>
<code>檢查GitLab環境配置</code>
<code>sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production</code>
<code>-----</code>
<code>production</code>
<code>System information</code>
<code>System: CentOS 6.8</code>
<code>Current User: git</code>
<code>Using RVM: no</code>
<code>Ruby Version: 2.1.5p273</code>
<code>Gem Version: 2.2.2</code>
<code>Bundler Version:1.15.1</code>
<code>Rake Version: 10.3.2</code>
<code>Sidekiq Version:2.17.8</code>
<code>GitLab information</code>
<code>Version: 7.6.2</code>
<code>Revision: fatal: Not a git repository (or any parent up to mount point /home)</code>
<code>Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).</code>
<code>Directory: /home/git/gitlab</code>
<code>DB Adapter: mysql2</code>
<code>URL: http://your_ip</code>
<code>HTTP Clone URL: http://your_ip/some-project.git</code>
<code>SSH Clone URL: git@your_ip:some-project.git</code>
<code>Using LDAP: no</code>
<code>Using Omniauth: no</code>
<code>GitLab Shell</code>
<code>Version: 2.1.0</code>
<code>Repositories: /home/git/repositories/</code>
<code>Hooks: /home/git/gitlab-shell/hooks/</code>
<code>Git: /usr/bin/git</code>
<code># 生成GitLab前端資源</code>
<code>sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production</code>
<code># 啟動gitlab服務</code>
<code>service gitlab start</code>
<code># 使用yum進行安裝</code>
<code>yum install -y nginx</code>
<code>chkconfig nginx on</code>
<code>wget -O /etc/nginx/conf.d/gitlab.conf https://gitlab.com/gitlab-org/gitlab-ce/raw/master/lib/support/nginx/gitlab-ssl</code>
<code># 将nginx使用者添加到git組</code>
<code>mkdir -p /etc/nginx/ssl</code>
<code>cd /etc/nginx/ssl/</code>
<code>openssl req -new -x509 -nodes -days 3560 -out gitlab.crt -keyout gitlab.key</code>
<code># 啟動nginx服務</code>
<code>service nginx restart</code>
<code># 使用SMTP郵件伺服器,可以不安裝postfix</code>
<code>sudo -u git -H cp config/initializers/smtp_settings.rb.sample config/initializers/smtp_settings.rb</code>
<code>#修改如下</code>
<code>sudo -u git -H vim config/initializers/smtp_settings.rb</code>
<code>這裡提供163和騰訊企業郵箱兩種配置方式,注意将下面的123456替換成自己的密碼</code>
<code>163郵箱:</code>
<code>if Rails.env.production?</code>
<code> </code><code>Gitlab::Application.config.action_mailer.delivery_method = :smtp</code>
<code> </code><code>ActionMailer::Base.delivery_method = :smtp #使用smtp方法</code>
<code> </code><code>ActionMailer::Base.smtp_settings = {</code>
<code> </code><code>address: "smtp.163.com",</code>
<code> </code><code>port: 25,</code>
<code> </code><code>user_name: "wpgitlab",</code>
<code> </code><code>password: "123456",</code>
<code> </code><code>domain: "163.com",</code>
<code> </code><code>authentication: :plain,</code>
<code> </code><code>enable_starttls_auto: true</code>
<code> </code><code>}</code>
<code>end</code>
<code>QQ郵箱:</code>
<code> </code><code>address: "smtp.exmail.qq.com",</code>
<code> </code><code>user_name: "[email protected]",</code>
<code> </code><code>domain: "smtp.qq.com",</code>
<code> </code><code>enable_starttls_auto: true,</code>
<code>3. 修改gitlab.yml</code>
<code>一鍵安裝路徑:</code>
<code>cd</code>
<code> </code><code>/opt/gitlab-8.5.7-0</code>
<code>vim</code>
<code> </code><code>apps/gitlab/htdocs/config/gitlab.yml</code>
<code>将預設郵箱修改為自己的郵箱</code>
<code>163:</code>
<code>## Email settings</code>
<code> </code><code># Email address used in the "From" field in mails sent by GitLab</code>
<code> </code><code>email_from: [email protected]</code>
<code>騰訊企業郵箱:</code>
<code> </code><code>email_from: [email protected]</code>
<code>#編輯檔案</code>
<code>[root@git gitlab]#sudo -u git -H vim config/environments/production.rb</code>
<code>config.action_mailer.delivery_method = :smtp #将方法修改成smtp方式</code>
<code>4. 修改後。重新開機gitlab</code>
<code>#監控日志檔案</code>
<code>tail -f /home/git/gitlab/log/*.log</code>
<code>tail -f /var/log/maillog</code>
安裝完成後gitlab運作異常使用如下指令檢測,并解決
<code>sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production</code>
驗證結果,通路位址如下:
<a href="https://s1.51cto.com/wyfs02/M01/9C/B9/wKiom1l1cguCzu5wAASuN-fkXt0395.png-wh_500x0-wm_3-wmp_4-s_2473678897.png" target="_blank"></a>
使用者名和密碼如下
login.........root
password......5iveL!fe
使用Gitlab一鍵安裝包安裝Gitlab非常單, 同樣的備份恢複與遷移也非常簡單,用一條指令即可建立完整的Gitlab備份:
<code>sudo -u git -H bundle exec rake gitlab:backup:create RAILS_ENV=production STRATEGY=copy</code>
注:跳過某些内容sudo -u git -H bundle exec rake gitlab:backup:create RAILS_ENV=production SKIP=db,uploads
skip為:
db (database)
uploads (attachments)
repositories (Git repositories data)
builds (CI job output logs)
artifacts (CI job artifacts)
lfs (LFS objects)
registry (Container Registry images)
pages (Pages content)
修改<code>/home/git/gitlab/config/gitlab.yml</code>來修改預設存放備份檔案的目錄:
<code>sudo -u git -H vim /home/git/gitlab/config/gitlab.yml</code>
<code>---------------------- </code>
<code> </code><code>backup:</code>
<code> </code><code>path: "/home/git/backups/" # Relative paths are relative to Rails.root (default: tmp/backups/)</code>
<code># Create a full backup of the GitLab repositories and SQL database every day at 4am</code>
<code>0 4 * * * cd /home/git/gitlab && PATH=/usr/local/bin:/usr/bin:/bin bundle exec rake gitlab:backup:creat</code>
<code># 0 4 * * * cd /home/git/gitlab && sudo -u git -H bundle exec rake gitlab:backup:create RAILS_ENV=production</code>
首先進入備份 gitlab 的目錄,這個目錄是配置檔案中的<code>path</code>,本文設定為 /home/git/backups/ 。
然後停止 unicorn 和 sidekiq ,保證資料庫沒有新的連接配接,不會有寫資料情況。
<code># 停止相關資料連接配接服務</code>
<code>service gitlab stop</code>
<code>sudo -u git -H bundle exec rake gitlab:backup:restore RAILS_ENV=productione RAILS_ENV=production CRON=1</code>
<code># 如果備份目錄下面有多個備份檔案,則需加參數并指明時間戳</code>
<code>BACKUP=timestamp_of_backup (required if more than one backup exists)</code>
<code>force=yes (do not ask if the authorized_keys file should get regenerated)</code>
<code>sudo -u git -H bundle exec rake gitlab:backup:restore RAILS_ENV=productione RAILS_ENV=production CRON=1 force=yes BACKUP=timestamp_of_backup</code>
<code>#恢複時候BACKUP=timestamp_of_backup timestamp_of_backup表示是時間字首 預設恢複最新一次的備份</code>
<code># 啟動Gitlab</code>
<code>sudo gitlab-ctl start</code>
<code># 恢複過程中沒有權限</code>
<code>mkdir /home/git/backups/</code>
<code>chown git /home/git/backups/</code>
<code>chmod 700 /home/git/backups/</code>
把備份檔案拷貝到gitlab的備份目錄下,根據上面gitlab恢複步驟即可。
還需要備份檔案:/home/git/gitlab/config/secrets.yml(兩步驗證時用到:使用者名密碼登入及短信驗證)
本文轉自奔跑在路上部落格51CTO部落格,原文連結http://blog.51cto.com/qiangsh/1949450如需轉載請自行聯系原作者
qianghong000