dnsmasq+nginx缓存

环境:centos7,软件:dnsmasq,nginx 服务器ip址址:192.168.0.133

一.安装dnsmasq:

需要安装epel源:rpm -Uvh http://dl.fedoraproject.org/p... (主要是提供tinyproxy的rpm包)
yum update
yum install dnsmasq -y
3.修改配置文件:
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.133
address=/**.**.cn/192.168.0.133
listen-address=192.168.0.113(如果用此计算机作为一组主机的默认DNS,就需要使用固定 IP 地址)

4.修改/etc/resolv.conf文件,添加dns

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)

二.nginx安装

wget http://nginx.org/packages/cen...

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/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

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值