ubuntu gitlab nginx 安装配置
首先申明一点,Ubuntu做为服务器,个人是不推荐的。但是Ubuntu源的东西还是挺全的,要装什么东西都比较方便。
1,安装gitlab要用的一些组件
# apt-get install Nginx curl openssh-server ca-certificates postfix
2,安装gitlab
# curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash # apt-get install gitlab-ce
3,配置,启动gitlab
# cat /etc/gitlab/gitlab.rb | awk '{gsub(/^ +#/,"#",$0);if($0 !~ /^$/ && $0 !~ /^#/) {print $0}}' external_url 'http://gitlab.XXXXX.com' //域名 git_data_dirs({ "default" => { "path" => "/home/gitlab" //定义仓库路径 } }) web_server['external_users'] = ['www-data','gitlab-www','git'] //允许启动gitlab的用户 Nginx['enable'] = false //不使用内置Nginx # gitlab-ctl reconfigure //配置生效,并启动 # gitlab-ctl status //查看状态,或用ps,netstat查看进程 run: gitaly: (pid 21519) 66501s; run: log: (pid 14077) 70678s run: gitlab-monitor: (pid 21531) 66501s; run: log: (pid 14277) 70666s run: gitlab-workhorse: (pid 21543) 66500s; run: log: (pid 14015) 70692s run: logrotate: (pid 14722) 1699s; run: log: (pid 14044) 70684s run: node-exporter: (pid 21561) 66499s; run: log: (pid 14175) 70672s run: postgres-exporter: (pid 21566) 66499s; run: log: (pid 14372) 70652s run: postgresql: (pid 21576) 66499s; run: log: (pid 13758) 70745s run: prometheus: (pid 21658) 66498s; run: log: (pid 14319) 70658s run: redis: (pid 21669) 66498s; run: log: (pid 13695) 70751s run: redis-exporter: (pid 21673) 66497s; run: log: (pid 14301) 70660s run: sidekiq: (pid 24538) 56197s; run: log: (pid 13996) 70698s run: unicorn: (pid 21704) 66494s; run: log: (pid 13953) 70704s
web_server['external_users'] = ['www-data','gitlab-www','git'],这一步很重要,如果不加用户,访问网址的时候,就会报502,
connect() to unix://var/opt/gitlab/gitlab-rails/sockets/gitlab.socket failed (13: Permission denied) while connecting to upstream
查看一下Nginx.conf就可以知道,nginx的启动用户,加到web_server就行了。
4,配置nginx
# cat /etc/nginx/sites-enabled/gitlab.conf upstream gitlab { # 7.x 版本在此位置 # server unix:/var/opt/gitlab/gitlab-rails/tmp/sockets/gitlab.socket; # 8.0 位置 server unix://var/opt/gitlab/gitlab-rails/sockets/gitlab.socket; } server { listen 80; server_name gitlab.XXXXX.com; root /opt/gitlab/embedded/service/gitlab-rails/public; # 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_pass http://gitlab; } } # /etc/init.d/Nginx start
然后就可以访问http://gitlab.XXXXX.com,就ok了