我想在无头 CentOS 7 服务器上运行 Pulseaudio 系统。如果我 startx 但在文本模式(相当于运行级别 3)下脉冲音频客户端失败,则 Pulseaudio 工作得很好。
所以我创建了一个systemd服务文件:
[Unit]
Description=PulseAudio Daemon
[Install]
WantedBy=multi-user.target
[Service]
Type=simple
PrivateTmp=true
ExecStart=/usr/bin/pulseaudio --system --realtime --disallow-exit --no-cpu-limit
它启动了,但我在journalctl中看到以下内容:
Jan 19 13:31:47 lserver.mydomain pulseaudio[2523]: W: [pulseaudio] main.c: Running in system mode, but --disallow-module-loading not set!
Jan 19 13:31:47 lserver.mydomain pulseaudio[2523]: N: [pulseaudio] main.c: Running in system mode, forcibly disabling SHM mode!
Jan 19 13:31:47 lserver.mydomain pulseaudio[2523]: N: [pulseaudio] main.c: Running in system mode, forcibly disabling exit idle time!
Jan 19 13:31:47 lserver.mydomain pulseaudio[2523]: W: [pulseaudio] main.c: OK, so you are running PA in system mode. Please note that you most likely shouldn't be doing that.
Jan 19 13:31:47 lserver.mydomain pulseaudio[2523]: W: [pulseaudio] main.c: If you do it nonetheless then it's your own fault if things don't work as expected.
Jan 19 13:31:47 lserver.mydomain pulseaudio[2523]: W: [pulseaudio] main.c: Please read http://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/User/WhatIsWrongWithSystemWide/ for an explanation why system mode is usually a bad idea.
Jan 19 13:31:48 lserver.mydomain pulseaudio[2523]: N: [pulseaudio] alsa-util.c: Disabling timer-based scheduling because running inside a VM.
Jan 19 13:31:48 lserver.mydomain pulseaudio[2523]: N: [pulseaudio] alsa-util.c: Disabling timer-based scheduling because running inside a VM.
Jan 19 13:31:48 lserver.mydomain pulseaudio[2523]: W: [pulseaudio] authkey.c: Failed to open cookie file '/var/run/pulse/.config/pulse/cookie': No such file or directory
Jan 19 13:31:48 lserver.mydomain pulseaudio[2523]: W: [pulseaudio] authkey.c: Failed to load authentication key '/var/run/pulse/.config/pulse/cookie': No such file or directory
Jan 19 13:31:48 lserver.mydomain pulseaudio[2523]: W: [pulseaudio] authkey.c: Failed to open cookie file '/var/run/pulse/.pulse-cookie': No such file or directory
Jan 19 13:31:48 lserver.mydomain pulseaudio[2523]: W: [pulseaudio] authkey.c: Failed to load authentication key '/var/run/pulse/.pulse-cookie': No such file or directory
Jan 19 13:31:48 lserver.mydomain systemd[1]: Got message type=signal sender=org.freedesktop.DBus destination=n/a object=/org/freedesktop/DBus interface=org.freedesktop.DBus member=NameOwnerChanged cookie=56 reply_cookie=0 error=n/a
Jan 19 13:31:48 lserver.mydomain systemd-logind[575]: Got message type=signal sender=org.freedesktop.DBus destination=n/a object=/org/freedesktop/DBus interface=org.freedesktop.DBus member=NameOwnerChanged cookie=56 reply_cookie=0 error=n/a
Jan 19 13:31:48 lserver.mydomain systemd-logind[575]: Got message type=signal sender=org.freedesktop.DBus destination=n/a object=/org/freedesktop/DBus interface=org.freedesktop.DBus member=NameOwnerChanged cookie=57 reply_cookie=0 error=n/a
Jan 19 13:31:48 lserver.mydomain systemd[1]: Got message type=signal sender=org.freedesktop.DBus destination=n/a object=/org/freedesktop/DBus interface=org.freedesktop.DBus member=NameOwnerChanged cookie=57 reply_cookie=0 error=n/a
并尝试访问音频失败:
speaker-test 1.1.1
Playback device is default
Stream parameters are 48000Hz, S16_LE, 1 channels
Using 16 octaves of pink noise
ALSA lib pulse.c:243:(pulse_connect) PulseAudio: Unable to connect: Access denied
Playback open error: -111,Connection refused
扬声器测试后日志显示:
Jan 19 14:06:39 lserver.ocg.ca pulseaudio[2795]: W: [pulseaudio] protocol-native.c: Denied access to client with invalid authentication data.
用户 root 已添加到“音频”组。扬声器测试正在以 root 身份运行。有人可以建议如何解决这个问题吗?
答案1
经过一些实验,我发现修改 /etc/pulse/system.pa 以允许匿名:
load-module module-native-protocol-unix auth-anonymous=1
现在音频播放正常。希望这可以帮助其他需要系统模式脉冲的人
答案2
您的输出中包含有关以系统用户身份运行 PulseAudio 的反馈:
请阅读http://www.freedesktop.org/wiki/Software/PulseAudio/Documentation/User/WhatIsWrongWithSystemWide/解释为什么系统模式通常是一个坏主意。
另一种方法是以您登录的用户身份运行 PulseAudio。如何做到这一点是一个问题已经得到答复。