设为首页 收藏本站
查看: 1032|回复: 0

[经验分享] gitlab6 nginx配置和启动脚本

[复制链接]

尚未签到

发表于 2016-12-25 09:09:02 | 显示全部楼层 |阅读模式
  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 "================================================================="



  

  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-319013-1-1.html 上篇帖子: 使用gitlab实现上线自动化 下篇帖子: gitlab 安装 timeout: down: nginx: 0s, normally up, want up
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表