Fedora 37 启动时从 NAS 挂载 iscsi 目标速度缓慢

Fedora 37 启动时从 NAS 挂载 iscsi 目标速度缓慢

我在 Asustor NAS 上有一个 iscsi 目标,但将其添加到 fstab 后,F37 启动速度慢了 2 分钟,因为 iscsi.service 在启动过程中重新加载了两次,我不知道为什么。

$ sudo iscsiadm -m discovery -t st -p 192.168.0.90
192.168.0.90:3260,1 iqn.2011-08.com.asustor:as5304t-8d33b5.target001
172.17.0.1:3260,1 iqn.2011-08.com.asustor:as5304t-8d33b5.target001

$ sudo blkid
/dev/sdc1: UUID="a8ba2edc-5c7c-41b3-bc78-6b8229dedb7d" BLOCK_SIZE="4096" TYPE="ext4" PARTLABEL="primary" PARTUUID="19732655-96b8-439c-9ff1-07928f2486ef"

$ sudo iscsiadm -m session -o show
tcp: [1] 192.168.0.90:3260,1 iqn.2011-08.com.asustor:as5304t-8d33b5.target001 (non-flash)

最慢的服务是

$ systemd-analyze blame
2min 1.740s iscsi.service

# the slowest line is 
$ echo "$(< /var/log/boot.log)"
[  OK  ] Finished iscsi.service - Login and scanning of iSCSI devices.

$ systemd-analyze critical-chain
The time when unit became active or started is printed after the "@" character.
The time the unit took to start is printed after the "+" character.

graphical.target @2min 35.648s
└─multi-user.target @2min 35.648s
  └─plymouth-quit-wait.service @2min 14.928s +20.711s
    └─systemd-user-sessions.service @2min 14.891s +15ms
      └─remote-fs.target @2min 14.877s
        └─home-oglop-iscsi.mount @2min 14.846s +30ms
          └─remote-fs-pre.target @2min 14.828s
            └─iscsi.service @13.085s +2min 1.740s
              └─iscsid.service @13.201s +105ms
                └─network-online.target @13.073s
                  └─NetworkManager-wait-online.service @4.821s +8.250s
                    └─NetworkManager.service @4.738s +63ms
                      └─network-pre.target @4.720s
                        └─firewalld.service @3.911s +807ms
                          └─polkit.service @3.494s +388ms
                            └─basic.target @3.296s
                              └─dbus-broker.service @3.200s +91ms
                                └─dbus.socket @3.165s
                                  └─sysinit.target @3.100s
                                    └─systemd-resolved.service @2.581s +517ms
                                      └─systemd-tmpfiles-setup.service @2.326s +205ms
                                        └─local-fs.target @2.313s
                                          └─run-user-1000-doc.mount @2min 26.179s
                                            └─run-user-1000.mount @2min 15.287s
                                              └─local-fs-pre.target @1.792s
                                                └─lvm2-monitor.service @1.012s +773ms
                                                  └─dm-event.socket @980ms
                                                    └─system.slice
                                                      └─-.slice

/etc/systemd/system/remote-fs.target.wants/iscsi.service 是 F37 中的默认值我没有更改任何内容

[Unit]
Description=Login and scanning of iSCSI devices
Documentation=man:iscsiadm(8) man:iscsid(8)
DefaultDependencies=no
Before=remote-fs-pre.target
After=network.target network-online.target iscsid.service iscsiuio.service systemd-remount-fs.service
Wants=remote-fs-pre.target
ConditionDirectoryNotEmpty=/var/lib/iscsi/nodes

[Service]
Type=oneshot
RemainAfterExit=true
ExecStart=-/usr/sbin/iscsiadm -m node --loginall=automatic
ExecReload=-/usr/sbin/iscsiadm -m node --loginall=automatic
SuccessExitStatus=21

[Install]
WantedBy=remote-fs.target

iscsi.服务日志

$ sudo journalctl -u iscsi -b
Dec 27 00:33:48 t450s systemd[1]: Starting iscsi.service - Login and scanning of iSCSI devices...
Dec 27 00:35:51 t450s iscsiadm[1325]: iscsiadm: Could not login to [iface: default, target: iqn.2011-08.com.asustor:as5304t-8d33b5.target0>
Dec 27 00:35:51 t450s iscsiadm[1325]: iscsiadm: initiator reported error (8 - connection timed out)
Dec 27 00:35:51 t450s iscsiadm[1325]: iscsiadm: Could not log into all portals
Dec 27 00:35:51 t450s iscsiadm[1325]: Logging in to [iface: default, target: iqn.2011-08.com.asustor:as5304t-8d33b5.target001, portal: 192>
Dec 27 00:35:51 t450s iscsiadm[1325]: Logging in to [iface: default, target: iqn.2011-08.com.asustor:as5304t-8d33b5.target001, portal: 172>
Dec 27 00:35:51 t450s iscsiadm[1325]: Login to [iface: default, target: iqn.2011-08.com.asustor:as5304t-8d33b5.target001, portal: 192.168.>
Dec 27 00:35:51 t450s systemd[1]: Finished iscsi.service - Login and scanning of iSCSI devices.
Dec 27 00:35:51 t450s systemd[1]: Reloading iscsi.service - Login and scanning of iSCSI devices...
Dec 27 00:37:54 t450s iscsiadm[1529]: iscsiadm: Could not login to [iface: default, target: iqn.2011-08.com.asustor:as5304t-8d33b5.target0>
Dec 27 00:37:54 t450s iscsiadm[1529]: iscsiadm: initiator reported error (8 - connection timed out)
Dec 27 00:37:54 t450s iscsiadm[1529]: iscsiadm: Could not log into all portals
Dec 27 00:37:54 t450s iscsiadm[1529]: Logging in to [iface: default, target: iqn.2011-08.com.asustor:as5304t-8d33b5.target001, portal: 172>
Dec 27 00:37:54 t450s systemd[1]: Reloaded iscsi.service - Login and scanning of iSCSI devices.

我可以从上面的日志中看到

Dec 27 00:35:51 t450s systemd[1]: Finished iscsi.service - Login and scanning of iSCSI devices.
Dec 27 00:35:51 t450s systemd[1]: Reloading iscsi.service - Login and scanning of iSCSI devices...

它完成加载服务,然后开始重新加载服务,然后花了 2 分钟才完成加载。不知道为什么它想再次重新加载。

启动后挂载工作正常,只是启动时间很慢,如果我注释掉 fstab 行,启动又很快,但我希望它在启动时自动挂载。

如果我手动重启服务,也需要2分钟

$ sudo systemctl restart iscsi.service

$ sudo journalctl -u iscsi
Dec 27 12:23:07 t450s systemd[1]: iscsi.service: Deactivated successfully.
Dec 27 12:23:07 t450s systemd[1]: Stopped iscsi.service - Login and scanning of iSCSI devices.
Dec 27 12:23:07 t450s systemd[1]: Stopping iscsi.service - Login and scanning of iSCSI devices...
Dec 27 12:23:07 t450s systemd[1]: Starting iscsi.service - Login and scanning of iSCSI devices...
Dec 27 12:25:09 t450s iscsiadm[6021]: iscsiadm: Could not login to [iface: default, target: iqn.2011-08.com.asustor:as5304t-8d33b5.target>
Dec 27 12:25:09 t450s iscsiadm[6021]: iscsiadm: initiator reported error (8 - connection timed out)
Dec 27 12:25:09 t450s iscsiadm[6021]: iscsiadm: Could not log into all portals
Dec 27 12:25:09 t450s iscsiadm[6021]: Logging in to [iface: default, target: iqn.2011-08.com.asustor:as5304t-8d33b5.target001, portal: 17>
Dec 27 12:25:09 t450s systemd[1]: Finished iscsi.service - Login and scanning of iSCSI devices.

这里可能有答案,但我看不到隐藏的解决方案。https://access.redhat.com/solutions/3649231

答案1

最后我发现了一个肮脏的黑客

  1. 在 /etc/fstab 中使用它
UUID=a8ba2edc-5c7c-41b3-bc78-6b8229dedb7d /home/oglop/iscsi ext4 defaults,_netdev,noauto,x-systemd.automount 0 0
  1. 将 iscsi.serviceType=从修改oneshotforking
sudo systemctl edit --full iscsi

据介绍,这是最令人困惑的部分系统服务doc,oneshot正是我们在这里需要的类型,但是分叉​​消除了延迟,并且在启动后仍然显示正确的服务状态。

我的完整 iSCSI.service

[Unit]
Description=Login and scanning of iSCSI devices
Documentation=man:iscsiadm(8) man:iscsid(8)
DefaultDependencies=no
Before=remote-fs-pre.target
After=network.target network-online.target iscsid.service iscsiuio.service systemd-remount-fs.service
Wants=remote-fs-pre.target
ConditionDirectoryNotEmpty=/var/lib/iscsi/nodes

[Service]
#Type=oneshot
Type=forking
RemainAfterExit=true
ExecStart=-/usr/sbin/iscsiadm -m node --loginall=automatic
ExecReload=-/usr/sbin/iscsiadm -m node --loginall=automatic
SuccessExitStatus=21

[Install]
WantedBy=remote-fs.target

更新:黑客工作了几个小时,然后开始导致默认的 90 秒延迟。

我添加--debug=8到iscsi.service,这是使用时的完整日志Type=oneshot

https://pastebin.com/4XbvcjYj

答案2

我突然意识到这是因为它正在尝试登录我在 NAS 上的第二个目标,不知道它是如何创建的,我那里只有一个 lun。

sudo iscsiadm --m node -T iqn.2011-08.com.asustor:as5304t-8d33b5.target001 -p 172.17.0.1:3260 -o delete

然后重新启动,现在一切都很棒,没有延迟

相关内容