old-www/LDP/solrhe/Securing-Optimizing-Linux-R.../chap28sec233.html

398 lines
8.0 KiB
HTML

<HTML
><HEAD
><TITLE
>Configure the /etc/rc.d/init.d/squid script file -/all configurations</TITLE
><META
NAME="GENERATOR"
CONTENT="Modular DocBook HTML Stylesheet Version 1.60"><LINK
REL="HOME"
TITLE="Securing and Optimizing Linux"
HREF="index.html"><LINK
REL="UP"
TITLE="Software -Server/Proxy Network"
HREF="netproxy-squid.html"><LINK
REL="PREVIOUS"
TITLE="Configure of the /etc/squid/squid.conf file -/proxy-caching mode"
HREF="chap28sec232.html"><LINK
REL="NEXT"
TITLE="Configure the /etc/logrotate.d/squid file"
HREF="chap28sec234.html"></HEAD
><BODY
CLASS="section"
BGCOLOR="#FFFFFF"
TEXT="#000000"
LINK="#0000FF"
VLINK="#840084"
ALINK="#0000FF"
><DIV
CLASS="NAVHEADER"
><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TH
COLSPAN="3"
ALIGN="center"
>Securing and Optimizing Linux: RedHat Edition -A Hands on Guide</TH
></TR
><TR
><TD
WIDTH="10%"
ALIGN="left"
VALIGN="bottom"
><A
HREF="chap28sec232.html"
>Prev</A
></TD
><TD
WIDTH="80%"
ALIGN="center"
VALIGN="bottom"
>Chapter 28. Software -Server/Proxy Network</TD
><TD
WIDTH="10%"
ALIGN="right"
VALIGN="bottom"
><A
HREF="chap28sec234.html"
>Next</A
></TD
></TR
></TABLE
><HR
ALIGN="LEFT"
WIDTH="100%"></DIV
><DIV
CLASS="section"
><H1
CLASS="section"
><A
NAME="AEN18388"
>28.8. Configure the <TT
CLASS="filename"
>/etc/rc.d/init.d/squid</TT
> script file -/all configurations</A
></H1
><P
>&#13; Configure your <TT
CLASS="filename"
>/etc/rc.d/init.d/squid</TT
> script file to start and stop the Squid Internet Object Cache. This script has been modified to setup swap cache for Squid in <TT
CLASS="filename"
>/cache</TT
> instead
of <TT
CLASS="filename"
>/var/spool/squid</TT
>.
Create the <TT
CLASS="filename"
>squid</TT
> script file, <B
CLASS="command"
>touch</B
> <TT
CLASS="filename"
>/etc/rc.d/init.d/squid</TT
> and add:
</P
><TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="programlisting"
>&#13; #!/bin/bash
# squid This shell script takes care of starting and stopping
# Squid Internet Object Cache
#
# chkconfig: - 90 25
# description: Squid - Internet Object Cache. Internet object caching is \
# a way to store requested Internet objects (i.e., data available \
# via the <SPAN
CLASS="acronym"
>HTTP</SPAN
>, <SPAN
CLASS="acronym"
>FTP</SPAN
>, and gopher protocols) on a system closer to the \
# requesting site than to the source. Web browsers can then use the \
# local Squid cache as a proxy <SPAN
CLASS="acronym"
>HTTP</SPAN
> server, reducing access time as \
# well as bandwidth consumption.
# pidfile: /var/run/squid.pid
# config: /etc/squid/squid.conf
PATH=/usr/bin:/sbin:/bin:/usr/sbin
export PATH
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ <TT
CLASS="prompt"
>$</TT
>{NETWORKING} = "no" ] &#38;&#38; exit 0
# check if the squid conf file is present
[ -f /etc/squid/squid.conf ] || exit 0
# determine the name of the squid binary
[ -f /usr/sbin/squid ] &#38;&#38; SQUID=squid
[ -z "$SQUID" ] &#38;&#38; exit 0
# determine which one is the cache_swap directory
CACHE_SWAP=`sed -e 's/#.*//g' /etc/squid/squid.conf | \
grep cache_dir | sed -e 's/cache_dir//' | \
cut -d ' ' -f 2`
[ -z "$CACHE_SWAP" ] &#38;&#38; CACHE_SWAP=/cache
# default squid options
# -D disables initial dns checks. If you most likely will not to have an
# internet connection when you start squid, uncomment this
#SQUID_OPTS="-D"
RETVAL=0
case "$1" in
start)
echo -n "Starting $SQUID: "
for adir in $CACHE_SWAP; do
if [ ! -d $adir/00 ]; then
echo -n "init_cache_dir $adir... "
$SQUID -z -F 2&#62;/dev/null
fi
done
$SQUID $SQUID_OPTS &#38;
RETVAL=<TT
CLASS="prompt"
>$</TT
>?
echo $SQUID
[ $RETVAL -eq 0 ] &#38;&#38; touch /var/lock/subsys/$SQUID
;;
stop)
echo -n "Stopping $SQUID: "
$SQUID -k shutdown &#38;
RETVAL=<TT
CLASS="prompt"
>$</TT
>?
if [ $RETVAL -eq 0 ] ; then
rm -f /var/lock/subsys/$SQUID
while : ; do
[ -f /var/run/squid.pid ] || break
sleep 2 &#38;&#38; echo -n "."
done
echo "done"
else
echo
fi
;;
reload)
$SQUID $SQUID_OPTS -k reconfigure
exit <TT
CLASS="prompt"
>$</TT
>?
;;
restart)
$0 stop
$0 start
;;
status)
status $SQUID
$SQUID -k check
exit <TT
CLASS="prompt"
>$</TT
>?
;;
probe)
exit 0;
;;
*)
echo "Usage: $0 {start|stop|status|reload|restart}"
exit 1
esac
exit $RETVAL
</PRE
></TD
></TR
></TABLE
><P
>&#13; Now, make this script executable and change its default permissions:
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="screen"
>&#13; [root@deep /]# <B
CLASS="command"
>chmod</B
> 700 /etc/rc.d/init.d/squid
</PRE
></TD
></TR
></TABLE
>
Create the symbolic rc.d links for Squid with the command:
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="screen"
>&#13; [root@deep /]# <B
CLASS="command"
>chkconfig</B
> --add squid
</PRE
></TD
></TR
></TABLE
>
</P
><P
>&#13; By default the squid script will not automatically start the proxy server on Red Hat Linux when you reboot the server. You can change it's default by executing the following command:
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="screen"
>&#13; [root@deep /]# <B
CLASS="command"
>chkconfig</B
> --level 345 squid on
</PRE
></TD
></TR
></TABLE
>
Start your new Squid Proxy Server manually with the following command:
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="screen"
>&#13; [root@deep /]# /etc/rc.d/init.d/squid <B
CLASS="command"
>start</B
>
</PRE
></TD
></TR
></TABLE
>
<TABLE
BORDER="0"
BGCOLOR="#E0E0E0"
WIDTH="100%"
><TR
><TD
><PRE
CLASS="literallayout"
><TT
CLASS="computeroutput"
>&#13; Starting squid: init_cache_dir ufs... squid
</TT
></PRE
></TD
></TR
></TABLE
>
</P
></DIV
><DIV
CLASS="NAVFOOTER"
><HR
ALIGN="LEFT"
WIDTH="100%"><TABLE
WIDTH="100%"
BORDER="0"
CELLPADDING="0"
CELLSPACING="0"
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
><A
HREF="chap28sec232.html"
>Prev</A
></TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="index.html"
>Home</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
><A
HREF="chap28sec234.html"
>Next</A
></TD
></TR
><TR
><TD
WIDTH="33%"
ALIGN="left"
VALIGN="top"
>Configure of the <TT
CLASS="filename"
>/etc/squid/squid.conf</TT
> file -/proxy-caching mode</TD
><TD
WIDTH="34%"
ALIGN="center"
VALIGN="top"
><A
HREF="netproxy-squid.html"
>Up</A
></TD
><TD
WIDTH="33%"
ALIGN="right"
VALIGN="top"
>Configure the <TT
CLASS="filename"
>/etc/logrotate.d/squid</TT
> file</TD
></TR
></TABLE
></DIV
></BODY
></HTML
>