首页 > 文章 > WEB > Nginx > 正文

Nginx 安装与配置
2011-06-16 19:23:39   来源:   评论:0 点击:

Nginx 安装与配置

Nginx 安装与配置

系统准备

echo '2' > /proc/sys/net/ipv4/conf/lo/arp_announce

echo '1' > /proc/sys/net/ipv4/conf/lo/arp_ignore

echo '2' > /proc/sys/net/ipv4/conf/all/arp_announce

echo '1' > /proc/sys/net/ipv4/conf/all/arp_ignore

sysctl net.ipv4.ip_forward=1

sysctl net.ipv4.netfilter.ip_conntrack_tcp_timeout_syn_recv=60

sysctl net.ipv4.tcp_max_syn_backlog=8192

sysctl net.ipv4.tcp_synack_retries=2

sysctl net.ipv4.tcp_syn_retries=2

sysctl -w

sysctl -p

/etc/rc.local中配置好路由策略

/etc/init.d/network在start函数的最后一行添加一句:source /etc/rc.local 让重启网络服务之后自动执行路由策略脚本。

一、nginx安装

yum install -y gcc*

yum install -y pcre-devel

yum install -y openssl-devel

/opt/nginx-0.8.53

./configure

make

make install

cd /usr/local/nginx/conf/

vi ./nginx.conf

/usr/local/nginx/sbin/nginx

 

二、配置nginx

[root@***]# vi ./nginx.conf

#user
nobody;

worker_processes
16;

#error_log
logs/error.log;

#error_log
logs/error.log
notice;

#error_log
logs/error.log
info;

#pid
logs/nginx.pid;

events {


worker_connections
10240;

}

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"';


#access_log
logs/access.log
main;


sendfile
on;


#tcp_nopush
on;


#keepalive_timeout
0;


keepalive_timeout
65;


#gzip
on;


upstream  itminer
{


server
192.168.0.11;


server   192.168.0.12;

 

ip_hash;


}


server {


listen
80;


server_name www.itminer.net;


#charset koi8-r;


access_log
logs/host.access.log
main;


#location / {


#root
html;


# index
index.html index.htm index.jsp default.jsp;


#}


location / {


proxy_pass
http://itminer;


proxy_redirect
off;


proxy_set_header
host
$host;


proxy_set_header
X-Real-IP
$remote_addr;


proxy_set_header
X-Forwarded-For $proxy_add_x_forwarded_for;


log_format
nginx.itminer.net
'$remote_addr - $remote_user [$time_local] $request '


'"$status" $body_bytes_sent "$http_referer" '


'"$http_user_agent" "$http_x_forwarded_for"';


log_format
nginx.itminer.net '$remote_addr - $remote_user [$time_local] $request '


'"$status" $body_bytes_sent "$http_referer" '


'"$http_user_agent" "$http_x_forwarded_for"';


access_log
logs/access.log
nginx.itminer.net;


}

#error_page
404
/404.html;

......

后面的保持不变。


三:nginx的开启和关闭

开启: /usr/local/nginx/sbin/nginx

关闭:killall nginx

日志:/usr/local/nginx/logs/*

 

四、keepalived安装

cd /opt

tar zxf keepalived-1.1.17.tar.gz

cd keepalived-1.1.17

./configure

make

make install

cd /usr/local/etc/keepalived

vi keepalived.conf


五、配置keepalived

[root@teset keepalived]# vi ./keepalived.conf

! Configuration File for keepalived

global_defs {


notification_email {
#报警邮件设置

     test@itminer.net


}


notification_email_from nginx_keepalived@byidc.com


smtp_server 127.0.0.1


smtp_connect_timeout 30


router_id LVS_DEVEL

}

vrrp_instance VI_31 {


state BACKUP

#备用服务器
MASTER为主
BACKUP为备


interface eth2
#监控接口


#track_interface {


#
eth1


#
eth2


#
eth3


#}


virtual_router_id 31

#
mcast_src_ip  220.181.6.175


priority 80

#优先级不能高于MASTER服务器


advert_int 1


authentication {


auth_type PASS


auth_pass 1234
#主备通讯密钥


}


virtual_ipaddress {


220.181.6.53
#VIP


220.181.6.54


}

#
virtual_routes {
#虚拟路由

#
220.181.6.48/28 dev eth2

#
}

}

注意配置完之后,在iptables中设置好允许主备服务器监听网卡所在的网段互相可以访问。

六、keepalived的开启于关闭

开启:/usr/local/sbin/keepalived -D -f /usr/local/etc/keepalived/keepalived.conf

关闭:killall keepalived

日志:/var/log/messages
 

TOP

 

相关热词搜索:Nginx 安装与配置

上一篇:No input file specified for nginx httpd错误解决方法
下一篇:linux下查看nginx,apache,mysql,php的编译参数[转]

分享到: 收藏