环境:centos7,软件:dnsmasq,nginx 服务器ip址址:192.168.0.133
一.安装dnsmasq:
需要安装epel源:rpm -Uvh (主要是提供tinyproxy的rpm包)
yum updateyum install dnsmasq -y3.修改配置文件:1.vim /etc/dnsmasq.conf (dnsmasq的配置文件)resolv-file=/etc/resolv.conf (域名解析的配置的文件,可以写多个)address=/**.**.cn/192.168.0.133(指定需要dns缓存的域名,192.168.0.133为dnsmasq服务的ip)address=/**.**.cn/192.168.0.133address=/**.**.cn/192.168.0.133listen-address=192.168.0.113(如果用此计算机作为一组主机的默认DNS,就需要使用固定 IP 地址)
4.修改/etc/resolv.conf文件,添加dns
nameserver 192.168.1.3(本地的dns)nameserver 202.106.0.20nameserver 202.106.196.115
5.启动服务
systemctl start dnsmasq检查进程是否运行:ps -ef |grep dnsmasq6.检查一下端口是否正常:netstat -anptu | grep 53 (是否对应着dnsmasq)二.nginx安装
wget
rpm -ivh nginx-1.10.3-1.el7.ngx.x86_64.rpm
修改配置(/etc/nginx/conf.d/ttedu.conf):
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修改配置: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 ngin三.配置防火墙:
由于centos7默认采用的防火墙是firewalld.service,我们采用iptables防火墙
关闭firewalld.service:systemctl stop firewalld.service(关闭服务)firewall-cmd --state (查看服务状态是否为not running)安装iptables防火墙yum install iptables-service之后添加规则:vim /etc/sysconfig/iptablesiptables: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-prohibitedCOMMI
防火墙配置完毕后。启动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