28.9. 配置/etc/logrotate.d/squid文件

配置你的/etc/logrotate.d/squid文件以每周自动轮转你的日志文件。创建squid文件,touch/etc/logrotate.d/squid并添加

               /var/log/squid/access.log {
               weekly
               rotate 5
               copytruncate
               compress
               notifempty
               missingok
               }
               /var/log/squid/cache.log {
               weekly
               rotate 5
               copytruncate
               compress
               notifempty
               missingok
               }

               /var/log/squid/store.log {
               weekly
               rotate 5
               copytruncate
               compress
               notifempty
               missingok
               # This script asks squid to rotate its logs on its own.
               # Restarting squid is a long process and it is not worth
               # doing it just to rotate logs
               postrotate
               /usr/sbin/squid -k rotate
               endscript
               }
             

28.9.1. 保护和免疫 Squid

通过更好地控制 Squid 缓存目录的挂载,如果你已经在 Linux 系统的独立分区中创建了 Squid 的缓存目录 /cache,就像我们在安装设置期间所做的那样,那么你可以使用noexec, nodev,以及nosuid功能来改进和加强缓存安全性。这些功能可以在/etc/fstab文件中设置,以告知系统不允许执行任何二进制文件;noexec不解释字符或块特殊设备;nodev并且不允许 set-user-identifier 或 set-group-identifier 位生效,nosuid在挂载的文件系统上/cache 在我们的例子中。在 Squid 缓存所在的分区上应用此过程将有助于消除DEV, SUID/SGID,以及任何二进制文件的执行。

举个例子,假设/dev/sda8是系统中/cacheSquid 目录所在的分区,你必须编辑 fstab 文件,vi/etc/fstab并更改与/dev/sda8
                   /dev/sda8			/cache		ext2		defaults        1 2
                 
读取相关的行
                   /dev/sda8			/cache 		ext2		noexec,nodev,nosuid 1 2
                 
不要忘记重启你的系统以使更改生效。

你应该免疫重要的配置文件,例如squid.conf。正如我们已经知道的,immutable 位可以用来防止删除、覆盖或创建文件的符号链接。一旦你的squid.conf文件配置完成,最好使用以下命令对其进行免疫
                 [root@deep /]# chattr +i /etc/squid/squid.conf