centos 6.x install squid

Keywords: firewall iptables yum CentOS

Do not set user authentication

install

# install
yum install squid
yum install httpd
#View version
rpm -qa | grep squid
#Here is the version I installed
#squid-3.1.23-24.el6.i686

Modify profile

  • Use vim to edit the / etc/squid/squid.conf file. As shown below
#/etc/squid/squid.conf

# The configuration file already has these two options. Replace them
http_port 3912
http_access allow all
# The configuration file does not have the following options and needs to be added
cache_mem 64 MB
maximum_object_size 4 MB
cache_dir ufs /var/spool/squid 100 16 256
access_log /var/log/squid/access.log

visible_hostname squid.xuezhisd

Initialization

# Create swap directories
squid -z

start-up

# centos 6
service squid start
# centos 7
systemctl start squid

Local use

  • linux system can set environment variables.
export http_proxy=http://ip:3912
export https_proxy=http://ip:3912
#export http_proxy=http://198.21.192.182:3912
  • test
# Execute the following test command locally
curl http://baidu.com
# Server view log
cat /var/log/squid/access.log
#Server log: 1522999771.638 11 42.62.85.10 TCP? Hit / 200 511 get http://baidu.com/ - none / - text / HTML
#Test successful!!!

Turn off the firewall [optional]

Mode 1: turn off the firewall
/etc/init.d/iptables stop
 #Mode 2: open port access
iptables -A INPUT -p tcp --dport 8888 -j ACCEPT
 #Restart firewall
/etc/init.d/iptables restart

Self starting

chkconfig --level 35 squid on  

Add user authentication

Add user

  • ncsa authentication module is used to add authentication for our squid.

  • Configure users and passwords. Note: xuezhisd is replaced with its own username.

htpasswd -c /etc/squid/passwd xuezhisd

Modify profile

http_port 3912
cache_mem 64 MB
maximum_object_size 4 MB
cache_dir ufs /var/spool/squid 100 16 256
access_log /var/log/squid/access.log
#http_access allow all # replace
http_access deny all
visible_hostname squid.xuezhisd

# 32bit system
auth_param basic program /usr/lib/squid/ncsa_auth /etc/squid/passwd
# 64bit system
auth_param basic program /usr/lib64/squid/basic_ncsa_auth /etc/squid/passwd
auth_param basic children 5
auth_param basic realm xuezhisd's squid server
auth_param basic credentialsttl 2 hours
acl myacl proxy_auth REQUIRED
http_access allow myacl

Modify environment variables locally

  • linux system can set environment variables.
export http_proxy=http://username:passwd@ip:3912
export https_proxy=http://username:passwd@ip:3912
#export http_proxy=http://xuezhisd:xuezhisd@198.21.192.182:3912

Retest

# Execute the following test command locally
curl http://baidu.com
# Server view log
cat /var/log/squid/access.log
#Server log: 1522999771.638 11 42.62.85.10 TCP? Hit / 200 511 get http://baidu.com/ - none / - text / HTML
#Test successful!!!

Posted by cheald on Sat, 04 Apr 2020 06:04:43 -0700