amazon-web-services - Ubuntu Aws 用户会话停止
问题描述
再会。
Aws 上有一个 Ubuntu 实例。它使用来自用户的 systemd 运行 api 服务。用户和相关服务的会话会定期停止。
Jun 25 15:31:49 systemd-networkd[581]: eth0: Configured
Jun 25 15:31:49 systemd-timesyncd[449]: Network configuration changed, trying to establish connection.
Jun 25 15:31:49 systemd-timesyncd[449]: Synchronized to time server 91.189.89.199:123 (ntp.ubuntu.com).
Jun 25 15:37:55 systemd[1]: Starting Cleanup of Temporary Directories...
Jun 25 15:37:55 systemd[1]: Started Cleanup of Temporary Directories.
Jun 25 15:54:07 snapd[29375]: storehelpers.go:438: cannot refresh snap "amazon-ssm-agent": snap has no updates available
Jun 25 15:54:12 systemd[1]: Reloading.
Jun 25 15:54:12 systemd[1]: Starting Daily apt download activities...
Jun 25 15:54:12 systemd[1]: Mounting Mount unit for core, revision 9436...
Jun 25 15:54:12 systemd[1]: Mounted Mount unit for core, revision 9436.
Jun 25 15:54:14 systemd[1]: Started Daily apt download activities.
Jun 25 15:54:14 kernel: [3718687.245500] audit: type=1400 audit(1593100454.191:59): apparmor="STATUS" operation="profile_load" profile="unconfined" name="/snap/core/9436/usr/lib/snapd/snap-confine" pid=4420 comm="apparmor_parser"
Jun 25 15:54:14 kernel: [3718687.245865] audit: type=1400 audit(1593100454.191:60): apparmor="STATUS" operation="profile_load" profile="unconfined" name="/snap/core/9436/usr/lib/snapd/snap-confine//mount-namespace-capture-helper" pid=4420 comm="apparmor_parser"
Jun 25 15:54:14 kernel: [3718687.380157] audit: type=1400 audit(1593100454.323:61): apparmor="STATUS" operation="profile_replace" profile="unconfined" name="snap.core.hook.configure" pid=4466 comm="apparmor_parser"
Jun 25 15:54:14 kernel: [3718687.387060] audit: type=1400 audit(1593100454.331:62): apparmor="STATUS" operation="profile_replace" info="same as current profile, skipping" profile="unconfined" name="snap-update-ns.core" pid=4469 comm="apparmor_parser"
Jun 25 15:54:14 snapd[29375]: daemon.go:542: gracefully waiting for running hooks
Jun 25 15:54:14 snapd[29375]: daemon.go:544: done waiting for running hooks
Jun 25 15:54:14 systemd[1]: snapd.service: Service hold-off time over, scheduling restart.
Jun 25 15:54:14 systemd[1]: snapd.service: Scheduled restart job, restart counter is at 4.
Jun 25 15:54:14 systemd[1]: Stopped Snappy daemon.
Jun 25 15:54:14 systemd[1]: Starting Snappy daemon...
Jun 25 15:54:15 snapd[4483]: AppArmor status: apparmor is enabled and all features are available
Jun 25 15:54:15 snapd[4483]: AppArmor status: apparmor is enabled and all features are available
Jun 25 15:54:15 snapd[4483]: patch.go:64: Patching system state level 6 to sublevel 1...
Jun 25 15:54:15 snapd[4483]: patch.go:64: Patching system state level 6 to sublevel 2...
Jun 25 15:54:15 snapd[4483]: patch.go:64: Patching system state level 6 to sublevel 3...
Jun 25 15:54:15 snapd[4483]: daemon.go:343: started snapd/2.45.1 (series 16; classic) ubuntu/18.04 (amd64) linux/4.15.0-1065-aws.
Jun 25 15:54:15 snapd[4483]: daemon.go:436: adjusting startup timeout by 40s (pessimistic estimate of 30s plus 5s per snap)
Jun 25 15:54:16 kernel: [3718689.181896] audit: type=1400 audit(1593100456.127:63): apparmor="STATUS" operation="profile_replace" profile="unconfined" name="/snap/core/9436/usr/lib/snapd/snap-confine" pid=4553 comm="apparmor_parser"
Jun 25 15:54:16 kernel: [3718689.182052] audit: type=1400 audit(1593100456.127:64): apparmor="STATUS" operation="profile_replace" profile="unconfined" name="/snap/core/9436/usr/lib/snapd/snap-confine//mount-namespace-capture-helper" pid=4553 comm="apparmor_parser"
Jun 25 15:54:16 kernel: [3718689.212835] audit: type=1400 audit(1593100456.159:65): apparmor="STATUS" operation="profile_replace" profile="unconfined" name="snap-update-ns.amazon-ssm-agent" pid=4555 comm="apparmor_parser"
Jun 25 15:54:16 kernel: [3718689.222505] audit: type=1400 audit(1593100456.167:66): apparmor="STATUS" operation="profile_replace" profile="unconfined" name="snap-update-ns.core" pid=4556 comm="apparmor_parser"
Jun 25 15:54:16 kernel: [3718689.300833] audit: type=1400 audit(1593100456.247:67): apparmor="STATUS" operation="profile_replace" profile="unconfined" name="snap.core.hook.configure" pid=4557 comm="apparmor_parser"
Jun 25 15:54:16 kernel: [3718689.305021] audit: type=1400 audit(1593100456.251:68): apparmor="STATUS" operation="profile_replace" info="same as current profile, skipping" profile="unconfined" name="snap.amazon-ssm-agent.amazon-ssm-agent" pid=4559 comm="apparmor_parser"
Jun 25 15:54:16 systemd[1]: Started Snappy daemon.
Jun 25 15:54:17 systemd[1]: Reloading.
Jun 25 15:54:18 snapd[4483]: storehelpers.go:438: cannot refresh snap "core": snap has no updates available
Jun 25 16:01:48 systemd-networkd[581]: eth0: Configured
Jun 25 16:01:48 systemd-timesyncd[449]: Network configuration changed, trying to establish connection.
Jun 25 16:01:48 systemd-timesyncd[449]: Synchronized to time server 91.189.89.199:123 (ntp.ubuntu.com).
Jun 25 16:12:11 systemd[1]: Stopping User Manager for UID 1000...
Jun 25 16:12:11 systemd[18795]: Stopped target Default.
Jun 25 16:12:11 systemd[18795]: Stopping API_SERVICE...
Jun 25 16:12:11 systemd[18795]: Stopped API_SERVICE.
Jun 25 16:12:11 systemd[18795]: Stopped target Basic System.
Jun 25 16:12:11 systemd[18795]: Stopped target Sockets.
Jun 25 16:12:11 systemd[18795]: Closed GnuPG cryptographic agent and passphrase cache.
Jun 25 16:12:11 systemd[18795]: Closed REST API socket for snapd user session agent.
Jun 25 16:12:11 systemd[18795]: Closed GnuPG cryptographic agent and passphrase cache (restricted).
Jun 25 16:12:11 systemd[18795]: Closed GnuPG cryptographic agent (ssh-agent emulation).
Jun 25 16:12:11 systemd[18795]: Closed GnuPG network certificate management daemon.
Jun 25 16:12:11 systemd[18795]: Closed GnuPG cryptographic agent and passphrase cache (access for web browsers).
Jun 25 16:12:11 systemd[18795]: Stopped target Timers.
Jun 25 16:12:11 systemd[18795]: Stopped target Paths.
Jun 25 16:12:11 systemd[18795]: Reached target Shutdown.
Jun 25 16:12:11 systemd[18795]: Starting Exit the Session...
Jun 25 16:12:11 systemd[18795]: Received SIGRTMIN+24 from PID 5414 (kill).
Jun 25 16:12:11 systemd[1]: Stopped User Manager for UID 1000.
Jun 25 16:12:11 systemd[1]: Removed slice User Slice of API_USER.
Jun 25 16:17:01 CRON[5416]: (root) CMD ( cd / && run-parts --report /etc/cron.hourly)
Jun 25 16:31:49 systemd-timesyncd[449]: Network configuration changed, trying to establish connection.
Jun 25 16:31:49 systemd-networkd[581]: eth0: Configured
Jun 25 16:31:49 systemd-timesyncd[449]: Synchronized to time server 91.189.89.199:123 (ntp.ubuntu.com).
之后,用户会话不会启动。但是如果你尝试向这个服务的 api 发出请求,那么用户会话和服务就会被启动。
Jun 26 11:31:28 systemd-networkd[581]: eth0: Configured
Jun 26 11:31:28 systemd-timesyncd[449]: Network configuration changed, trying to establish connection.
Jun 26 11:31:28 systemd-timesyncd[449]: Synchronized to time server 91.189.89.199:123 (ntp.ubuntu.com).
Jun 26 11:32:37 systemd[1]: Created slice User Slice of API_USER.
Jun 26 11:32:37 systemd[1]: Starting User Manager for UID 1000...
Jun 26 11:32:37 systemd[1]: Started Session 1208 of user API_USER.
Jun 26 11:32:37 systemd[6860]: /home/API_USER/.config/systemd/user/API_SERVICE.service:8: Failed to parse service type, ignoring: Simple
Jun 26 11:32:37 systemd[6860]: Listening on GnuPG network certificate management daemon.
Jun 26 11:32:37 systemd[6860]: Listening on REST API socket for snapd user session agent.
Jun 26 11:32:37 systemd[6860]: Reached target Timers.
Jun 26 11:32:37 systemd[6860]: Listening on GnuPG cryptographic agent and passphrase cache (access for web browsers).
Jun 26 11:32:37 systemd[6860]: Listening on GnuPG cryptographic agent and passphrase cache (restricted).
Jun 26 11:32:37 systemd[6860]: Listening on GnuPG cryptographic agent (ssh-agent emulation).
Jun 26 11:32:37 systemd[6860]: Listening on GnuPG cryptographic agent and passphrase cache.
Jun 26 11:32:37 systemd[6860]: Reached target Sockets.
Jun 26 11:32:37 systemd[6860]: Reached target Paths.
Jun 26 11:32:37 systemd[6860]: Reached target Basic System.
Jun 26 11:32:37 systemd[1]: Started User Manager for UID 1000.
Jun 26 11:32:37 systemd[6860]: Started API_SERVICE.
Jun 26 11:32:37 systemd[6860]: Reached target Default.
Jun 26 11:32:37 systemd[6860]: Startup finished in 53ms.
Jun 26 11:32:38 API_SERVICE[6873]: API_SERVICE_LOG
- 用户会话停止的原因是什么?
- 如何防止这种情况?
解决方案
loginctl enable-linger USER_NAME
出色地。事实证明,服务在用户会话工作时工作,这是由活动的 ssh 连接支持的。当我断开此连接时,用户会话已关闭,因此该用户的所有服务都已关闭。当有对非工作服务的请求时,请求以错误结束,我收到了通知,之后我通过 ssh 连接到服务器,因此引发了用户会话和相关的服务它被提出来了。因此,一切看起来都如问题中所述。
当我开始比较我如何在其他没有此类问题的服务器上配置服务时,我发现在这种情况下我错过了上面指示的命令的执行。完成后,断开 ssh 连接后用户会话不会结束。
推荐阅读
- wix - 启动条件是否以静默模式显示?
- linux-kernel - Yocto SDK 内核源制作脚本失败
- bash - 通过 nohup 命令传递参数
- html - 为什么我不能使用引导程序正确更改输入宽度的大小百分比
- python-idle - 无论如何在IDLE for python中突出显示我的变量名和数字不同的颜色?
- javascript - 如何在 php 中设置 php 变量集并从文件夹中获取文件名
- c# - WPF XAML - 在 Datagrid c# 中进行分组的嵌套扩展器控件
- c - 在 Swift 项目中使用多个 Objective-C 头文件
- python - 检查不和谐消息是否有参考(是回复)
- python - Python Pandas 计算两列的 value_counts 并使用 groupby