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 "================================================================="

gitlab6 nginx配置和启动脚本的更多相关文章

  1. Centos 配置开机启动脚本启动 docker 容器

    Centos 配置开机启动脚本启动 docker 容器 Intro 我们的 Centos 服务器上部署了好多个 docker 容器,因故重启的时候就会导致还得手动去手动重启这些 docker 容器,为 ...

  2. ubuntu系统自动配置开机启动脚本

    以前一直搞的centos配置开机启动脚本,但是相同方法用在ubuntu系统上就不管用了,非常伤脑筋. 非常感谢  https://www.linuxidc.com/Linux/2017-09/1471 ...

  3. 【Web】Nginx配置开机启动

    在添加nginx服务之后,大家会希望开机伴随启动nginx,避免手动路径输入启动: nginx官方提供了启动脚本:https://www.nginx.com/resources/wiki/start/ ...

  4. nginx配置开机启动及配置sudo授权启动

    1.https://www.cnblogs.com/whatmiss/p/7091220.html        配置开机启动nginx 2.sudo授权其它用户启动 (1)root用户编辑 visu ...

  5. yum 安装nginx(配置开机启动)

    yum install -y nginx 通过yum安装的时候提示下面的错误 [root@localhost yum.repos.d]# yum install nginx 已加载插件:fastest ...

  6. nginx、php-fpm启动脚本

    Nginx官方启动脚本 //service nginx stop|start|restart|reloadtouch /etc/init.d/nginx chmod nginxvi /etc/init ...

  7. nginx二进制编译-启动脚本编写

    首先先把这个文件上传到root目录下,并解压 #tar zxf nginx-1.11.2.tar.gz 写脚本 # vi nginx-running.sh 内容如下 #!/bin/bash #chkc ...

  8. 配置和启动脚本(bash shell学习01)

    bash是 Bourne Again Shell简称 ,从unix系统的sh发展而来 查看当前shellecho $SHELL查看系统支持的shellcat /etc/shells cd /binls ...

  9. nginx init 官方启动脚本

    #!/bin/sh # # nginx - this script starts and stops the nginx daemon # # chkconfig: - 85 15 # descrip ...

随机推荐

  1. 初识Redis系列之四:.net使用Redis存储数据

    首先Redis在Windows上的安装前面的文章已经介绍过,这里不介绍了,直奔主题, 直接来看看.net怎么使用Redis 首先需要引用redis相关的dll,两个途径,意识网上下载编译好的dll : ...

  2. 常见常用的CSS

    字体属性:(font) 大小 {font-size: x-large;}(特大) xx-small;(极小) 一般中文用不到,只要用数值就可以,单位:PX.PD 样式 {font-style: obl ...

  3. 搭建 RabbitMQ Server 高可用集群

    阅读目录: 准备工作 搭建 RabbitMQ Server 单机版 RabbitMQ Server 高可用集群相关概念 搭建 RabbitMQ Server 高可用集群 搭建 HAProxy 负载均衡 ...

  4. Python中的str与unicode处理方法

    Python中的str与unicode处理方法 2015/03/25 · 基础知识 · 3 评论· Python 分享到:42 原文出处: liuaiqi627 的博客    python2.x中处理 ...

  5. Lock锁子类了解一下

    前言 回顾前面: 多线程三分钟就可以入个门了! Thread源码剖析 多线程基础必要知识点!看了学习多线程事半功倍 Java锁机制了解一下 AQS简简单单过一遍 只有光头才能变强! 上一篇已经将Loc ...

  6. Ubuntu 16.04LTS 安装 MATLAB 2014B

    环境:Ubuntu 16.04LTS 软件:MATLAB 2014B MATLAB 2014B 下载地址(带Crack): 链接: https://pan.baidu.com/s/1nvGtmEd 密 ...

  7. django模板语言中的extends,block和include

    extends和block一起用 它们用于母版和子版的继承 在母版html中将一些需要替换的部分用{% block xxx %}...{% endblock %}括起来, 在子版html中,在第一行需 ...

  8. Dynamics CRM2016 Web Api之查询查找字段的相关属性

    之前有篇博文介绍了如何获取查找字段的name值(跳转),本篇在此基础上再延伸下,实现的效果类似于EntityReference,可以取到查找字段的id,name,localname. 这里我以客户实体 ...

  9. Hadoop2动态调整Log级别-以datanode的heartbeat log为例

    在Hadoop中,有些log信息在正常情况下是不打印出来的.比如datanode发送heartbeat的日志. 代码位于BPServiceActor#sendHeartBeat方法中,如下图: 由于默 ...

  10. Hexo 简明教程

    概述 对于个人独立博客的搭建,或者一些产品网站的介绍我个人比较推崇直接用静态网站生成器来完成这个事情,对于,静态网页部署方便,浏览速度快. 以下为部分静态网站生成器简要列表: Ruby Jekyll ...