Nginx 역방향 에이전트 웹 부하 균형 실현
,DNS、 、LVS ( )、F5( , , ) DNS, Web
DNS , DNS 。 , down ,DNS , , , , 。 DNS web , 3 IP, 。 IPv4 , , .
nginx
: web server( Apache, Nginx), , , 。 ,Nginx max_fails , , DNS 。 。 .
nginx : IP nginx , IP 。 , Nginx Server ,Nginx Server weight fail_timeout 。 :
。 , Web server , web server 。
NFS :Network file system NFS SUN , 。 , NFS .
NFS PHP-FPM (172.16.251.215)
、 Nginx
1、
2、 Nginx
( )
# groupadd nginx
# useradd -g nginx -s /bin/false -M nginx
./configure \
--prefix=/usr \
--sbin-path=/usr/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx/nginx.pid \
--lock-path=/var/lock/nginx.lock \
--user=nginx \
--group=nginx \
--with-http_ssl_module \
--with-http_flv_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/tmp/nginx/client/ \
--http-proxy-temp-path=/var/tmp/nginx/proxy/ \
--http-fastcgi-temp-path=/var/tmp/nginx/fcgi/ \
--with-pcre
make && make install
3、 Nginx
( )
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /etc/sysconfig/nginx
# pidfile: /var/run/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/etc/nginx/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
make_dirs() {
# make required directories
user=`nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -`
options=`$nginx -V 2>&1 | grep 'configure arguments:'`
for opt in $options; do
if [ `echo $opt | grep '.*-temp-path'` ]; then
value=`echo $opt | cut -d "=" -f 2`
if [ ! -d "$value" ]; then
# echo "creating" $value
mkdir -p $value && chown -R $user $value
fi
fi
done
}
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
make_dirs
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
configtest || return $?
stop
sleep 1
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
4、 Nginx
( )
#
#user nobody;
# ( CPU )
worker_processes 1;
# , [debug|info|notice|warn|error|crit]
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
# pid
#pid logs/nginx.pid;
events {
# I/O ,Linux epoll ,FreeBSD kqueue
#use epoll;
worker_connections 1024; #
}
http {
include 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"';
# $remote_addr: Nginx IP
#X-Forwarded-For: ip .
#$remote_user:
#$time_local:
#$request: URL http
#$status: , 200,, 404
#$body_bytes_sent: ;
#$http_referer: ;
#$http_usr_agent: .
# combined
access_log path [format [buffer=size | off]]
access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
#proxy_cache_path /nginx/cache levels=1:2 keys_zone=mycache:16m
# inactive=24h max_size=1g;
upstream backend
server 172.16.251.253 weight=1 max_fails=2 fail_timeout=30s;
server 172.16.251.244 weight=1 max_fails=2 fail_timeout=30s;
server 172.16.251.208 weight=1 max_fails=2 fail_timeout=30s;
}
#upstream: proxy_pass fastcgi_pass
#weight: , , . 1
#max_fails: , (404 ), . 1, 0
#fail_timeout: max_fails , .
#down: , ip_hash
#backup: backup .
server {
listen 80;
server_name www.nginx.com 220.2.2.2;
#server_name , IP
location / {
proxy_pass http://backend;
proxy_set_header host www.nginx.com;
#proxy_cache mycache;
#proxy_cache_valid 200 301 1d;
#proxy_cache_valid 404 1m;
}
#proxy_pass:
#proxy_connect_timeout: _
#proxy_read_timeout: _ _ 。
#proxy_send_timeout: _
#proxy_buffer_size: _ Nginx _
#proxy_buffers: nginx buffer
#proxy_busy_buffers_size: Proxy_buffers
#proxy_temp_file_write_size: ;
# location / {
# root html;
# index index.php index.html index.htm;
# }
error_page 404 /404.html;
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 172.16.251.215:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}
# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443;
# server_name localhost;
# ssl on;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_timeout 5m;
# ssl_protocols SSLv2 SSLv3 TLSv1;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}
、 web , Httpd Web Server:172.16.251.208
Web Server: 172.16.251.244
1、 http2.4.9, apr apr-util。apr apache portable runtime
( )
#tar xf apr-1.5.0.tar.bz2
#cd apr-1.5.0
#./configure --prefix=/usr/local/apr
#make && make install
2、 apr-util-1.5.2
( )
#tar xf apr-util-1.5.2.tar.bz2
#cd apr-util-1.5.2
#./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/
#make && make install
3、 http2.4.9
( )
# tar xf httpd-2.4.9.tar.bz2
# cd httpd-2.4.9
# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd24 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --enable-modules=most --enable-mpms-shared=all --with-mpm=event
# make && make install
4、 :
( )
#ln -sv /usr/local/apache/include/usr/include/httpd
#vim /etc/profile.d/httpd.sh
exportPATH=/usr/local/apache/bin:$PATH
#vim /etc/man.conf
#MANPATH /usr/local/apache/man
5、 httpd , Pid vim /etc/httpd24/httpd.conf
( )
PidFile "/var/run/httpd.pid"
6、 :
(1) MPM
,MPM 。 MPM, 。 MPM, 。 MPM, configure , --with-mpm=NAME。NAME MPM 。 , ./httpd -l MPM。 , MPM。
(2) MPM
Unix ,MPM , 。 MPM LoadModule MPM, 。 configure , --enable-mpms-shared 。 all , MPM 。 。 MPM, configure --with- mpm , 。 LoadModule MPM。
7、 SysV /etc/rc.d/init.d/httpd, :
( )
#!/bin/bash
#
# httpd Startup script for the Apache HTTP Server
#
# chkconfig: - 85 15
# description: Apache is a World Wide Web server. It is used to serve \
# HTML files and CGI.
# processname: httpd
# config: /etc/httpd/conf/httpd.conf
# config: /etc/sysconfig/httpd
# pidfile: /var/run/httpd.pid
# Source function library.
. /etc/rc.d/init.d/functions
if [ -f /etc/sysconfig/httpd ]; then
. /etc/sysconfig/httpd
fi
# Start httpd in the C locale by default.
HTTPD_LANG=${HTTPD_LANG-"C"}
# This will prevent initlog from swallowing up a pass-phrase prompt if
# mod_ssl needs a pass-phrase from the user.
INITLOG_ARGS=""
# Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
# with the thread-based "worker" MPM; BE WARNED that some modules may not
# work correctly with a thread-based MPM; notably PHP will refuse to start.
# Path to the apachectl script, server binary, and short-form for messages.
apachectl=/usr/local/apache/bin/apachectl
httpd=${HTTPD-/usr/local/apache/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/var/run/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd}
RETVAL=0
start() {
echo -n $"Starting $prog: "
LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch ${lockfile}
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc -p ${pidfile} -d 10 $httpd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
다양한 언어의 JSONJSON은 Javascript 표기법을 사용하여 데이터 구조를 레이아웃하는 데이터 형식입니다. 그러나 Javascript가 코드에서 이러한 구조를 나타낼 수 있는 유일한 언어는 아닙니다. 저는 일반적으로 '객체'{}...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.