Nginx + keepalived
user nginx;
worker_processes 4;
error_log /var/log/nginx/error.log;
#error_log /var/log/nginx/error.log notice;
#error_log /var/log/nginx/error.log info;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
# Load config files from the /etc/nginx/conf.d directory
# The default server is in conf.d/default.conf
upstream backend
{
ip_hash;
server 172.16.249.74:80;
server 172.16.249.75:80 ;
}
server {
listen 80;
server_name www.firefox.com;
location / {
root /var/www/html;
index index.php index.html index.htm;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Formarded-For proxy_add_x_forwarded_for;
proxy_pass http://backend;
}
location /nginx {
access_log off;
stub_status on;
}
log_format access '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /data/logs/access.log access;
}
}
Master keepalived: configure file:
! Configuration File for keepalived
global_defs {
notification_email {
[email protected]
}
notification_email_from [email protected]
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 100
mcast_src_ip 172.16.249.32
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
172.16.249.100
}
}
slave keepalived: configure configure file
! Configuration File for keepalived
global_defs {
notification_email {
[email protected]
}
notification_email_from [email protected]
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 99
mcast_src_ip 172.16.249.64
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
172.16.249.100
}
}
로그 정보 보기:
[root@node1 keepalived]# tail /var/log/messages
Apr 27 17:47:32 node1 Keepalived_vrrp[2464]: Using LinkWatch kernel netlink reflector...
Apr 27 17:47:32 node1 Keepalived_vrrp[2464]: VRRP sockpool: [ifindex(2), proto(112), fd(10,11)]
Apr 27 17:47:32 node1 Keepalived_healthcheckers[2463]: Configuration is using : 7273 Bytes
Apr 27 17:47:32 node1 Keepalived_healthcheckers[2463]: Using LinkWatch kernel netlink reflector...
Apr 27 17:47:33 node1 Keepalived_vrrp[2464]: VRRP_Instance(VI_1) Transition to MASTER STATE
Apr 27 17:47:34 node1 Keepalived_vrrp[2464]: VRRP_Instance(VI_1) Entering MASTER STATE
Apr 27 17:47:34 node1 Keepalived_vrrp[2464]: VRRP_Instance(VI_1) setting protocol VIPs.
Apr 27 17:47:34 node1 Keepalived_vrrp[2464]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 172.16.249.100
Apr 27 17:47:34 node1 Keepalived_healthcheckers[2463]: Netlink reflector reports IP 172.16.249.100 added
Apr 27 17:47:39 node1 Keepalived_vrrp[2464]: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 172.16.249.100
nginx 서비스 프로 세 스 보기
# lsof -i :80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
nginx 1995 root 7u IPv4 12113 0t0 TCP *:http (LISTEN)
nginx 1997 nginx 7u IPv4 12113 0t0 TCP *:http (LISTEN)
nginx 1998 nginx 7u IPv4 12113 0t0 TCP *:http (LISTEN)
nginx 1999 nginx 7u IPv4 12113 0t0 TCP *:http (LISTEN)
nginx 2000 nginx 7u IPv4 12113 0t0 TCP *:http (LISTEN)
IP 주소 할당 여부 보기:
[root@node1 keepalived]# ip addr show
1: lo: mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:ed:5e:11 brd ff:ff:ff:ff:ff:ff
inet 172.16.249.32/16 brd 172.16.255.255 scope global eth0
inet 172.16.249.100/32 scope global eth0
inet6 fe80::20c:29ff:feed:5e11/64 scope link
nginx 서비스 모니터링 스 크 립 트 작성:
nohup /bin/bash /root/nginx.sh
#!/bin/bash
while :
do
nginxpid=`ps -C nginx --no-header | wc -l`
if [ $nginxpid -eq 0 ]; then
/usr/sbin/nginx #
sleep 3
nginxpid=`ps -C nginx --no-header | wc -l`
echo $nginxpid
if [ $nginxpid -eq 0 ]; then
/etc/rc.d/init.d/keepalived stop # ; keepalived
fi
fi
sleep 4
done
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
C에서 파일 입/출력저장 및 , 우리는 파일 유형을 가리키는 구조 포인터를 사용합니다 - FILE. fopen() 함수는 기존 파일을 열거나 새 파일을 만드는 데 사용됩니다. 여기서 fp는 열린(또는 생성된) 파일에 대한 참조를 보유할...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.