linux gitlab nginx 安裝 配置


更新:bitnami-gitlab 7.8版本后界面發生變化

郵件問題:

cd /data/server/gitlab/apps/gitlab/htdocs/config
vim environments/production.rb

  config.action_mailer.smtp_settings = {
    :address => "smtp.163.com",
    :port => 25,
    :domain => "163.com",
    :authentication => "login",
    :user_name => "zab_alert",
    :password => "ynxxxxxxxxxxx",
    :enable_starttls_auto => true
  }

cp initializers/smtp_settings.rb.sample initializers/smtp_settings.rb

vim initializers/smtp_settings.rb
  ActionMailer::Base.smtp_settings = {
    address: "smtp.163.com",
    port: 25,
    user_name: "zab_alert",
    password: "ydnsgtbwbbdwygin",
    domain: "163.com",
    authentication: :login,
    enable_starttls_auto: true,
    openssl_verify_mode: 'none'
  }

vim gitlab.yml 

  email_from: zab_alert@163.com

  

 

更新: 用官方rpm包裝很方便

rpm下載地址: https://www.gitlab.com/downloads/

教程地址:https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md

              https://gitlab.com/gitlab-org/gitlab-ce/blob/master/doc/install/installation.md

              http://www.cw1314.com/index.php/archives/73/    smtp手動設置發送郵件

             http://www.tuicool.com/articles/AzeEru                  https

-----------------------------------------發送郵件,頭像問題,url-------------------------------------------------------------

vim /etc/gitlab/gitlab.rb

external_url = 'http://172.16.2.122'
gitlab_rails['gravatar_plain_url'] = 'http://gravatar.duoshuo.com/avatar/%{hash}?s=%{size}&d=identicon'
gitlab_rails['gitlab_shell_ssh_port'] = 2001
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.exmail.qq.com"
gitlab_rails['smtp_port'] = 25
gitlab_rails['smtp_user_name'] = "gitlab"
gitlab_rails['smtp_password'] = "blinksoul2015"
gitlab_rails['smtp_domain'] = "blinksoul.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['gitlab_email_from'] = 'gitlab@blinksoul.com'

-------------------------------------企業郵箱提示的356端口無法使用-----------------------------------------------------------------

-------------------------------------ssh端口------------------------------------------------

vim /opt/gitlab/embedded/service/gitlab-rails/config/gitlab.yml

ssh_port: 2001

---------------------------------------------------------------------------------------------

安裝:

sudo yum install openssh-server
sudo yum install postfix # sendmail or exim is also OK
sudo rpm -i gitlab-x.y.z.rpm
sudo gitlab-ctl reconfigure

維護:

# Start all GitLab components
sudo gitlab-ctl start

# Stop all GitLab components
sudo gitlab-ctl stop

# Restart all GitLab components
sudo gitlab-ctl restart
It is also possible to start, stop or restart individual components.

sudo gitlab-ctl restart unicorn

 

環境

Requirements
軟件 版本
CentOS 6.6
Python 2.6
Ruby 2.1.5
Git 1.7.10+
Redis 2.0+
MySQL  
GitLab 7-8-stable
GitLab Shell v2.6.0
yum源

為了提高軟件安裝速度,將yum源設置為阿里雲開源鏡像

$ cd /etc/yum.repos.d $ wget -O CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
必要軟件包
$ 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 zlib-devel openssl-devel cpio expat-devel gettext-devel curl-devel perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker

安裝Git

// 查看當前git版本
$ git --version // 如果小於1.7.10則先卸載 $ yum remove git // 下載最新的git並安裝 $ wget -O git-src.zip https://github.com/git/git/archive/master.zip $ unzip git-src.zip $ cd git-src $ make prefix=/usr/local all $ make prefix=/usr/local install $ ln -fs /usr/local/bin/git* /usr/bin/

安裝Ruby環境

$ mkdir /tmp/ruby && cd /tmp/ruby
$ curl --progress ftp://ftp.ruby-lang.org/pub/ruby/ruby-2.1.5.tar.gz | tar xz $ cd ruby-2.1.5 $ ./configure --disable-install-rdoc $ make && make install $ ln -s /usr/local/bin/ruby /usr/bin/ruby $ ln -s /usr/local/bin/gem /usr/bin/gem $ ln -s /usr/local/bin/bundle /usr/bin/bundle // 設置ruby gem源為淘寶 $ gem source -r https://rubygems.org/ $ gem source -a http://ruby.taobao.org/ $ gem install bundler --no-ri --no-rdoc

安裝MySQL及初始化GitLab庫

$ yum install mysql mysql-devel mysql-server -y
$ /etc/init.d/mysqld start
$ chkconfig mysqld on // 登錄mysql創建gitab的帳號和數據庫 mysql> CREATE USER 'gitlab'@'localhost' IDENTIFIED BY 'gitlab'; mysql> CREATE DATABASE IF NOT EXISTS `gitlabhq_production` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_unicode_ci`; mysql> GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON `gitlabhq_production`.* TO 'gitlab'@'localhost'; //測試是否可以用git帳號登錄數據庫 sudo -u git -H mysql -u gitlab -p -D gitlabhq_production

安裝Redis

$ yum -y install redis $ /etc/init.d/redis start $ chkconfig redis on

添加git帳號並允許sudo

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

安裝GitLab

$ /home/git $ sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-ce.git -b 7-8-stable gitlab $ cd /home/git/gitlab $ sudo -u git -H cp config/gitlab.yml.example config/gitlab.yml // 編輯git路徑, gitlab的host:port $ vim config/gitlab.yml // bin_path: /usr/local/bin/git // host: localhost // port: 80 // 給文件夾添加相應的權限 $ chown -R git log/ $ chown -R git tmp/ $ chmod -R u+rwX log/ $ chmod -R u+rwX tmp/ // 創建必要的文件夾,以及復制配置文件 $ sudo -u git -H mkdir /home/git/gitlab-satellites $ sudo -u git -H mkdir tmp/pids/ $ sudo -u git -H mkdir tmp/sockets/ $ sudo chmod -R u+rwX tmp/pids/ $ sudo chmod -R u+rwX tmp/sockets/ $ sudo -u git -H mkdir public/uploads $ sudo chmod -R u+rwX public/uploads $ sudo -u git -H cp config/unicorn.rb.example config/unicorn.rb $ sudo -u git -H cp config/initializers/rack_attack.rb.example config/initializers/rack_attack.rb // 配置數據庫連接信息 $ sudo -u git cp config/database.yml.mysql config/database.yml $ sudo -u git -H vim config/database.yml $ vim config/database.yml // production: // username: gitlab // password: "gitlab"

安裝GitLab-Shell

$ cd /home/git $ sudo -u git -H git clone https://gitlab.com/gitlab-org/gitlab-shell.git -b v2.6.0 $ cd gitlab-shell/ $ sudo -u git -H cp config.yml.example config.yml // 編輯配置文件, 設置gitlab_url, redis-cli, log-level... $ vim config.yml // gitlab_url: "http://localhost/" // /usr/bin/redis-cli // 安裝git-shell $ sudo -u git -H ./bin/install

安裝需要ruby的gems

$ cd /home/git/gitlab $ sudo -u git -H bundle install --deployment --without development test postgres aws

初始化數據庫(創建GitLab相關表)

$ sudo -u git -H bundle exec rake gitlab:setup RAILS_ENV=production

安裝啟動文件以及日志切割文件

cp lib/support/init.d/gitlab /etc/init.d/gitlab cp lib/support/init.d/gitlab.default.example /etc/default/gitlab cp lib/support/logrotate/gitlab /etc/logrotate.d/gitlab

設置git帳號信息

$ sudo -u git -H git config --global user.name "Troy Zhang" $ sudo -u git -H git config --global user.email "troyz@synnex.com" $ sudo -u git -H git config --global core.autocrlf input

安裝Nginx

$ yum -y install nginx $ vim /etc/nginx/nginx.conf user root git; worker_processes 2; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; # GITLAB # Maintainer: @randx # App Version: 5.0 upstream gitlab { server unix:/home/git/gitlab/tmp/sockets/gitlab.socket; } server { listen *:80 default_server; # e.g., listen 192.168.1.1:80; In most cases *:80 is a good idea server_name YOUR_SERVER_FQDN; # e.g., server_name source.example.com; server_tokens off; # don't show the version number, a security best practice root /home/git/gitlab/public; # Set value of client_max_body_size to at least the value of git.max_size in gitlab.yml client_max_body_size 5m; # individual nginx logs for this gitlab vhost access_log /var/log/nginx/gitlab_access.log; error_log /var/log/nginx/gitlab_error.log; location / { # serve static files from defined root folder;. # @gitlab is a named location for the upstream fallback, see below try_files $uri $uri/index.html $uri.html @gitlab; } # if a file, which is not found in the root folder is requested, # then the proxy pass the request to the upsteam (gitlab unicorn) location @gitlab { proxy_read_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694 proxy_connect_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694 proxy_redirect off; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header Host $http_host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_pass http://gitlab; } } }

更改權限,啟動nginx

$ nginx -t $ chown -R git:git /var/lib/nginx/ $ /etc/init.d/nginx start

檢測當前環境

sudo -u git -H bundle exec rake gitlab:env:info RAILS_ENV=production

拉取gitlab靜態資源文件

$ sudo -u git -H bundle exec rake assets:precompile RAILS_ENV=production

啟動gitlab

$ /etc/init.d/gitlab start

檢測各個組件是否正常工作

$ sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM