squid3 的权限问题

squid3 的权限问题

我一直在尝试让 squid 工作。我有一个在目录中创建缓存的配置/var/cache/squid3/。但是,当我使用“-z”标签运行 squid 时(这是第一次运行),我收到此错误:

WARNING: Cannot write log file: /var/log/squid3/cache.log
/var/log/squid3/cache.log: Permission denied
 messages will be sent to 'stderr'.
2015/05/23 20:05:39 kid1| Creating missing swap directories
2015/05/23 20:05:39 kid1| /var/cache/squid3 exists
FATAL: Failed to make swap directory /var/cache/squid3/00: (13)
Permission denied
Squid Cache (Version 3.3.8): Terminated abnormally.
CPU Usage: 0.010 seconds = 0.007 user + 0.003 sys
Maximum Resident Size: 22560 KB
Page faults with physical i/o: 0

我尝试通过输入来解决这个问题sudo chmod 755 /var/cache/squid3,但是也没有成功。

的输出namei -l /var/cache/squid3为:

$ namei -l /var/cache/squid3
f: /var/cache/squid3
drwxr-xr-x root root /
drwxr-xr-x root root var
drwxr-xr-x root root cache
drwxr-xr-x root root squid3

更新:/squid3_log我在和 中创建了新目录/squid3_cache。然后我为这两个目录发布了:

sudo chown -R root:proxy /squid3_log #and squid3_cache

sudo chmod -R 777 /squid3_log #and squid3_cache

它修复了 squid3_cache 拒绝的权限问题,但没有修复 squid3_log 拒绝的权限问题。

更新: 我尝试清除、重新安装、重新配置,第一次运行squid3 -z时一切正常。但当我运行调试时squid3 -NCd1,它显示:

2015/06/01 16:24:24| Starting Squid Cache version 3.3.8 for x86_64-pc-linux-gnu...
2015/06/01 16:24:24| Process ID 20379
2015/06/01 16:24:24| Process Roles: master worker
2015/06/01 16:24:24| With 65536 file descriptors available
2015/06/01 16:24:24| Initializing IP Cache...
2015/06/01 16:24:24| DNS Socket created at [::], FD 5
2015/06/01 16:24:24| DNS Socket created at 0.0.0.0, FD 6
2015/06/01 16:24:24| Adding nameserver 127.0.1.1 from /etc/resolv.conf
2015/06/01 16:24:24| Adding domain Home from /etc/resolv.conf
2015/06/01 16:24:24| Logfile: opening log /home/john/squid3_log/access.log
2015/06/01 16:24:24| WARNING: log parameters now start with a module name. Use 'stdio:/home/john/squid3_log/access.log'
2015/06/01 16:24:24| WARNING: no_suid: setuid(0): (1) Operation not permitted
2015/06/01 16:24:25| Unlinkd pipe opened on FD 11
2015/06/01 16:24:25| Local cache digest enabled; rebuild/rewrite every 3600/3600 sec
2015/06/01 16:24:25| Logfile: opening log /home/john/squid3_log/store.log
2015/06/01 16:24:25| WARNING: log parameters now start with a module name. Use 'stdio:/home/john/squid3_log/store.log'
2015/06/01 16:24:25| Swap maxSize 15360000 + 16384 KB, estimated 1182798 objects
2015/06/01 16:24:25| Target number of buckets: 59139
2015/06/01 16:24:25| Using 65536 Store buckets
2015/06/01 16:24:25| Max Mem  size: 16384 KB
2015/06/01 16:24:25| Max Swap size: 15360000 KB
2015/06/01 16:24:25| Rebuilding storage in /home/john/squid3_cache (no log)
2015/06/01 16:24:25| Using Least Load store dir selection
2015/06/01 16:24:25| Current Directory is /home/john
2015/06/01 16:24:25| Loaded Icons.
2015/06/01 16:24:25| HTCP Disabled.
2015/06/01 16:24:25| Sending SNMP messages from [::]:3129
2015/06/01 16:24:25| WARNING: no_suid: setuid(0): (1) Operation not permitted
2015/06/01 16:24:25| Pinger socket opened on FD 17
2015/06/01 16:24:25| /var/run/squid3.pid: (13) Permission denied
2015/06/01 16:24:25| Closing HTTP port [::]:3128
FATAL: Could not write pid file
Aborted (core dumped)

我正在使用 Ubuntu 14.04 LTS (Trusty Tahr) 和最新版本的 Squid3

答案1

squid3以用户身份运行proxy,因此您将所有者用户(和组)设置为proxy,然后相应地设置权限。

您可以执行以下操作以递归方式将所有文件的所有者和所有者组分别更改/var/cache/squid3为用户proxy和组proxy

sudo chown -R proxy:proxy /var/cache/squid3 

还要确保所有者具有正确的权限,即您当前拥有的权限就0755可以了。

在您的情况下,正如您所看到的,该目录/var/cache/squid3只有可写root,因此您收到权限被拒绝错误。

答案2

就我的情况(Ubuntu 16.04,Squid 3.5.12)而言,问题出在标准 AppArmor 规则和非标准缓存目录中,请查看/var/log/syslog

Sep 26 23:08:34 server2 kernel: [ 6458.643201] audit: type=1400 audit(1506449314.016:36): apparmor="DENIED" operation="mkdir" profile="/usr/sbin/squid" name="/BIG/squid_spool/00/00/" pid=4377 comm="squid" requested_mask="c" denied_mask="c" fsuid=13 ouid=13

在这种情况下,符号链接也不起作用。

可能的解决方案:

  • 将选项更改cache_dir为标准/var/spool/squid并且不在此路径中使用符号链接;
  • 更改文件/etc/apparmor.d/usr.sbin.squid并重新加载 apparmor:

    sudo apparmor_parser -r /etc/apparmor.d/usr.sbin.squid
    

    但您在更新时可能会遇到一些小问题。

  • 为 Squid 缓存挂载单独的分区。

答案3

将安装目录的所有者更改为代理 sudo chown proxy:proxy /usr/local/squid -R 并在 squid.conf 中设置代理用户

vi /usr/local/squid/etc/squid.conf cache_effective_user 代理

然后重新启动 squid,您的权限被拒绝问题就消失了,并且警告:无法写入日志文件也解决了。

我已经在我的系统上的 ubuntu 14.x 中测试过,然后在这里评论

相关内容