메모: gitlab - ce 교체 (2)

30146 단어
필기 2gitlab 의 9.4.3 버 전 을 예 로 들 면 [toc]
1. nginx / apache 교체 gitlab - nginx
  • 수정 /etc/gitlab/gitlab.rb:
  • nginx['enable'] = false
    
    ##     ,
    ## nginx:nginx.conf     user(    www www)
    ## apache:httpd.conf     User Group (    daemon daemon)
    web_server['external_users'] = ['www']
    
    
    ##    apache,      ,nginx  
    gitlab_workhorse['listen_network'] = "tcp"
    gitlab_workhorse['listen_addr'] = "127.0.0.1:8181"
  • apache / nginx 프로필 수정
  • apache   
    
    # This configuration has been tested on GitLab 8.2
    # Note this config assumes unicorn is listening on default port 8080 and
    # gitlab-workhorse is listening on port 8181. To allow gitlab-workhorse to
    # listen on port 8181, edit /etc/gitlab/gitlab.rb and change the following:
    #
    # gitlab_workhorse['listen_network'] = "tcp"
    # gitlab_workhorse['listen_addr'] = "127.0.0.1:8181"
    #
    #Module dependencies
    # mod_rewrite
    # mod_proxy
    # mod_proxy_http
    
      ServerName YOUR_SERVER_FQDN
      ServerSignature Off
    
      ProxyPreserveHost On
    
      # Ensure that encoded slashes are not decoded but left in their encoded state.
      # http://doc.gitlab.com/ce/api/projects.html#get-single-project
      AllowEncodedSlashes NoDecode
    
      
        # New authorization commands for apache 2.4 and up
        # http://httpd.apache.org/docs/2.4/upgrading.html#access
        Require all granted
    
        #Allow forwarding to gitlab-workhorse
        ProxyPassReverse http://127.0.0.1:8181
        ProxyPassReverse http://YOUR_SERVER_FQDN/
      
    
      # Apache equivalent of nginx try files
      # http://serverfault.com/questions/290784/what-is-apaches-equivalent-of-nginxs-try-files
      # http://stackoverflow.com/questions/10954516/apache2-proxypass-for-rails-app-gitlab
      RewriteEngine on
    
      #Forward all requests to gitlab-workhorse except existing files like error documents
      RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f [OR]
      RewriteCond %{REQUEST_URI} ^/uploads/.*
      RewriteRule .* http://127.0.0.1:8181%{REQUEST_URI} [P,QSA,NE]
    
      # needed for downloading attachments
      DocumentRoot /opt/gitlab/embedded/service/gitlab-rails/public
    
      #Set up apache error documents, if back end goes down (i.e. 503 error) then a maintenance/deploy page is thrown up.
      ErrorDocument 404 /404.html
      ErrorDocument 422 /422.html
      ErrorDocument 500 /500.html
      ErrorDocument 502 /502.html
      ErrorDocument 503 /503.html
    
      # It is assumed that the log directory is in /var/log/httpd.
      # For Debian distributions you might want to change this to
      # /var/log/apache2.
      LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b" common_forwarded
      ErrorLog /var/log/httpd/logs/YOUR_SERVER_FQDN_error.log
      CustomLog /var/log/httpd/logs/YOUR_SERVER_FQDN_forwarded.log common_forwarded
      CustomLog /var/log/httpd/logs/YOUR_SERVER_FQDN_access.log combined env=!dontlog
      CustomLog /var/log/httpd/logs/YOUR_SERVER_FQDN.log combined
    
    
    
    
    nginx   
    
    ## GitLab 8.3+
    ##
    ## Lines starting with two hashes (##) are comments with information.
    ## Lines starting with one hash (#) are configuration parameters that can be uncommented.
    ##
    ##################################
    ##        CONTRIBUTING          ##
    ##################################
    ##
    ## If you change this file in a Merge Request, please also create
    ## a Merge Request on https://gitlab.com/gitlab-org/omnibus-gitlab/merge_requests
    ##
    ###################################
    ##         configuration         ##
    ###################################
    ##
    ## See installation.md#using-https for additional HTTPS configuration details.
    
    upstream gitlab-workhorse {
      server unix:/var/opt/gitlab/gitlab-workhorse/socket;
    }
    
    ## Normal HTTP host
    server {
      ## Either remove "default_server" from the listen line below,
      ## or delete the /etc/nginx/sites-enabled/default file. This will cause gitlab
      ## to be served if you visit any address that your server responds to, eg.
      ## the ip address of the server (http://x.x.x.x/)n 0.0.0.0:80 default_server;
      listen 0.0.0.0:80 default_server;
      listen [::]:80 default_server;
      server_name YOUR_SERVER_FQDN; ## Replace this with something like gitlab.example.com
      server_tokens off; ## Don't show the nginx version number, a security best practice
      root /opt/gitlab/embedded/service/gitlab-rails/public;
    
      ## See app/controllers/application_controller.rb for headers set
    
      ## Individual nginx logs for this GitLab vhost
      access_log  /var/log/nginx/gitlab_access.log;
      error_log   /var/log/nginx/gitlab_error.log;
    
      location / {
        client_max_body_size 0;
        gzip off;
    
        ## https://github.com/gitlabhq/gitlabhq/issues/694
        ## Some requests take more than 30 seconds.
        proxy_read_timeout      300;
        proxy_connect_timeout   300;
        proxy_redirect          off;
    
        proxy_http_version 1.1;
    
        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_set_header    X-Forwarded-Proto   $scheme;
    
        proxy_pass http://gitlab-workhorse;
      }
    }
    

    2, mysql 교체 gitlab - postgres :gitlab-ce-9.4.3-ce.0.el7.x86_64.rpm , , 。 : gitlab mysql , 。( , )
    (1) gitlab 에 권한 계 정 을 설정 하고 라 이브 러 리 를 만 듭 니 다.
    mysql> grant all privileges on *.* to gitlab@"localhost" identified by "lzour";
    mysql> flush privileges;
    mysql> CREATE DATABASE IF NOT EXISTS `gitlab` DEFAULT CHARACTER SET `utf8` COLLATE `utf8_general_ci`;

    (2) gitlab 설정 수정 /etc/gitlab/gitlab.rb:
    #    postgresql
    postgresql['enable'] = false
    
    # mysql   
    gitlab_rails['db_adapter'] = 'mysql2'
    gitlab_rails['db_encoding'] = 'utf8'
    #       ,    IP  
    gitlab_rails['db_host'] = '127.0.0.1'
    gitlab_rails['db_port'] = '3306'
    gitlab_rails['db_username'] = 'gitlab'
    gitlab_rails['db_password'] = 'lzour'
    gitlab_rails['db_host'] = "127.0.0.1"
    gitlab_rails['db_port'] = 3306
    

    (3) 설정 후 실행 gitlab-ctl reconfigure, 오류 발생
    [root@stone ~]# gitlab-ctl reconfigure
    
    ……
    Recipe: gitlab::database_migrations
      * bash[migrate gitlab-rails database] action run
        [execute] rake aborted!
                  Gem::LoadError: Specified 'mysql2' for database adapter, but the gem is not loaded. Add `gem 'mysql2'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).
                  /opt/gitlab/embedded/service/gitlab-rails/config/environment.rb:5:in `'
                  /opt/gitlab/embedded/bin/bundle:22:in `load'
                  /opt/gitlab/embedded/bin/bundle:22:in `
    ' Gem::LoadError: mysql2 is not part of the bundle. Add it to Gemfile. /opt/gitlab/embedded/service/gitlab-rails/config/environment.rb:5:in `' /opt/gitlab/embedded/bin/bundle:22:in `load' /opt/gitlab/embedded/bin/bundle:22:in `
    ' Tasks: TOP => gitlab:db:configure => environment (See full trace by running task with --trace) ================================================================================ Error executing action `run` on resource 'bash[migrate gitlab-rails database]' ================================================================================ Mixlib::ShellOut::ShellCommandFailed ------------------------------------ ## , mysql2, ruby gem , , ruby gem bundle [root@stone bin]# vim /opt/gitlab/embedded/service/gitlab-rails/.bundle/config --- BUNDLE_RETRY: "5" BUNDLE_JOBS: "9" ## mysql postgres BUNDLE_WITHOUT: "development:test:postgres" ## gitlab [root@stone ~]# cd /opt/gitlab/embedded/bin/ [root@stone bin]# ./gem install mysql2 Fetching: mysql2-0.4.9.gem (100%) Building native extensions. This could take a while... Successfully installed mysql2-0.4.9 Parsing documentation for mysql2-0.4.9 Installing ri documentation for mysql2-0.4.9 Done installing documentation for mysql2 after 0 seconds 1 gem installed ## [root@stone ~]# gitlab-rake gitlab:check Your bundle is locked to mysql2 (0.3.20), but that version could not be found in any of the sources listed in your Gemfile. If you haven't changed sources, that means the author of mysql2 (0.3.20) has removed it. You'll need to update your bundle to a different version of mysql2 (0.3.20) that hasn't been removed in order to install. Run `bundle install` to install missing gems. ## , 0.3.20 , [root@stone bin]# ./gem uninstall mysql2 Successfully uninstalled mysql2-0.4.9 [root@stone bin]# ./gem install mysql2 -v "0.3.20" Fetching: mysql2-0.3.20.gem (100%) Building native extensions. This could take a while... Successfully installed mysql2-0.3.20 Parsing documentation for mysql2-0.3.20 Installing ri documentation for mysql2-0.3.20 Done installing documentation for mysql2 after 0 seconds 1 gem installed ## ,0.3.20, [root@stone bin]# ./gem list | grep mysql mysql2 (0.3.20) ## ( ……, , ) [root@stone bin]# gitlab-rake gitlab:check Could not find peek-mysql2-1.1.0 in any of the sources Run `bundle install` to install missing gems. [root@stone bin]# ./gem install peek-mysql2 -v 1.1.0 …… , , (gitlab-rake gitlab:check) 【 】 ## , QQ , 。 ## , [root@stone ~]# gitlab-ctl reconfigure …… Running handlers: Running handlers complete Chef Client finished, 11/330 resources updated in 43 seconds gitlab Reconfigured!

    3, redis 교체 gitlab - redis
    (1) 준비 - redis 예제 설치 디 렉 터 리 /usr/loacl/redis
    [root@stone etc]#                inet xx.xx.xx.xx,inet 127.0.0.1
    [root@stone etc]# ifconfig
    eth0: flags=4163  mtu 1500
            inet xx.xx.xx.xx  netmask 255.255.240.0  broadcast 172.17.239.255
            ether 00:16:3e:10:66:35  txqueuelen 1000  (Ethernet)
            RX packets 6900  bytes 673498 (657.7 KiB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 6525  bytes 1549613 (1.4 MiB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    lo: flags=73  mtu 65536
            inet 127.0.0.1  netmask 255.0.0.0
            loop  txqueuelen 1  (Local Loopback)
            RX packets 9297  bytes 16797712 (16.0 MiB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 9297  bytes 16797712 (16.0 MiB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
    
    ---
    
    [root@stone etc]# vim /usr/local/redis/etc/redis.conf
    # Redis configuration file example.
    #
    # Note that in order to read the configuration file, Redis must be
    ……
    ##           (ifconfig    inet)
    bind 127.0.0.1 xx.xx.xx.xx
    ……
    ##   redis  
    requirepass love
    
    ---
    
    [root@stone etc]redis     ,path/redis stop   ,    :
    [root@stone etc]# vim /etc/init.d/redis 
    ……
    REDISPORT=6379
    EXEC=/usr/local/redis/bin/redis-server
    REDIS_CLI=/usr/local/redis/bin/redis-cli
    
    PIDFILE=/var/run/redis.pid
    ##    PWD=love
    PWD=stone
    ……
    ##   `shutdown`,        `-a $PWD`
    $REDIS_CLI -a $PWD -p $REDISPORT shutdown

    redis 클 라 이언 트 RedisDesktopManager 로 원 격 로그 인 redis 성공 (6379 포트 개방 주의)
    (2) 설정 /etc/gitlab/gitlab.rb
    [root@stone etc]# vim /etc/gitlab/gitlab.rb
    
    ---
    
    redis['enable'] = false
    
    #   redis    ,    IP
    gitlab_rails['redis_host'] = '127.0.0.1'
    gitlab_rails['redis_port'] = 6379
    
    #           ,     
    gitlab_rails['redis_password'] = 'love'
    
    #      ,   tmp  
    gitlab_rails['redis_socket'] = '/tmp/redis.sock'

    (3) gitlab - redis 를 닫 고 gitlab 설정 을 초기 화 합 니 다.
    redis - cli 방법 으로 닫 습 니 다. 구체 적 인 위치: /opt/gitlab/embedded/bin/redis-cli"tip: 어떻게 된 건 지 모 르 겠 어 요. gitlab - redis 가 자꾸 꺼 지지 않 아 요. 모든 게 제 가 직접" init 6
    [root@stone ~]#gitlab-ctl reconfigure
    (  )
    
    [root@stone ~]# gitlab-ctl status
    run: gitaly: (pid 480) 1632s; run: log: (pid 479) 1632s
    run: gitlab-monitor: (pid 6271) 18s; run: log: (pid 486) 1632s
    run: gitlab-workhorse: (pid 6261) 18s; run: log: (pid 484) 1632s
    run: logrotate: (pid 489) 1632s; run: log: (pid 488) 1632s
    run: node-exporter: (pid 478) 1632s; run: log: (pid 477) 1632s
    run: prometheus: (pid 496) 1632s; run: log: (pid 495) 1632s
    run: sidekiq: (pid 6243) 19s; run: log: (pid 490) 1632s
    run: unicorn: (pid 6228) 19s; run: log: (pid 494) 1632s
    (  redis  , ,  )
    
    [root@stone ~]# ps aux | grep redis
    root      1184  0.0  0.4 145244  9364 ?        Ssl  17:06   0:00 /usr/local/redis/bin/redis-server 127.0.0.1:6379
    root      6437  0.0  0.0 112652   968 pts/0    R+   17:34   0:00 grep --color=auto redis
    (      redis,  )

    좋은 웹페이지 즐겨찾기