关闭

gitlab6 nginx配置和启动脚本

标签: gitlab nginx
2751人阅读 评论(0) 收藏 举报

gitlab6 nginx配置和启动脚本

cheungmine

2013-10

最近把gitlab安装到了ubuntu12.04.3的虚拟机上了。参考:

https://github.com/gitlabhq/gitlabhq/blob/master/doc/install/installation.md
www.nickyeoman.com/blog/system-administration/180-install-gitlab-on-ubuntu


我用了2个虚拟机,vm-gitlab6安装gitlab6和相关的东西:nginx, postfix, redis,ruby,另一个vm-mysqldb4git安装了mysql db。用这2台虚拟机构成了整个内网下的 gitlab服务。由于使用了NAT,还需要在主机上安装nginx,指向vm-gitlab6上的nginx服务。

虚拟机的用户car设置了sudo免密码,参考:

http://blog.csdn.net/cheungmine/article/details/12341005

这样连同主机在内有3台机器:

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

host: 192.168.90.122

nginx A

/etc/hosts 中加入:

192.168.90.122  vm-gitlab
--------------------------------------------------

vm-gitlab6: 192.168.122.24

nginx B

gitlab6.1

git

ruby2.0x

postfix

redis

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

vm-mysqldb4git: 192.168.122.139

mysqldb for git


nginx A需要指向nginx B,nginx A配置文件(/etc/nginx/sites-available/gitlab)如下:

# GITLAB
# Maintainer: @randx
# App Version: 5.0

upstream gitlab {
  server unix:/home/git/gitlab/tmp/sockets/gitlab.socket;
}

server {
  listen 80;     # e.g., listen 192.168.1.1:80; In most cases *:80 is a good idea

  ##server_name 192.168.90.122;     # e.g., server_name source.example.com;
  server_name 192.168.90.122 vm-gitlab;     # 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;

  # 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://192.168.122.24;
  }
}

nginx B 配置文件(/etc/nginx/sites-available/gitlab)如下:

# 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 vm-gitlab;     # 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;

  # 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;
  }
}


由于gitlab都在虚拟机上,每次启动和关闭都很繁琐,特写了启动和关闭的脚本,使操作一键完成,可以重复启动和关闭,这样也方便更改配置。启动脚本如下:

#!/bin/bash
# start-gitlab.sh
# cheungmine@gmail.com
################################################################################
# vm-gitlab6
vm_gitlab6_name='vm-gitlab6'
vm_gitlab6_ip='192.168.122.24'
vm_gitlab6_login='car'
vm_gitlab6_passwd='abc1234'

# vm-mysqldb4git
vm_mysqldb4git_name='vm-mysqldb4git'
vm_mysqldb4git_ip='192.168.122.139'
vm_mysqldb4git_login='car'
vm_mysqldb4git_passwd='abc1234'

echo "================================================================="
echo "start gitlab, mysqldb4git virtual machines and services..."

# check if vm-gitlab6 is running
if (! ping -c 1 $vm_gitlab6_ip); then
    echo -e $vm_gitlab6_name "(" $vm_gitlab6_ip ") is not running!\r\n"
    sudo virsh start $vm_gitlab6_name
fi

# check if vm-mysqldb4git is running
if (! ping -c 1 $vm_mysqldb4git_ip); then
    echo -e $vm_mysqldb4git_name "(" $vm_mysqldb4git_ip ") is not running!\r\n"
    sudo virsh start $vm_mysqldb4git_name
fi


# waiting for vm-gitlab6 is ready
while (! ping -c 1 $vm_gitlab6_ip); do sleep 1; done

sudo virsh list --all

# start services in vm-gitlab6
sshpass -p $vm_gitlab6_passwd ssh $vm_gitlab6_login@$vm_gitlab6_ip "sudo /etc/init.d/gitlab restart"
sshpass -p $vm_gitlab6_passwd ssh $vm_gitlab6_login@$vm_gitlab6_ip "sudo /etc/init.d/nginx restart"

# start local nginx service
echo "start nginx at localhost:" `hostname`
sudo /etc/init.d/nginx restart

echo "gitlab, mysqldb4git virtual machines and services are now ready !"
echo "================================================================="

关闭脚本如下:

#!/bin/bash
# stop-gitlab.sh
# cheungmine@gmail.com
################################################################################
# vm-gitlab6
vm_gitlab6_name='vm-gitlab6'
vm_gitlab6_ip='192.168.122.24'
vm_gitlab6_login='car'
vm_gitlab6_passwd='abc1234'

# vm-mysqldb4git
vm_mysqldb4git_name='vm-mysqldb4git'
vm_mysqldb4git_ip='192.168.122.139'
vm_mysqldb4git_login='car'
vm_mysqldb4git_passwd='abc1234'

echo "================================================================="
echo "stop gitlab, mysqldb4git virtual machines and services..."

# stop services on vm-gitlab6
if (! ping -c 1 $vm_gitlab6_ip); then
    echo -e $vm_gitlab6_name "(" $vm_gitlab6_ip ") is not running!\r\n"
else
    sshpass -p $vm_gitlab6_passwd ssh $vm_gitlab6_login@$vm_gitlab6_ip "sudo /etc/init.d/gitlab stop"
    sshpass -p $vm_gitlab6_passwd ssh $vm_gitlab6_login@$vm_gitlab6_ip "sudo /etc/init.d/nginx stop"
    sleep 10
    sudo virsh shutdown $vm_gitlab6_name
fi

# stop services on vm-mysqldb4git
if (! ping -c 1 $vm_mysqldb4git_ip); then
    echo -e $vm_mysqldb4git_name "(" $vm_mysqldb4git_ip ") is not running!\r\n"
else
    # close mysqldb
    # sleep 5
    sudo virsh shutdown $vm_mysqldb4git_name
    sleep 5
fi

sudo virsh list --all

# stop local nginx service
echo "stop nginx at localhost:" `hostname`
sudo /etc/init.d/nginx stop

echo "gitlab, mysqldb4git virtual machines are shutdown !"
echo "================================================================="




0
0
查看评论
发表评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场

centos下nginx启动脚本和chkconfig管理

在安装完nginx后,重新启动需要“kill -HUP nginx进程编号”来进行重新加载,显然十分不方便。如果能像apache一样,直接通过脚本进行管理就方便多了。 nginx官方早就想好了,也提...
  • wave_1102
  • wave_1102
  • 2015-07-30 11:35
  • 2034

linux(centos6.6) 下安装,配置nginx, 及开机自启动

linux:centos 6.6 x64 nginx:1.7.8   1.安装一下软件: yum -y install pcre* yum -y install openssl*   #pc...
  • liwateryi
  • liwateryi
  • 2016-06-03 11:09
  • 7917

nginx1.3.6 的简单配置和启动脚本

(1) nginx信息 root@ubuntu:/usr/local/nginx/sbin# ./nginx -V nginx version: nginx/1.3.6 built ...
  • commshare
  • commshare
  • 2012-10-09 11:30
  • 894

supervisor开机自动启动脚本+redis+MySQL+tomcat+nginx进程自动重启配置

supervisor开机自动重启脚本 #! /bin/sh PATH=/sbin:/bin:/usr/sbin:/usr/bin PROGNAME=supervisord DAEMON=/usr/b...
  • xieliaowa9231
  • xieliaowa9231
  • 昨天 18:58
  • 32

nginx服务启动脚本

  • 2016-05-18 11:30
  • 2KB
  • 下载

linux下 nginx启动脚本

  • 2015-11-03 11:36
  • 3KB
  • 下载

解决Nginx启动脚本在redhat上不兼容问题

  • 2016-06-17 07:57
  • 58KB
  • 下载

nginx开机启动脚本

  • 2016-09-19 18:31
  • 2KB
  • 下载

nginx、php-fpm启动脚本详解

php-fpm启动脚本#!/bin/sh # # php-fpm - this script starts and stops the php-fpm daemin # # chkconfig: - ...
  • b1303110335
  • b1303110335
  • 2017-07-16 09:11
  • 218

nginx整合php自动启动脚本

nginx启动脚本#vi /etc/init.d/nginx#!/bin/bash # v.0.0.1 # create by jackbillow at 2007.10.15 # nginx - T...
  • killfen
  • killfen
  • 2012-05-07 18:58
  • 783
    个人资料
    • 访问:1431092次
    • 积分:18203
    • 等级:
    • 排名:第598名
    • 原创:295篇
    • 转载:9篇
    • 译文:16篇
    • 评论:1240条
    文章分类
    最新评论