Study with me in linux 10

Source: Internet
Author: User
Learn linux with me 10-Linux Enterprise Application-Linux server application information. The following is a detailed description. We will discuss the linux Proxy Server squid today.
1. Check whether squid is installed.
[Root @ zy root] # rpm-qa | grep squid
If not installed, go here to download the latest version for installation http://www.squid-cache.org/Versions/v2/2.6/
2. Because the downloaded directory is under the/home/jishu directory
[Root @ zy jishu] # tar zxvf squid-2.6.STABLE14.tar
Then a directory squid-2.6.STABLE4 will be generated
[Root @ zy jishu] # cd squid-2.6.STABLE4
[Root @ zy squid-2.6.STABLE4] #./configure -- prefix =/var/squid specifies the installation directory as/var/squid, Which is/usr/local/squid by default.
[Root @ zy squid-2.6.STABLE4] #./configure -- enable-linux-netfilter allows the use of Linux transparent proxy
[Root @ zy squid-2.6.STABLE4] #./configure -- enable-storeio = ufs, null
The file system used is usually the default ufs, but if you want to create a proxy server that does not cache any files, you need to add a null file system.
[Root @ zy squid-2.6.STABLE4] #./configure -- enable-arp-acl
In this way, you can manage the MAC address of the client directly in Rule settings to prevent IP spoofing.
[Root @ zy squid-2.6.STABLE4] #./configure -- enable-err-extensions ages = "Simplify_Chinese"
[Root @ zy squid-2.6.STABLE4] #./configure -- enable-default-err-extensions ages = "Simplify_Chinese"
The above two options tell Squid to compile and use the simplified Chinese error message.
[Root @ zy squid-2.6.STABLE4] #./configure -- enable-underscore
An underscore is allowed in the URL to be parsed. By default, Squid considers the URL with an underscore illegal and rejects access to the address.
3. [root @ zy squid-2.6.STABLE4] # make
[Root @ zy squid-2.6.STABLE4] # make install
4. [root @ zy squid-2.6.STABLE4] # cd/var/squid/
[Root @ zy squid] # ls
[Root @ zy squid] # vi/etc/squid. conf modify the master configuration file of squid
[1] http_port 192.168.1.144: 3128 the default port is 3128. Of course, it can also be any other port, as long as it does not conflict with other services. For the sake of security, adding an IP address in front of Squid will not listen to external network interfaces. The IP address of the internal network interface eth0 is 192.168.1.144, And the IP address of the external network interface eth1 is 202.96.xx.xx.
[2] cache_mgr zy_66289214@126.com Server Manager email, when an error occurs, the address will be displayed on the error page, easy to contact the user
[3] cache_dir ufs/var/squid/var/cache 3500 16 43
Cache_mem 64 MB
Cache_swap_low 90
Cache_swap_high 95
Here, Squid uses the/var/squid/var/cache directory as the directory for storing cache data. The cache size for each processing is 64 mb. When the cache space reaches 95%, the new content will replace the old one instead of being directly added to the directory until the space drops to 90% again. If you do not want Squid to cache any files, such as some vpcs with limited storage space, you can use a null File System (which does not require those cache policies cache_dir null/tmp
[4] access_log/var/squid/var/logs/access. log squid cache_access_log
Description: Specifies the full path (including the file name and directory) of the log recorded by the customer request. The request can be an HTTP request from a common user or an ICP request from a neighbor. If you do not need this log, use the following statement to cancel: cache_access_log none
Cache_log/var/squid/var/logs/cache. log
Cache_log
Description: Specify the complete path of the squid General Information log (including the file name and directory ).
Cache_store_log/var/squid/var/logs/store. log cache_store_log
Description: Specifies the full path of OSS logs (including the file name and directory ). This record indicates which objects are written to the swap space and which objects are cleared from the swap space. If you do not need this log, use the following statement to cancel: cache_store_log none
[5] dns_nameservers 202.96.209.134
Defines the Domain Name Server used by Squid for domain name resolution
[6]
Set squid transparent proxy
Two options are used to define the squid acceleration mode. Use virtual to specify the virtual host mode. Port 80 is the request port to be accelerated.
Httpd_accel_host virtual
Httpd_accel_port 80
In transparent proxy mode, it must be set to on. In this mode, Squid is both the accelerator of web requests and the cache proxy server.
Httpd_accel_with_proxy on
Httpd_accel_uses_host_header on
When setting transparent proxy, you must enable the packet forwarding function
[Root @ zy root] # echo "1">/proc/sys/net/ipv4/ip_forward
In addition, to save this value, we need to open
[Root @ zy root] # vi/etc/sysctl. conf
Net. ipv4.ip _ forward = 1
Wq
In Linux, you can use iptables/ipchains to directly forward requests to Web port 80 to Squid port 3128, which is claimed by Squid, the user's browser still thinks it accesses port 80 of the other party. For example, the following command:
Iptables-t nat-a prerouting-s 192.168.1.0/24-p tcp -- dport 80-j REDIRECT 3128
That is, all access requests to port 80 in the group 192.168.1.0 are redirected to port 3128.
[7] setting simple access control rules
Acl meinv 192.168.1.2-192.168.1.200/32
Http_access allow meinv
Http_access deny all
These three commands mean that the IP address range 192.168.1.0 can access the proxy server. The rule name is meinv and other IP address segments are denied.
Then there are some detailed configuration rules
Acl 1 src 192.168.1.10 192.168.1.20 192.168.1.30
Http_access allow 1
Http_access deny! 1
This rule only allows machines with IP addresses 192.168.1.10, 192.168.1.20, and 192.168.1.30
Access to the Internet is denied on machines with other IP addresses.
2. restrict the access period.
Acl 1 src 192.168.1.10
Acl 2 time MTWHF-
Http_access allow 1 2
Http_access deny! 1
This rule allows the subnet 192.168.1.10 to access the Internet from AM to Am from Monday to Friday.
3. assign different access periods to different clients.
Acl 11 192.168.1.10
Acl 12 192.168.1.20
Acl 13 192.168.1.30
Acl morning time-
Acl lunch time-
Acl evening time-
Http_access allow 11 morning
Http_access allow 11 evening
Http_access allow 12 lunch
Http_access allow 13 evening
Http_access deny all
In this rule, host 11 can access the Internet during the morning and evening periods. Host 12 and host 13 can only access the Internet during the lunch and evening periods, respectively.
Squid can block certain sites or sites that contain certain words. You can use the following rules:
Acl 14 192.168.1.17
Acl 15 banned_sites www.sina.com
Http_access deny 15
Http_access allow 14
It can also be used to shield websites that contain certain words (such as fuck ).
  
Acl 14 192.168.1.17
Acl 16 url_regex fuck
Http_access deny 16
Http_access allow 14
In practical applications, you do not need to list all websites or words to be blocked. You can first store them in a file (see the banned in the/etc directory. list file) ACL will read the required information from this file to shield prohibited sites.
Acl 14 192.168.1.17
Acl banned_sites url_regex "/etc/banned. list"
Http_access deny banned_sites
Http_access allow 14
Wq
I will not talk about the verification. Haha, here is just a small test for everyone to learn.
[Root @ zy root] # service squid restart
Then go to your windows Server and set it as a proxy link. Then you can test the webpage. you can experiment with www.sina.com, but other websites can.
After two days of study, I hope you can support me.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.