mysql squid_iptable +squid 做mysql的代理

mysql有时候要从不同地方连接但是可能出现要用代理的情况

在代理机器上我们要做的是下面的工作

1,安装一个squid启动一个3306的端口 其他的不要安排

acl manager proto cache_object

acl localhost src 127.0.0.1/32

acl to_localhost dst 127.0.0.0/8

acl localnet src 10.0.0.0/8     # RFC1918 possible internal network

acl localnet src 172.16.0.0/12  # RFC1918 possible internal network

acl localnet src 192.168.0.0/16 # RFC1918 possible internal network

acl SSL_ports port 443

acl Safe_ports port 80          # http

acl Safe_ports port 21          # ftp

acl Safe_ports port 443         # https

acl Safe_ports port 70          # gopher

acl Safe_ports port 210         # wais

acl Safe_ports port 1025-65535  # unregistered ports

acl Safe_ports port 280         # http-mgmt

acl Safe_ports port 488         # gss-http

acl Safe_ports port 591         # filemaker

acl Safe_ports port 777         # multiling http

acl CONNECT method CONNECT

http_access allow manager localhost

http_access deny manager

http_access deny !Safe_ports

http_access deny CONNECT !SSL_ports

http_access allow localnet

http_access allow localhost

http_access deny all

http_port 3306

hierarchy_stoplist cgi-bin ?

coredump_dir /usr/local/squid/var/cache

refresh_pattern ^ftp:           1440    20%     10080

refresh_pattern ^gopher:        1440    0%      1440

refresh_pattern -i (/cgi-bin/|\?) 0     0%      0

refresh_pattern .               0       20%     4320

2,开启iptables的相应转发NAT

(1),转发的话一定要开启NAT转发功能ip_forward要启动

#!/bin/bash

modprobe ip_tables

modprobe ip_nat_ftp

modprobe ip_conntrack

modprobe ip_conntrack_ftp

echo 1>/proc/sys/net/ipv4/ip_forward

iptables -t nat -F

iptables -F

iptables -F -t nat

iptables -t nat -A PREROUTING -d 192.168.18.140 -p tcp --dport 3306 -j DNAT --to-destination 192.168

.18.97:3306

iptables -t nat -A POSTROUTING -d 192.168.18.97 -p tcp --dport 3306 -j SNAT --to 192.168.18.140

最好是在/etc/sysctl.conf

修改#

Controls the use of TCP syncookies

net.ipv4.tcp_syncookies = 1

这样就一切搞定

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值