In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
How to build a CDN in CentOS7 system, for this problem, this article details the corresponding analysis and answer, hoping to help more small partners who want to solve this problem find a simpler and easier way.
1. Test requirements
CDN Basic Experiment 2---Caching Based on nginx+squid
Build two web services using nginx.
A source site (then domain name: www.cdntest.com) configured to implement functionality: providing accessible web services;
The other is a reverse proxy that receives user requests. The configuration implementation function is: proxy to squid of the backend.
2. Build a squid service and configure it to achieve the following functions:
1) txt cache 1 month, jpg file not cached
2) Configure the back-to-source function, and the source site is the backend web server (nginx)
The detailed structure is as follows
Fig. 1
II. Experimental environment
Fig. 2
III. Preparation for the test
centos7 software source settings
Backup the original.repo file
[root@localhost ~]# mkdir /etc/yum.repos.d/bacakup
[root@localhost~]# mv /etc/yum.repos.d/* /etc/yum.repos.d/bacakup
Download Ali's yum source
[root@localhost~]# wget -O /etc/yum.repos.d/Centos-7.repo http://mirrors.aliyun.com/repo/Centos-7.repo
[root@localhost~]# wget -O /etc/yum.repos.d/epel-7.repo http://mirrors.aliyun.com/repo/epel-7.repo
Clear and create metadata cache
[root@localhost~]# yum clean all
[root@localhost~]# yum makecache
IV. Service Configuration
Nginx-Proxy virtual machine configuration
install Nginx
[root@proxy ~]# yum install -y nginx
Configuration/etc/nginx/nginx.conf Other default (centos6.x system is edited/etc/nginx/conf.d/defualt.conf)
[root@proxy ~]# vim /etc/nginx/nginx.conf
server {
listen 80 default_server; #This port 80, the default is fine, can be changed according to actual needs
server_name www.cdntest.com; #This can be customized
location / {
proxy_pass http://192.168.56.5; #Fill in the IP of the squid server
}
}
Activate and activate nginx
[root@proxy ~]# systemctl enable nginx.service
[root@proxy ~]# systemctl start nginx.service
Squid cache server configuration
Install Squid
[root@squid ~]# yum install squid
Configure/etc/squid/squid.conf, save the rest as default
[root@squid ~]# vim /etc/squid/squid.conf
acl url_image url_regex -i ^http://.*\. jpg$
no_cache deny url_image
http_access allow deny#In the experiment, all (deny changed to allow) can be allowed, and the actual production environment can be configured according to the situation.
http_port 192.168.56.5:80 accel vhost #Configure squid local NIC and port 80. If dual NIC, you can select the one used to access the source server.
cache_peer 192.168.56.4 parent 80 0 originserver #This is the origin server for the reverse proxy
cache_dir ufs /var/spool/squid 100 16 256 #cache directory
The requested URL/log/squid/cache.log was not found on this server.
refresh_pattern -i \.txt $43200 100% 43200 #Cache rules, txt file saved for one month
Activate and start squid services
[root@squid ~]# systemctl enable squid.service
[root@squid ~]# systemctl start squid.service
Nginx-Web Server Configuration
Install nginx as above.
Configuration/etc/nginx/nginx.conf
[root@server ~]# vim /etc/nginx/nginx.conf
server {
server_name www.cdntest.com; #Configure domain name, others can be kept by default
}
Activation and activation services as above.
Note: In order to meet the requirements of the experiment, you must have.txt files and.jpg files on your nginx-web server.
5. Client access and validation cache
Edit the C:\Windows\System32\drivers\etc\hosts file on Windows
Add the following two lines
192.168.56.3 www.cdntest.com
192.168.56.3 cdntest.com #This enables Windows browsers to access this domain directly
Nginx-Proxy This reverse proxy server
Enter www.cdntest.com or cdntest.com in your browser and access the following
Fig. 3
Verify cache success
Executed under nginx-proxy server
[root@proxy ~]# curl -I http://192.168.56.5/txt/5.txt #view txt cache (Figure 4)
[root@proxy ~]# curl -I http://192.168.56.5/images/work-1.jpg #View image cache (Figure 5)
return results
Fig. 4
Fig. 5
About how to build a CDN in CentOS7 system, the answer to the question is shared here. I hope the above content can be of some help to everyone. If you still have a lot of doubts, you can pay attention to the industry information channel to learn more about it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.