所以今天我决定将我的 ts3 服务器从我的旧 Windows 盒子移动到新的 centos8 服务器。一切正常,但现在我正在尝试创建一个 systemd 服务文件,以便服务器可以在启动时自动启动。当我尝试以服务用户身份启动时,我可以很好地运行所有内容,但我无法以 root 身份启动它(使用 systemctl)。更多信息:
我想要与之一起运行的用户
[root@lnxsrv01 opt]# id teamspeak
uid=1000(teamspeak) gid=1000(teamspeak) groups=1000(teamspeak)
我的文件夹结构(注意权限和执行标志)
[root@lnxsrv01 teamspeak]# ll
total 16380
drwxr-xr-x. 9 teamspeak teamspeak 4096 Nov 2 17:28 .
drwxr-xr-x. 3 root root 23 Nov 2 16:11 ..
-rw-------. 1 teamspeak teamspeak 629 Nov 2 17:30 .bash_history
-rw-rw-rw-. 1 teamspeak teamspeak 66724 Jul 2 11:21 CHANGELOG
drwxr-xr-x. 3 teamspeak teamspeak 192 Jun 17 18:27 doc
drwx------. 4 teamspeak teamspeak 45 Nov 2 16:59 files
-rwxr-xr-x. 1 teamspeak teamspeak 947368 Jul 2 15:24 libts3db_mariadb.so
-rwxr-xr-x. 1 teamspeak teamspeak 2174344 Jul 2 15:24 libts3db_sqlite3.so
-rwxr-xr-x. 1 teamspeak teamspeak 1096144 Jul 2 15:24 libts3_ssh.so
-rw-r--r--. 1 teamspeak teamspeak 68141 Jun 17 18:27 LICENSE
drwx------. 2 teamspeak teamspeak 270 Nov 2 17:10 logs
-rw-rw-rw-. 1 teamspeak teamspeak 0 Nov 2 16:59 query_ip_blacklist.txt
-rw-rw-rw-. 1 teamspeak teamspeak 14 Nov 2 16:59 query_ip_whitelist.txt
drwxr-xr-x. 2 teamspeak teamspeak 29 Jul 2 15:24 redist
drwxrwxrwx. 2 teamspeak teamspeak 8192 Jun 24 11:28 serverquerydocs
drwxrwxrwx. 5 teamspeak teamspeak 8192 Jun 17 18:26 sql
-rw-rw-rw-. 1 teamspeak teamspeak 3243 Nov 2 16:59 ssh_host_rsa_key
-rwxr-xr-x. 1 teamspeak teamspeak 12033888 Jul 2 15:24 ts3server
-rw-rw-r--. 1 teamspeak teamspeak 0 Nov 2 16:59 .ts3server_license_accepted
-rwxrwxrwx. 1 teamspeak teamspeak 117 Jun 17 18:26 ts3server_minimal_runscript.sh
-rw-rw-r--. 1 teamspeak teamspeak 6 Nov 2 17:10 ts3server.pid
-rw-r--r--. 1 teamspeak teamspeak 282624 Nov 2 16:58 ts3server.sqlitedb
-rw-r--r--. 1 teamspeak teamspeak 32768 Nov 2 17:22 ts3server.sqlitedb-shm
-rw-r--r--. 1 teamspeak teamspeak 6320 Nov 2 17:21 ts3server.sqlitedb-wal
-rwxrwxrwx. 1 teamspeak teamspeak 2654 Jun 18 11:51 ts3server_startscript.sh
drwxr-xr-x. 2 teamspeak teamspeak 85 Jul 2 15:24 tsdns
[root@lnxsrv01 teamspeak]# pwd
/opt/teamspeak
我的systemd服务文件
[root@lnxsrv01 teamspeak]# cat /lib/systemd/system/teamspeak3.service
[Unit]
Description=TeamSpeak Server Service
After=network.target
[Service]
Type=forking
WorkingDirectory=/opt/teamspeak/
ExecStart=/opt/teamspeak/ts3server_startscript.sh start
ExecStop=/opt/teamspeak/ts3server_startscript.sh stop
User=teamspeak
Group=teamspeak
PIDFile=/opt/teamspeak/ts3server.pid
Restart=always
RestartSec=9
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=teamspeak3
[Install]
WantedBy=multi-user.target
相关系统日志条目
Nov 2 17:26:36 lnxsrv01 systemd[17585]: teamspeak3.service: Failed to execute command: Permission denied
Nov 2 17:26:36 lnxsrv01 systemd[17585]: teamspeak3.service: Failed at step EXEC spawning /opt/teamspeak/ts3server_startscript.sh: Permission denied
Nov 2 17:26:36 lnxsrv01 systemd[1]: teamspeak3.service: Control process exited, code=exited status=203
Nov 2 17:26:36 lnxsrv01 systemd[1]: teamspeak3.service: Failed with result 'exit-code'.
Nov 2 17:26:36 lnxsrv01 systemd[1]: Failed to start TeamSpeak Server Service.
Nov 2 17:26:43 lnxsrv01 systemd[1]: Stopped TeamSpeak Server Service.
当我su到“teamspeak”用户并从那里运行startscript时,一切正常。但我似乎无法让 systemd 工作。
我在这里缺少什么想法吗?
答案1
如果问题可以通过关闭 SELinux 来解决,那么深入挖掘并找出原因是值得的。
(您不会关闭防火墙来打开端口 80,对吗?)
在这种特殊情况下,为了通过 systemd 单元文件调用二进制文件或脚本,它需要是 SELinux 类型bin_t
(/usr/bin
与/usr/sbin
通常的文件一样)。
要查明文件的类型,请使用ls
's-Z
标志。然后相应地设置类型:
chcon -t bin_t /opt/teamspeak/ts3server_startscript.sh
要找出哪些操作被 SELinux 阻止(以及原因),请查看 中的审核日志/var/log/audit/audit.log
。
然而,通常情况下,更改文件的 SELinux 类型是不够的:
答案2
我的雷达上没有 SElinux...关闭它解决了这个问题。