Linux下Squid配置(CDN,负载均衡)

Squid配置

服务端

安装服务

yum install squid -y

在这里插入图片描述
打开服务

systemctl start squid

在这里插入图片描述
查看打开结果

netstat -antlupe|grep 3128

在这里插入图片描述
修改配置文件/etc/squid/squid.conf

# And finally deny all other access to this proxy
http_access allow all

# Squid normally listens to port 3128
http_port 3128

# Uncomment and adjust the following to add a disk cache directory.
cache_dir ufs /var/spool/squid 100 16 256

在这里插入图片描述
重启服务

systemctl restart squid

在这里插入图片描述

客户端

配置代理
选择edit的preferences
在这里插入图片描述
选择网络选项
在这里插入图片描述
选择setting,配置IP地址以及端口
在这里插入图片描述
利用客户机上网,验证配置结果
在这里插入图片描述

CDN搭建

服务端(172.25.254.141)

yum install -y httpd
systemctl start httpd

在这里插入图片描述
编辑主文件

echo "Hello World">/var/www/html/index.html

在这里插入图片描述
访问结果
在这里插入图片描述

代理端(172.25.254.241)

yum install squid 
systemctl start squid

在这里插入图片描述
编写配置文件/etc/squid/squid.conf

# And finally deny all other access to this proxy
#允许其他主机的访问
http_access allow all

# Squid normally listens to port 3128
http_port 80		vhost vport			#指定使用端口
#指定父级主机,同时指定模式为仅代理模式
cache_peer 172.25.254.141 parent 80 0 proxy-only

# Uncomment and adjust the following to add a disk cache directory
#开启缓存
cache_dir ufs /var/spool/squid 100 16 256

在这里插入图片描述
重启服务

systemctl restart squid

在这里插入图片描述

测试机(172.25.254.41)

编辑/etc/hosts

172.25.254.241 www.octopus.com

在这里插入图片描述
配置代理
在这里插入图片描述
访问结果
在这里插入图片描述

负载均衡

服务器端1(172.25.254.141)
安装apache服务,启动,同时设置默认发布文件内容为22222222222222

yum install httpd -y 
echo "22222222222222" >/var/www/html/index.html

启动服务

systemctl start httpd

测试结果
在这里插入图片描述
服务器端2(172.25.254.41)
安装apache服务,启动,同时设置默认发布文件内容为11111111111111

yum install httpd -y 
echo "111111111111111" >/var/www/html/index.html

启动服务

systemctl start httpd

测试结果
在这里插入图片描述
squid端(172.25.24.241)
配置文件

参数 weight=2 权重参数
    cache_peer 172.25.254.141 parent 80 0 proxy-only no-query round-robin originserver name=web1
    cache_peer 172.25.254.41 parent 80 0 proxy-only no-query round-robin originserver name=web2 weight=2
    cache_peer_domain web1 web2 www.octopus.com

测试机
配置/etc/hosts

172.25.254.241 www.octopus.com

测试结果
在这里插入图片描述
在这里插入图片描述

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值