cd pcre-8.02
./configure --prefix=/usr --enable-utf8 --enable-pcregrep-libbz2 --enable-pcregrep-libz
make
make install
tar zxvf nginx-0.8.35.tar.gz
cd nginx-0.8.35
--prefix=/usr/local/nginx --with-pcre --user=www --group=www --with-file-aio --with-http_ssl_module --with-http_flv_module --with-http_gzip_static_module --with-http_stub_status_module --with-cc-opt=' -O3'
make
make install
user www www;
worker_processes 1;
error_log logs/error.log notice;
pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
tcp_nopush on;
keepalive_timeout 65;
gzip on;
server {
listen 80;
server_name localhost;
index index.html index.htm;
root /var/www;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
echo "192.168.6.188" > /var/www/index.html
script "/opt/nginx_pid.sh" ###监控脚本
interval 2 ###监控时间
weight 2 ###目前搞不清楚
}
vrrp_instance VI_1 {
state MASTER ### 设置为 主
interface eth0 ### 监控网卡
virtual_router_id 51 ### 这个两台服务器必须一样
priority 101 ### 权重值 MASTRE 一定要高于 BAUCKUP
authentication {
auth_type PASS ### 加密
auth_pass eric ### 加密的密码,两台服务器一定要一样,不然会出错
}
track_script {
chk_http_port ### 执行监控的服务
}
virtual_ipaddress {
192.168.6.7 ### VIP 地址
}
}
script "/opt/nginx_pid.sh"
interval 2
weight 2
}
vrrp_instance VI_1 {
state BACKUP ### 设置为 辅机
interface eth0
virtual_router_id 51 ### 与 MASTRE 设置 值一样
priority 100 ### 比 MASTRE权重值 低
authentication {
auth_type PASS
auth_pass eric ### 密码 与 MASTRE 一样
}
track_script {
chk_http_port
}
virtual_ipaddress {
192.168.6.7
}
}
#!/bin/bash
A=`ps -C nginx --no-header |wc -l` ## 查看是否有 nginx进程 把值赋给变量A
if [ $A -eq 0 ];then ## 如果没有进程值得为 零
fi
/etc/init.d/keepalived start
Apr 20 18:37:39 nginx Keepalived_vrrp: Registering gratutious ARP shared channel
Apr 20 18:37:39 nginx Keepalived_vrrp: Opening file '/etc/keepalived/keepalived.conf'.
Apr 20 18:37:39 nginx Keepalived_healthcheckers: Opening file '/etc/keepalived/keepalived.conf'.
Apr 20 18:37:39 nginx Keepalived_healthcheckers: Configuration is using : 3401 Bytes
Apr 20 18:37:39 nginx Keepalived_vrrp: Configuration is using : 35476 Bytes
Apr 20 18:37:40 nginx Keepalived_vrrp: VRRP_Instance(VI_1) Transition to MASTER STATE
Apr 20 18:37:41 nginx Keepalived_vrrp: VRRP_Instance(VI_1) Entering MASTER STATE
Apr 20 18:37:41 nginx Keepalived_vrrp: Netlink: skipping nl_cmd msg...
Apr 20 18:37:41 nginx Keepalived_vrrp: VRRP_Script(chk_http_port) succeeded
Apr 20 18:38:23 varnish Keepalived_healthcheckers: Configuration is using : 3405 Bytes
Apr 20 18:38:23 varnish Keepalived_vrrp: Using MII-BMSR NIC polling thread...
Apr 20 18:38:23 varnish Keepalived_vrrp: Registering Kernel netlink reflector
Apr 20 18:38:23 varnish Keepalived_vrrp: Registering Kernel netlink command channel
Apr 20 18:38:23 varnish Keepalived_vrrp: Registering gratutious ARP shared channel
Apr 20 18:38:23 varnish Keepalived_vrrp: Opening file '/etc/keepalived/keepalived.conf'.
Apr 20 18:38:23 varnish Keepalived_vrrp: Configuration is using : 35486 Bytes
Apr 20 18:38:23 varnish Keepalived_vrrp: VRRP_Instance(VI_1) Entering BACKUP STATE
Apr 20 18:38:25 varnish Keepalived_vrrp: VRRP_Script(chk_http_port) succeeded
Apr 20 18:41:26 nginx Keepalived_vrrp: Terminating VRRP child process on signal
Apr 20 18:41:24 varnish Keepalived_vrrp: VRRP_Instance(VI_1) Entering MASTER STATE
Apr 20 18:41:24 varnish Keepalived_vrrp: Netlink: skipping nl_cmd msg...
本文出自 “linuxer” 博客,请务必保留此出处http://deidara.blog.51cto.com/400447/302402