Nginx+Squid+Apache
环境:
OS: RHEL 5.4
Nginx IP: 192.168.128.134
Squid_1 IP: 192.168.128.135
Squid_2 IP: 192.168.128.137
Squid_2 IP: 192.168.128.139
Apache IP: 192.168.128.136
网站域名:pic.test.com
软件版本:Nginx 0.8.15
Squid 3.0.STABLE7
Apache 2.2.14
因我们的架构是做一个漫画网站.全都是静态的页面.所以不需要安装php.
开始安装:
Nginx: (192.168.128.134)
1、安装Nginx所需的pcre库, fair组件
#cd /usr/local/src/tarbag
#tar zxvf pcre-7.9.tar.gz -C ../software
#cd ../software/pcre-7.9/
#./configure
#make && make install
#cd ../../tarbag
#tar xvzf gnosek-nginx-upstream-fair-2131c73.tar.gz -C ../software
2、安装Nginx
#tar zxvf nginx-0.8.15.tar.gz -C ../software
#cd ../software/nginx-0.8.15/
#./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --add-module=/usr/local/gnosek-nginx-upstream-fair-2131c73
#make && make install
#cd ../../tarbag
3、创建Nginx日志目录
#mkdir -p /www/nginx/logs
#chmod +w /www/nginx/logs
#chown -R www:www /www/nginx/logs
4、创建Nginx配置文件
①、在/usr/local/nginx/conf/目录中创建nginx.conf文件:
#rm -f /usr/local/nginx/conf/nginx.conf
#vi /usr/local/nginx/conf/nginx.conf
user www www;
worker_processes 8;
error_log /www/nginx/logs/nginx_error.log crit;
pid /usr/local/nginx/nginx.pid;
#Specifies the value for maximum file deors that can be opened by this process.worker_rlimit_nofile 65535;
events
{
use epoll;
worker_connections 65535;
}
http
{
include mime.types;
default_type application/octet-stream;
keepalive_timeout 120;
tcp_nodelay on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 128k;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.0;
gzip_comp_level 2;
gzip_types text/plain application/x-java text/css application/xml;
gzip_vary on;
upstream pic.test.com {
server 192.168.128.135:80;
server 192.168.128.137:80;
server 192.168.128.139:80;
}
server
{
listen 80;
server_name pic.test.com;
location / {
proxy_pass http://pic.test.com;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /NginxStatus {
stub_status on;
access_log on;
auth_basic "NginxStatus";
}
log_format www_test_com '$remote_addr - $remote_user [$time_local] $request '
'"$status" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /www/nginx/logs/www.log www_test_com;
}
}
5、优化Linux内核参数
vi /etc/sysctl.conf
在末尾增加以下内容:
引用
# Add
net.ipv4.tcp_max_syn_backlog = 65536
net.core.netdev_max_backlog = 32768
net.core.somaxconn = 32768
net.core.wmem_default = 8388608
net.core.rmem_default = 8388608
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_timestamps = 0
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 2
net.ipv4.tcp_tw_recycle = 1
#net.ipv4.tcp_tw_len = 1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_mem = 94500000 915000000 927000000
net.ipv4.tcp_max_orphans = 3276800
#net.ipv4.tcp_fin_timeout = 30
#net.ipv4.tcp_keepalive_time = 120
net.ipv4.ip_local_port_range = 1024 65535
使配置立即生效:
/sbin/sysctl –p
6、nginx开机自动启动的实现:
# vim /etc/init.d/nginx
#!/bin/sh
#chkconfig: 35 85 15
#deion: nginx
#function: use this to stop,start,restart nginx....
#author:lw.yang
nginx_BIN=/usr/local/nginx/sbin/nginx
nginx_CONF=/usr/local/nginx/conf/nginx.conf
nginx_PID=/usr/local/nginx/logs/nginx.pid
nginx_PORT=`/bin/netstat -ntpl |grep nginx |grep 80 |wc -l`
case $1 in
start)
if [ $nginx_PORT = 0 ];then
echo "staring nginx..."
$nginx_BIN
else echo "starting naginx failed,Address already in use..."
exit 2
fi
;;
stop)
echo "stoping nginx..."
if [ -f $nginx_PID ];then
kill -QUIT `cat $nginx_PID`
else echo "nginx is no running...."
fi
;;
status)
if [ -f $nginx_PID ];then
echo "nginx is running..."
else echo "nginx is stop..."
fi
;;
restart)
if [ -f $nginx_PID ];then
kill -HUP `cat $nginx_PID`
else echo "nginx is no running...."
fi
;;
*)
echo "Usage: $0 {start|stop|status|restart}"
exit 1
;;
esac
# chmod +x /etc/init.d/nginx
# chkconfig --add nginx
# chkconfig nginx on
# service nginx start
staring nginx...
Squid安装 (192.168.128.135-137-139)
#cd /usr/local/src/tarbag
#wget http://www.squid-cache.org/Versions/v3/3.0/squid-3.0.STABLE7.tar.gz
# groupadd squid
# useradd -g squid -s /sbin/nologin squid
# tar -zxvf squid-3.0.STABLE7.tar.gz –C ../software/
#cd /usr/local/src/software/squid-3.0.STABLE7/
# ./configure --prefix=/usr/local/squid --enable-gnuregex --enable-arp-acl --enable-auth="basic" --enable-basic-auth-helpers="NCSA" --enable-async-io=80 --enable-storeio=ufs --enable-icmp --enable-kill-parent-hack --enable-snmp --disable-ident-lookups --enable-cache-digests --enable-ssl --enable-delay-pools --enable-poll --enable-linux-netfilter --enable-underscore --enable-err-language="Simplify_Chinese" --enable-default-err-languages="Simplify_Chinese"
解释说明:
--prefix=/usr/local/squid //指定安装路径
--enable-arp-acl //这样可以在规则设置中直接通过客户端的MAC地址进行管理,防止客户使用IP欺骗
--enable-async-io=80 //这个主要是设置async模式来运行squid,我的理解是设置用线程来运行squid,如果服务器配置很不错,有1G以上内存,cpu使用SMP的方式的话可以考虑设成160或者更高。如果服务器比较糟糕就根据实际情况设了。另外此项还另cache文件支持aufs
--enable-auth-modules //此编译选项启用认证模块,可以对访问代理用户进行授权。
--enable-cache-digests //使能缓存摘要,本来此项目的是为了在Squid集群服务之间迅速发现缓存对象,这里在本地使用,可以加快请求时,检索缓存内容的速度。
--enable-err-language="Simplify_Chinese" 和--enable-default-err-languages="Simplify_Chinese" //指定出错是显示的错误页面为简体中文
--enable-delay-pools //此选项使能一个延时池,这样能对某些特定的请求限制额定带宽。
--enable-gnuregex //由于Squid大量使用字符串处理做各种判断,加此项能更好处理。
--enable-icmp //加入icmp支持
--disable-ident-lookups //防止系统使用RFC931规定的身份识别方法。
--enable-kill-parent-hack //关掉suqid的时候,要不要连同父进程一起关掉,这个当然要啦
--enable-linux-netfilter //允许使用Linux的透明代理功能。
--enable-poll //应启用Poll()函数而不是select()函数,通常而言poll(轮询)比select要好,但configure(脚本程序)已知Poll在某些平台下失效, 若你认为你比configure编译配置脚本程序要聪明的话,可以用这个选项启用Poll。总之就是用这个可以提升性能就是啦。
--enable-snmp //此选项可以让MRTG使用SNMP协议对服务器的流量状态进行监测,因此必须选择此项,使Squid支持SNMP接口。
关键字:Nginx Squid Apache1
新文章:
- CentOS7下图形配置网络的方法
- CentOS 7如何添加删除用户
- 如何解决centos7双系统后丢失windows启动项
- CentOS单网卡如何批量添加不同IP段
- CentOS下iconv命令的介绍
- Centos7 SSH密钥登陆及密码密钥双重验证详解
- CentOS 7.1添加删除用户的方法
- CentOS查找/扫描局域网打印机IP讲解
- CentOS7使用hostapd实现无AP模式的详解
- su命令不能切换root的解决方法
- 解决VMware下CentOS7网络重启出错
- 解决Centos7双系统后丢失windows启动项
- CentOS下如何避免文件覆盖
- CentOS7和CentOS6系统有什么不同呢
- Centos 6.6默认iptable规则详解