V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
sam8818
V2EX  ›  CentOS

squid 完整部署方法,从安装到上线

  •  
  •   sam8818 · 2017-10-14 11:45:45 +08:00 · 2980 次点击
    这是一个创建于 2357 天前的主题,其中的信息可能已经有所发展或是发生改变。

    ###安装

    yum install squid -y
    yum install httpd-tools -y
    

    ###生成密码文件

    mkdir /etc/squid3/
    # test 是用户名
    htpasswd -cd /etc/squid3/passwords test
    # 提示输入密码,设密码为 test1234
    # 注意密码不要超过 8 位
    

    ###测试密码文件

    /usr/lib64/squid/basic_ncsa_auth /etc/squid3/passwords
    # 输入 用户名 密码
    test test1234
    # 提示 OK 说明成功,ERR 是有问题,请检查一下之前步骤
    OK
    # 测试完成,crtl + c 打断
    

    ###配置

    vim /etc/squid/squid.conf
    
    # 修改配置文件内容(加入认证)
    # And finally deny all other access to this proxy
    auth_param basic program /usr/lib64/squid/basic_ncsa_auth /etc/squid3/passwords #账户密码文件
    auth_param basic realm proxy
    auth_param basic children 50 #最多 50 个账户同时运行
    auth_param basic realm CoolTube Proxy Server #密码框描述
    auth_param basic credentialsttl 2 hours #认证持续时间
    acl authenticated proxy_auth REQUIRED #对 authenticated 进行外部认证
    http_access allow authenticated #允许 authenticated 中的成员访问
    http_access deny all #拒绝所有其他访问
    visible_hostname squid.CoolTube #代理机名字
    
    # 这里是端口号,可以按需修改
    # http_port 3128 这样写会同时监听 ipv6 和 ipv4 的端口,推荐适应下面的配置方法。
    http_port 0.0.0.0:3128
    

    ###启动服务

    # 先初始化一下
    squid -z
    # 启动
    systemctl start squid
    systemctl start squid.service
    # 停止
    systemctl stop squid.service
    # 重启
    systemctl restart squid.service
    # 把 3128 端口加入防火墙过滤掉
    firewall-cmd --permanent --zone=public --add-port=3128/tcp
    # 重启防火墙
    firewall-cmd --reload
    

    ###客户端访问

    在浏览器中修改代理配置即可。
    在 windows 中:
    Internet 选项 -> 连接 -> 局域网连接 -> 代理服务器
    
    在 macOSX 中:
    Safari -> 偏好设置 -> 代理 -> Web 代理
    然后输入你的代理地址和端口,就可以正常工作了。
    

    ###正式环境增加用户

    htpasswd -cd /etc/squid3/passwords 用户名
    # 提示输入密码,设密码为 test1234
    # 注意密码不要超过 8 位
    /usr/lib64/squid/basic_ncsa_auth /etc/squid3/passwords
    # 输入 用户名 密码
    test001 test1234
    # 提示 OK 说明成功,ERR 是有问题,请检查一下之前步骤
    OK
    # 测试完成,crtl + c 打断
    
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1408 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 17:28 · PVG 01:28 · LAX 10:28 · JFK 13:28
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.