Ubuntu

systemd redis.service 不允許 unix 套接字連接?

  • April 27, 2017

我已經在 ubuntu 16.04 上安裝了 redis-server,我正在嘗試通過 unix 套接字連接到它。我已經註釋掉了redis.conf中的bindand指令並取消了指令的註釋,所以我有:port``unixsocket

# Accept connections on the specified port, default is 6379.
# If port 0 is specified Redis will not listen on a TCP socket.
# port 6379

# TCP listen() backlog.
#
# In high requests-per-second environments you need an high backlog in order
# to avoid slow clients connections issues. Note that the Linux kernel
# will silently truncate it to the value of /proc/sys/net/core/somaxconn so
# make sure to raise both the value of somaxconn and tcp_max_syn_backlog
# in order to get the desired effect.
tcp-backlog 511

# By default Redis listens for connections from all the network interfaces
# available on the server. It is possible to listen to just one or multiple
# interfaces using the "bind" configuration directive, followed by one or
# more IP addresses.
#
# Examples:
#
# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1

# Specify the path for the Unix socket that will be used to listen for
# incoming connections. There is no default, so Redis will not listen
# on a unix socket when not specified.
#
unixsocket /var/run/redis/redis.sock
unixsocketperm 770

我已將本地使用者添加到 redis 組,並重新啟動了 redis 服務,sudo systemctl restart redis.serivce因此/var/run/redis/文件夾如下所示:

drwxrwsr-x  2 redis redis   80 Apr 27 17:39 .
drwxr-xr-x 34 root  root  1160 Apr 27 16:40 ..
-rw-r--r--  1 redis redis    6 Apr 27 17:38 redis-server.pid
srwxrwx---  1 redis redis    0 Apr 27 17:38 redis.sock

我希望現在能夠使用

$ redis-cli -s /var/run/redis/redis.sock

但是我得到:

Could not connect to Redis at /var/run/redis/redis.sock: Permission denied
not connected> 

奇怪的執行給了我應該不受約束$ redis-cli的預設值?127.0.0.1:6379>

如果我看一下redis程序:

redis    18108  0.0  0.0  40136  6652 ?        Ssl  17:45   0:00 /usr/bin/redis-server *:6379

在我看來,它甚至沒有使用正確的 conf 文件並綁定到 *:6379。該/etc/systemd/system/redis.service文件有

ExecStart=/usr/bin/redis-server /etc/redis/redis.conf

所以我很困惑為什麼這不是正在執行的程序,或者為什麼權限不允許我連接。

將本地使用者添加到 redis 組後,您是否已註銷並重新登錄?您需要這樣做才能應用更改

引用自:https://serverfault.com/questions/846952