Squid代理服务器的安装及使用
Squid代理服务器是基于Unix的代理服务器,可提供http代理,在有公网环境及内网ip的机器上部署Squid,然后提供给内网机器进行代理服务,达到内网机器也能访问外部网站的效果
也可以自己用其他方式进行http代理,如Java实现的http代理服务器等,参见我的另一个文档:Java实现Http代理服务器&通过http代理进行内网安装yum软件
1.安装
yum install -y squid
2.设置密码认证
##如设置认证账号为admin,密码为admin123,执行以下的命令然后输入密码。
htpasswd -c /etc/squid/passwd admin ##第一次建,建第一个账号
htpasswd /etc/squid/passwd user2 ##如果需要的话,增加第二个账号,没有-c
##如果报htpasswd不存在,执行httpd的安装,然后再操作
yum install -y httpd
3.设置squid.conf配置
-
##将所有的http_access allow的相关的先注解掉
-
##在http_access deny all这一行的上面增加以下配置
auth_param basic program /usr/lib64/squid/basic_ncsa_auth /etc/squid/passwd
auth_param basic children 5
auth_param basic realm chao's squid server
auth_param basic credentialsttl 2 hours
acl myacl proxy_auth REQUIRED
http_access allow myacl
http_access deny all
3. ##再增加几个日志相关的配置,方便日志管理
cache_access_log /var/log/squid/access.log
cache_log /var/log/squid/cache.log
cache_store_log /var/log/squid/store.log
logfile_rotate 3
4.启动Squid服务
##启动
systemctl start squid
##停止
systemctl stop squid
5.Squid日志管理
通过定时任务每天定时清理
crontab -e
0 3 * * * /usr/sbin/squid -k rotate
6. 在客户端进行使用
export http_proxy=http://admin:admin123@192.168.56.101:3128
export https_proxy=http://admin:admin123@192.168.56.101:3128
export no_proxy='127.0.0.1'
执行export命令后,然后进行正常的操作即可
,如: