有时候内网很多机器都不能上外网,只能开放几个特定ip访问外网, 那么可以在这个可以上外网的机器上面搭建代理服务器,其他机器配置好代理就能上网了。
不管是测试用途还是自己使用,squid都是一个很不错的代理工具。支持正向代理、反向代理、还有透明代理。 本篇演示搭建了一个简单的squid的正向代理,同时支持认证,随便记记笔记。
1 yum install squid -y
2 yum install httpd-tools -y
mkdir /etc/squid3/
htpasswd -cd /etc/squid3/passwords mybai
##提示输入密码,在这里我输入是123456,注意密码不要超过8位
下面是我的配置实例:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# Example rule allowing access from your local networks.
# Adapt to list your (internal) IP networks from where browsing
# should be allowed
acl all
src all
# RFC1918 possible internal network 全部开放
acl localnet src 10.0.0.0/8 # RFC1918 possible internal network
acl localnet src 172.16.0.0/12 # RFC1918 possible internal network
acl localnet src 192.168.0.0/16 # RFC1918 possible internal network
acl localnet src fc00::/7 # RFC 4193 local private network range
acl localnet src fe80::/10 # RFC 4291 link-local (directly plugged) machines
acl SSL_ports port 443
acl Safe_ports port 80 # http
acl Safe_ports port 21 # ftp
acl Safe_ports port 443 # https
acl Safe_ports port 70 # gopher
acl Safe_ports port 210 # wais
acl Safe_ports port 1025-65535 # unregistered ports
acl Safe_ports port 280 # http-mgmt
acl Safe_ports port 488 # gss-http
acl Safe_ports port 591 # filemaker
acl Safe_ports port 777 # multiling http
acl CONNECT method CONNECT
#
# Recommended minimum Access Permission configuration:
#
# Deny requests to certain unsafe ports
http_access deny !Safe_ports
# Deny CONNECT to other than secure SSL ports
http_access deny CONNECT !SSL_ports
# Only allow cachemgr access from localhost
http_access allow localhost manager
http_access deny manager
# We strongly recommend the following be uncommented to protect innocent
# web applications running on the proxy server who think the only
# one who can access services on "localhost" is a local user
#http_access deny to_localhost
#
# INSERT YOUR OWN RULE(S) HERE TO ALLOW ACCESS FROM YOUR CLIENTS
#
# Example rule allowing access from your local networks.
# Adapt localnet in the ACL section to list your (internal) IP networks
# from where browsing should be allowed
http_access allow localnet
http_access allow localhost
# And finally deny all other access to this proxy
http_access deny all
|
squid的日志默认是打开的,位于目录/var/log/squid/
,当然这个地址还有日志的格式都是可以完全自定义的
1
2
3
4
5
6
7
8
|
[root@controller161 ~]# ll /var/log/squid/
total 496
-rw-r----- 1 squid squid 355208 May 6 12:17 access.log
-rw-r----- 1 squid squid 1846 Jul 10 2016 access.log-20160710.gz
-rw-r----- 1 squid squid 3710 Jul 15 2016 access.log-20160718.gz
-rw-r----- 1 squid squid 125341 May 4 15:19 cache.log
-rw-r----- 1 squid squid 1325 Jul 9 2016 cache.log-20160710.gz
-rw-r----- 1 squid squid 1110 Jul 14 2016 cache.log-20160718.gz
|
1
2
3
4
5
6
7
8
|
# 开启启动
systemctl
enable squid.service
# 启动
systemctl start squid.service
# 停止
systemctl stop squid.service
# 重启
systemctl restart squid.service
|
在其他CentOS机器上面配置各种代理方法
vim /etc/profile
,在最后加入
1
2
|
export http_proxy=
"http://username:password@proxy_ip:port"
export https_proxy=
"http://username:password@proxy_ip:port"
|
编辑/etc/yum.conf
,在最后加入
1
2
|
# Proxy
proxy=http://username:password@proxy_ip:port/
|
编辑/etc/wgetrc
,在最后加入
1
2
3
4
|
# Proxy
http_proxy=http://username:password@proxy_ip:port/
https_proxy=http://username:password@proxy_ip:port/
ftp_proxy=http://username:password@proxy_ip:port/
|
在~/.bashrc
里面增加一个别名:
1
|
alias curl=
"curl -x http://username:password@proxy_ip:port"
|
另外一种方法是编辑~/.curlrc
文件 (没有就创建一个):
1
|
proxy = http://username:password@proxy_ip:port
|