環境:centos7,軟件:dnsmasq,nginx 服務器ip址址:192.168.0.133linux
須要安裝epel源:rpm -Uvh http://dl.fedoraproject.org/p... (主要是提供tinyproxy的rpm包)
yum update
yum install dnsmasq -y
3.修改配置文件:
1.vim /etc/dnsmasq.conf (dnsmasq的配置文件)nginx
resolv-file=/etc/resolv.conf (域名解析的配置的文件,能夠寫多個) address=/**.**.cn/192.168.0.133(指定須要dns緩存的域名,192.168.0.133爲dnsmasq服務的ip) address=/**.**.cn/192.168.0.133 address=/**.**.cn/192.168.0.133 listen-address=192.168.0.113(若是用此計算機做爲一組主機的默認DNS,就須要使用固定 IP 地址)
4.修改/etc/resolv.conf文件,添加dnsvim
nameserver 192.168.1.3(本地的dns) nameserver 202.106.0.20 nameserver 202.106.196.115
5.啓動服務
systemctl start dnsmasq
檢查進程是否運行:
ps -ef |grep dnsmasq
6.檢查一下端口是否正常:
netstat -anptu | grep 53 (是否對應着dnsmasq)centos
wget http://nginx.org/packages/cen...緩存
rpm -ivh nginx-1.10.3-1.el7.ngx.x86_64.rpm服務器
修改配置(/etc/nginx/conf.d/ttedu.conf):tcp
ttedu.conf優化
proxy_temp_path /home/nginxtemp; proxy_cache_path /home/nginxcache levels=1:2 keys_zone=ttedu:10g inactive=240m max_size=100g; server { listen 80; access_log /var/log/nginx/ttedu.log main; large_client_header_buffers 4 128k; client_max_body_size 300m; client_body_buffer_size 512k; proxy_connect_timeout 300; proxy_read_timeout 300; proxy_send_timeout 300; proxy_buffer_size 256k; proxy_buffers 4 512k; proxy_busy_buffers_size 512k; proxy_temp_file_write_size 512k; location / { resolver 202.106.0.20 8.8.8.8; resolver_timeout 30s; proxy_pass http://$host$request_uri; proxy_cache ttedu; proxy_cache_valid 200 301 302 7d; proxy_cache_valid any 5m; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-Server $host; add_header ttedu-cache "$upstream_cache_status"; } }
配置說明:
/home/nginxcache 緩存目錄
/var/log/nginx 日誌目錄
proxy_temp_path 臨時緩存目錄
resolver dns地址,根據實際狀況修改
max_size cache硬盤大小
/*levels設置目錄層次
keys_zone設置緩存名字和共享內存大小
inactive在指定時間內沒人訪問則被刪除在這裏是1天
max_size最大緩存空間*/
修改nginx配置(/etc/nginx/nginx.conf):
nginx.conf
修改配置:centos7
worker_processes 8; events { use epoll; worker_connections 10240; } log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"' ' "$upstream_cache_status"';
添加: ' "$upstream_cache_status"';單引號後有空格。
註釋access_log
添加配置:
server_tokens off;
重啓nginx服務 systemctl restart nginrest
因爲centos7默認採用的防火牆是firewalld.service,咱們採用iptables防火牆
關閉firewalld.service:
systemctl stop firewalld.service(關閉服務)
firewall-cmd --state (查看服務狀態是否爲not running)
安裝iptables防火牆
yum install iptables-service
以後添加規則:vim /etc/sysconfig/iptables
iptables :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [0:0] -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT #ping 使用的端口 -A INPUT -p icmp -j ACCEPT -A INPUT -i lo -j ACCEPT #放行的端口爲tcp 22,tcp 80 ,tcp及udp的53 -A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 53 -j ACCEPT -A INPUT -p udp -m state --state NEW -m udp --dport 53 -j ACCEPT #自身配置 -A INPUT -j REJECT --reject-with icmp-host-prohibited #自身配置 -A FORWARD -j REJECT --reject-with icmp-host-prohibited COMMI
防火牆配置完畢後。啓動iptables
systemctl restart iptables.service
事項 配置
修改打開文件數
vim /etc/security/limits.conf
* soft noproc 65535 * hard noproc 65535 * soft nofile 65535 * hard nofile 65535
關閉selinux setenforce 0修改/etc/selinux/config文件中設置SELINUX=disabled