The configuration method of CDN cache server is set up by Squid reverse proxy under linux

  • 2020-05-09 19:42:01
  • OfStack

Case study:
Web server: domain name www.abc.com IP: 192.168.21.129 telecom single line access
Access users: telecom broadband users, mobile broadband users
Problem: telecom users can open www.abc.com normally, mobile users can open www.abc.com slowly or even cannot open it
Solution: put one CDN proxy server in the mobile computer room, and let telecom users directly access Web server and mobile users access CDN proxy server through intelligent DNS parsing, so as to solve the problem of slow access of mobile users to Web server
Specific operation:
CDN proxy server:
System: CentOS 5.5 host name: cdn.abc.com IP:192.168.21.160 install Squid software, configure reverse proxy to build CDN cache server
Preparation before installation:
1. Turn off SELinux
vi /etc/selinux/config
Comment out #SELINUX=enforcing #
#SELINUXTYPE=targeted # comment out
SELINUX = disabled # increase
:wq save, close.
shutdown-r now restart the system


2. Open firewall port 80 (port 80 for squid configuration later)
vi /etc/sysconfig/iptables
Add the following
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
/ etc/init d/iptables restart # restart the firewall configuration to take effect


3. Modify the routing mode of the host
vi /etc/sysctl.conf
net.ipv4.ip_forward = 1 #0 for off, 1 for open routing use the sysctl-p command to view
4. Modify the host hosts file and add the domain name resolution record
vi /etc/hosts
192.168.21.129 www.abc.com # add a parsing record


===========================================================================
The installation start
1. Install Squid
yum install squid # installation (Squid 2.6)
service squid start # starts
service squid restart # restart
chkconfig squid on # setup startup


2. Configure Squid
cp etc/squid/squid conf etc/squid/squid confbak # backup
vi etc/squid/squid conf # edit files

http_port 80 transparent # sets squid port, which defaults to 3128 and is set to 80. The client does not need to enter the port number when opening the website
cache_mem 1024 MB # allocates the memory size
cache_dir ufs /var/spool/squid 4096 16 256 # set the cache file size
cache_effective_user squid # sets the user
cache_effective_group squid # sets the user group
access_log/var/log/squid/access log # set access log files
cache_log/var/log/squid/cache log # set the log file cache
cache_store_log/var/log/squid/store log # set the record file cache
visible_hostname cdn.abc.com # sets the squid server hostname
cache_mgr root@abc.com # set the administrator email (set it to your own email address)
acl all src 0.0.0.0/0.0.0.0 # set access control list, enabled by default
http_access allow all # sets access rights, commented out by default
cache_peer 192.168.21.129 parent 80 0 no-query originserver name=web # when a user accesses web, Squid sends a request to port 80 of 192.168.21.129
cache_peer_domain web www.com # set the web domain name to www.abc.com
cache_peer_access allow all # sets access rights to allow all external clients to access web

: wq! # save exit
service squid stop # stop
/usr/sbin/squid -z # initializes the cache cache directory
service squid start # start
The Squid reverse proxy server installation configuration is complete
==================================================================
Enable smart DNS
If a telecommunications user accesses the domain name www.abc.com resolved to 192.168.21.128
If a mobile user accesses the domain name www.abc.com resolved to 192.168.21.160
A dedicated connection is used between the CDN cache server and the Web server


Related articles: