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規則詳解