Centos 7.2 安裝配置帶使用者認證的squit正向 Proxy,centossquit

來源:互聯網
上載者:User

Centos 7.2 安裝配置帶使用者認證的squit正向 Proxy,centossquit
squit介紹?Squid 是一個緩衝 Internet 資料的軟體,其接收使用者的下載申請,並自動處理所下載的資料。當一個使用者想要下載一個首頁時,可以向 Squid 發出一個申請,要 Squid 代替其進行下載,然後 Squid 串連所申請網站並請求該首頁,接著把該首頁傳給使用者同時保留一個備份,當別的使用者申請同樣的頁面時,Squid 把儲存的備份立即傳給使用者。
?按照代理類型的不同,可以將 Squid 代理分為正向 Proxy和反向 Proxy,正向 Proxy中,根據實現方式的不同,又可以分為普通代理和透明代理。
普通代理:需要客戶機在瀏覽器中指定Proxy 伺服器的地址、連接埠。
透明代理:適用於企業的網關主機(共用接入 Internet)中,客戶機不需要指定Proxy 伺服器地址、連接埠等資訊,Proxy 伺服器需要設定防火牆策略將客戶機的 Web 存取資料轉交給代理服務程式處理。
反向 Proxy:是指以Proxy 伺服器來接受 Internet 上的串連請求,然後將請求轉寄給內部網路上的伺服器,並將從伺服器上得到的結果返回給 Internet 上請求串連的用戶端,此時Proxy 伺服器對外就表現為一個伺服器。
一、Proxy 伺服器系統內容
[root@ecs-35f2 ~]# cat /etc/redhat-release?
CentOS Linux release 7.2.1511 (Core)?
[root@ecs-35f2 ~]# ip add
1: lo: mtu 65536 qdisc noqueue state UNKNOWN?
? ? link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
? ? inet 127.0.0.1/8 scope host lo
? ? ? ?valid_lft forever preferred_lft forever
? ? inet6 ::1/128 scope host?
? ? ? ?valid_lft forever preferred_lft forever
2: eth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000
? ? link/ether fa:16:3e:49:29:b4 brd ff:ff:ff:ff:ff:ff
? ? inet 192.168.2.181/24 brd 192.168.2.255 scope global dynamic eth0
? ? ? ?valid_lft 75669sec preferred_lft 75669sec
? ? inet6 fe80::f816:3eff:fe49:29b4/64 scope link?
? ? ? ?valid_lft forever preferred_lft forever
二、yum安裝squid,這裡使用基於web服務apache的htpasswd密碼認證,所以也安裝上httpd[root@ecs-35f2 ~]# yum install -y squid
[root@ecs-35f2 ~]# yum install -y httpd
三、建立使用者並設定密碼,注意密碼長度不要超過8位[root@ecs-35f2 squid]# htpasswd -cd /etc/squid/passwords test?#test是自己取得使用者名稱
New password:???#輸入兩次相同的密碼
Re-type new password:?
Adding password for user test
四、驗證密碼檔案[root@ecs-35f2 squid]# /usr/lib64/squid/basic_ncsa_auth /etc/squid/passwords?
test qq..123
OK?
#顯示OK就證明成功(使用者名稱:test ,密碼qq..123),按ctrl+c 終端退出五、配置squid檔案,開啟預設安裝路徑 /etc/squid/squid.conf[root@ecs-35f2 squid]# vim /etc/squid/squid.conf
這裡我只放通可以使用代理的內網IP網段和連接埠號碼
因為規則是從上往下的,所以要在http_access deny all 拒絕所有這條規則上面添加認證使用者配置,使用預設連接埠3128,也可以自己更改,等下用戶端需要用到這個連接埠號碼。 添加註釋: #http_access allow localnet
添加: auth_param basic program /usr/lib64/squid/basic_ncsa_auth /etc/squid/passwords
auth_param basic credentialsttl 5 hours
acl ncsa_users proxy_auth REQUIRED
http_access allow ncsa_users
去掉注釋: cache_dir ufs /var/spool/squid 100 16 256

儲存退出
六、初始化squid[root@ecs-35f2 ~]# squid -z

按ctrl+c 終端退出
七、開啟squid並設定開機啟動[root@ecs-35f2 ~]# systemctl start squid.service?
[root@ecs-35f2 ~]# systemctl enable? squid.service?
Created symlink from /etc/systemd/system/multi-user.target.wants/squid.service to /usr/lib/systemd/system/squid.service.
八、關閉防火牆,設定SELINUX=disabled[root@ecs-35f2 ~]# systemctl stop firewalld
[root@ecs-35f2 ~]# cat /etc/selinux/config?
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#? ? ?enforcing - SELinux security policy is enforced.
#? ? ?permissive - SELinux prints warnings instead of enforcing.
#? ? ?disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
#? ? ?targeted - Targeted processes are protected,
#? ? ?minimum - Modification of targeted policy. Only selected processes are protected.?
#? ? ?mls - Multi Level Security protection.
SELINUXTYPE=targeted?九、用戶端Windows設定: 開啟IE瀏覽器》Internet選項》串連》區域網路設定》Proxy 伺服器(設定Proxy 伺服器的IP和連接埠,這裡的Proxy 伺服器內網ip是192.168.2.181,預設連接埠3128。Proxy 伺服器是可以上公網的)

設定好如果點擊上網就會彈出輸入使用者名稱和密碼視窗,輸入使用者名稱和和密碼即可上網。

查看IP
Linux用戶端:[root@ecs-5c78-0002 ~]# ip add
1: lo: mtu 65536 qdisc noqueue state UNKNOWN qlen 1
? ? link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
? ? inet 127.0.0.1/8 scope host lo
? ? ? ?valid_lft forever preferred_lft forever
? ? inet6 ::1/128 scope host?
? ? ? ?valid_lft forever preferred_lft forever
2: eth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000
? ? link/ether fa:16:3e:08:88:97 brd ff:ff:ff:ff:ff:ff
? ? inet 192.168.2.34/24 brd 192.168.2.255 scope global dynamic eth0
? ? ? ?valid_lft 80590sec preferred_lft 80590sec
? ? inet6 fe80::f816:3eff:fe08:8897/64 scope link?
? ? ? ?valid_lft forever preferred_lft forever
設定

[root@ecs-5c78-0002 ~]# export http_proxy="test:qq..123@192.168.2.181:3128"

#export http_proxy="代理使用者名稱:密碼@Proxy 伺服器IP:連接埠"

注:停止使用代理的時候,要把改過的檔案改成原樣.尤其是如果使用了export http_proxy=""代理使用者名稱:密碼@Proxy 伺服器IP:連接埠"命令,
要在命令列輸入: unset http_proxy ,去除環境變數.
因為export http_proxy=""代理使用者名稱:密碼@Proxy 伺服器IP:連接埠"這條命令的實質是把export後面的設定寫進環境設定檔案中
刪除之後就異常
至此完成!

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.