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 中加入:

  1. 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)如下:

  1. # GITLAB
  2. # Maintainer: @randx
  3. # App Version: 5.0
  4.  
  5. upstream gitlab {
  6. server unix:/home/git/gitlab/tmp/sockets/gitlab.socket;
  7. }
  8.  
  9. server {
  10. listen 80; # e.g., listen 192.168.1.1:80; In most cases *:80 is a good idea
  11.  
  12. ##server_name 192.168.90.122; # e.g., server_name source.example.com;
  13. server_name 192.168.90.122 vm-gitlab; # e.g., server_name source.example.com;
  14. server_tokens off; # don't show the version number, a security best practice
  15. root /home/git/gitlab/public;
  16.  
  17. # individual nginx logs for this gitlab vhost
  18. access_log /var/log/nginx/gitlab_access.log;
  19. error_log /var/log/nginx/gitlab_error.log;
  20.  
  21. location / {
  22. # serve static files from defined root folder;.
  23. # @gitlab is a named location for the upstream fallback, see below
  24. try_files $uri $uri/index.html $uri.html @gitlab;
  25. }
  26.  
  27. # if a file, which is not found in the root folder is requested,
  28. # then the proxy pass the request to the upsteam (gitlab unicorn)
  29. location @gitlab {
  30. proxy_read_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694
  31. proxy_connect_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694
  32. proxy_redirect off;
  33.  
  34. proxy_set_header X-Forwarded-Proto $scheme;
  35. proxy_set_header Host $http_host;
  36. proxy_set_header X-Real-IP $remote_addr;
  37.  
  38. proxy_pass http://192.168.122.24;
  39. }
  40. }

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

  1. # GITLAB
  2. # Maintainer: @randx
  3. # App Version: 5.0
  4.  
  5. upstream gitlab {
  6. server unix:/home/git/gitlab/tmp/sockets/gitlab.socket;
  7. }
  8.  
  9. server {
  10. listen *:80 default_server; # e.g., listen 192.168.1.1:80; In most cases *:80 is a good idea
  11. #server_name vm-gitlab; # e.g., server_name source.example.com;
  12. server_tokens off; # don't show the version number, a security best practice
  13. root /home/git/gitlab/public;
  14.  
  15. # individual nginx logs for this gitlab vhost
  16. access_log /var/log/nginx/gitlab_access.log;
  17. error_log /var/log/nginx/gitlab_error.log;
  18.  
  19. location / {
  20. # serve static files from defined root folder;.
  21. # @gitlab is a named location for the upstream fallback, see below
  22. try_files $uri $uri/index.html $uri.html @gitlab;
  23. }
  24.  
  25. # if a file, which is not found in the root folder is requested,
  26. # then the proxy pass the request to the upsteam (gitlab unicorn)
  27. location @gitlab {
  28. proxy_read_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694
  29. proxy_connect_timeout 300; # https://github.com/gitlabhq/gitlabhq/issues/694
  30. proxy_redirect off;
  31.  
  32. proxy_set_header X-Forwarded-Proto $scheme;
  33. proxy_set_header Host $http_host;
  34. proxy_set_header X-Real-IP $remote_addr;
  35.  
  36. proxy_pass http://gitlab;
  37. }
  38. }

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

  1. #!/bin/bash
  2. # start-gitlab.sh
  3. # cheungmine@gmail.com
  4. ################################################################################
  5. # vm-gitlab6
  6. vm_gitlab6_name='vm-gitlab6'
  7. vm_gitlab6_ip='192.168.122.24'
  8. vm_gitlab6_login='car'
  9. vm_gitlab6_passwd='abc1234'
  10.  
  11. # vm-mysqldb4git
  12. vm_mysqldb4git_name='vm-mysqldb4git'
  13. vm_mysqldb4git_ip='192.168.122.139'
  14. vm_mysqldb4git_login='car'
  15. vm_mysqldb4git_passwd='abc1234'
  16.  
  17. echo "================================================================="
  18. echo "start gitlab, mysqldb4git virtual machines and services..."
  19.  
  20. # check if vm-gitlab6 is running
  21. if (! ping -c 1 $vm_gitlab6_ip); then
  22. echo -e $vm_gitlab6_name "(" $vm_gitlab6_ip ") is not running!\r\n"
  23. sudo virsh start $vm_gitlab6_name
  24. fi
  25.  
  26. # check if vm-mysqldb4git is running
  27. if (! ping -c 1 $vm_mysqldb4git_ip); then
  28. echo -e $vm_mysqldb4git_name "(" $vm_mysqldb4git_ip ") is not running!\r\n"
  29. sudo virsh start $vm_mysqldb4git_name
  30. fi
  31.  
  32. # waiting for vm-gitlab6 is ready
  33. while (! ping -c 1 $vm_gitlab6_ip); do sleep 1; done
  34.  
  35. sudo virsh list --all
  36.  
  37. # start services in vm-gitlab6
  38. sshpass -p $vm_gitlab6_passwd ssh $vm_gitlab6_login@$vm_gitlab6_ip "sudo /etc/init.d/gitlab restart"
  39. sshpass -p $vm_gitlab6_passwd ssh $vm_gitlab6_login@$vm_gitlab6_ip "sudo /etc/init.d/nginx restart"
  40.  
  41. # start local nginx service
  42. echo "start nginx at localhost:" `hostname`
  43. sudo /etc/init.d/nginx restart
  44.  
  45. echo "gitlab, mysqldb4git virtual machines and services are now ready !"
  46. echo "================================================================="

关闭脚本如下:

  1. #!/bin/bash
  2. # stop-gitlab.sh
  3. # cheungmine@gmail.com
  4. ################################################################################
  5. # vm-gitlab6
  6. vm_gitlab6_name='vm-gitlab6'
  7. vm_gitlab6_ip='192.168.122.24'
  8. vm_gitlab6_login='car'
  9. vm_gitlab6_passwd='abc1234'
  10.  
  11. # vm-mysqldb4git
  12. vm_mysqldb4git_name='vm-mysqldb4git'
  13. vm_mysqldb4git_ip='192.168.122.139'
  14. vm_mysqldb4git_login='car'
  15. vm_mysqldb4git_passwd='abc1234'
  16.  
  17. echo "================================================================="
  18. echo "stop gitlab, mysqldb4git virtual machines and services..."
  19.  
  20. # stop services on vm-gitlab6
  21. if (! ping -c 1 $vm_gitlab6_ip); then
  22. echo -e $vm_gitlab6_name "(" $vm_gitlab6_ip ") is not running!\r\n"
  23. else
  24. sshpass -p $vm_gitlab6_passwd ssh $vm_gitlab6_login@$vm_gitlab6_ip "sudo /etc/init.d/gitlab stop"
  25. sshpass -p $vm_gitlab6_passwd ssh $vm_gitlab6_login@$vm_gitlab6_ip "sudo /etc/init.d/nginx stop"
  26. sleep 10
  27. sudo virsh shutdown $vm_gitlab6_name
  28. fi
  29.  
  30. # stop services on vm-mysqldb4git
  31. if (! ping -c 1 $vm_mysqldb4git_ip); then
  32. echo -e $vm_mysqldb4git_name "(" $vm_mysqldb4git_ip ") is not running!\r\n"
  33. else
  34. # close mysqldb
  35. # sleep 5
  36. sudo virsh shutdown $vm_mysqldb4git_name
  37. sleep 5
  38. fi
  39.  
  40. sudo virsh list --all
  41.  
  42. # stop local nginx service
  43. echo "stop nginx at localhost:" `hostname`
  44. sudo /etc/init.d/nginx stop
  45.  
  46. echo "gitlab, mysqldb4git virtual machines are shutdown !"
  47. 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. 两个对象用equals方法比较为true,它们的Hashcode值相同吗?

    两个对象用equals方法比较为true,它们的Hashcode值相同吗? 答:不一定相同.正常情况下,因为equals()方法比较的就是对象在内存中的值,如果值相同,那么Hashcode值也应该相同 ...

  2. 关于一些基础的Java问题的解答(三)

    11. HashMap和ConcurrentHashMap的区别   从JDK1.2起,就有了HashMap,正如上一个问题所提到的,HashMap与HashTable不同,不是线程安全的,因此多线程 ...

  3. 关于 minor allele frequency(次等位基因频率)的理解

    引用自NCBI的概念(https://www.ncbi.nlm.nih.gov/projects/SNP/docs/rs_attributes.html#gmaf) Global minor alle ...

  4. webpack2 配置 示例

    // https://github.com/webpack-contrib/extract-text-webpack-plugin var webpack = require("webpac ...

  5. popupwindow中EditText获取焦点后自动弹出软键盘

    关于popupwindow中EditText获取焦点后自动弹出软键盘的问题,玩过手机qq或空间的童鞋应该知道,再点击评论时会弹出一个编辑框,并且伴随软键盘一起弹出是不是很方便啊,下面我们就来讲一下实现 ...

  6. Mysql创建、删除用户、用户管理等相关:转载http://www.cnblogs.com/fly1988happy/archive/2011/12/15/2288554.html

    MySql中添加用户,新建数据库,用户授权,删除用户,修改密码(注意每行后边都跟个;表示一个命令语句结束): 1.新建用户 登录MYSQL: @>mysql -u root -p @>密码 ...

  7. intent flags标记

    Intent Flag介绍 FLAG_ACTIVITY_BROUGHT_TO_FRONT  这个标志一般不是由程序代码设置的,如在launchMode中设置singleTask模式时系统帮你设定. F ...

  8. FFmpeg与libx264接口源代码简单分析

    ===================================================== H.264源代码分析文章列表: [编码 - x264] x264源代码简单分析:概述 x26 ...

  9. 剑指Offer——银行考试

    剑指Offer--银行考试 网申简历 一. 银行网申简历主要看哪些方面? 1.职业形象(30%),基本体现为证件照: 2.学校+成绩+校内表现(40%),体现为证书,成绩排名以及任职经历等: 3.校外 ...

  10. javascript之正则表达式

    创建正则表达式的两种方法 显式: new RegExp("pattern"[,"flags"]); 例 var regex = new ("abc&q ...