CoreOS 在重启时安装 CIFS

CoreOS 在重启时安装 CIFS

我能够使用以下方式在 CoreOS 上安装 Windows 共享驱动器https://github.com/xynova/docker-cifs-build

我已经在里面创建了一个服务

$ sudo vim /etc/systemd/system/mount.service

[Unit]
Description=Mount Share service
After=network.target

[Service]
Type=oneshot
RemainAfterExit=yes
TimeoutStartSec=0
ExecStart=/opt/bin/mount.cifs //192.168.10.4/Apps/pegasus/operaII/Data/C /ccc/smb -o domain=server-apps.continental.local,username=usernam,password=password,uid=0,gid=0

[Install]
WantedBy=multi-user.target

重启后我得到了这个

Mar 08 10:21:24 araweelo coreos-cloudinit[670]: 2016/03/08 10:21:24 Ensuring runtime unit file "00-eno1.network" is unmasked
Mar 08 10:21:24 araweelo coreos-cloudinit[670]: 2016/03/08 10:21:24 /run/systemd/network/00-eno1.network is not null or empty, refusing to unmask
Mar 08 10:21:24 araweelo coreos-cloudinit[670]: 2016/03/08 10:21:24 Writing drop-in unit "20-cloudinit.conf" to filesystem
Mar 08 10:21:24 araweelo coreos-cloudinit[670]: 2016/03/08 10:21:24 Writing file to "/run/systemd/system/etcd.service.d/20-cloudinit.conf"
Mar 08 10:21:24 araweelo coreos-cloudinit[670]: 2016/03/08 10:21:24 Wrote file to "/run/systemd/system/etcd.service.d/20-cloudinit.conf"
Mar 08 10:21:24 araweelo coreos-cloudinit[670]: 2016/03/08 10:21:24 Wrote drop-in unit "20-cloudinit.conf"
Mar 08 10:21:24 araweelo coreos-cloudinit[670]: 2016/03/08 10:21:24 Ensuring runtime unit file "etcd.service" is unmasked
Mar 08 10:21:24 araweelo coreos-cloudinit[670]: 2016/03/08 10:21:24 Ensuring runtime unit file "etcd2.service" is unmasked
Mar 08 10:21:24 araweelo coreos-cloudinit[670]: 2016/03/08 10:21:24 Ensuring runtime unit file "fleet.service" is unmasked
Mar 08 10:21:24 araweelo coreos-cloudinit[670]: 2016/03/08 10:21:24 Ensuring runtime unit file "locksmithd.service" is unmasked
Mar 08 10:21:24 araweelo kernel: CIFS VFS: Error connecting to socket. Aborting operation.
Mar 08 10:21:24 araweelo kernel: CIFS VFS: cifs_mount failed w/return code = -101
Mar 08 10:21:24 araweelo systemd[1]: Reloading.
Mar 08 10:21:24 araweelo mount.cifs[719]: mount error(101): Network is unreachable
Mar 08 10:21:24 araweelo mount.cifs[719]: Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)
Mar 08 10:21:24 araweelo systemd[1]: mount.service: Main process exited, code=exited, status=32/n/a
Mar 08 10:21:24 araweelo systemd[1]: Failed to start Mount Share service.
-- Subject: Unit mount.service has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit mount.service has failed.
-- 
-- The result is failed.
Mar 08 10:21:24 araweelo systemd[1]: mount.service: Unit entered failed state.
Mar 08 10:21:24 araweelo systemd[1]: mount.service: Failed with result 'exit-code'.
Mar 08 10:21:24 araweelo coreos-cloudinit[670]: 2016/03/08 10:21:24 Restarting systemd-networkd
Mar 08 10:21:24 araweelo systemd[1]: Starting Garbage Collection for rkt...
-- Subject: Unit rkt-gc.service has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit rkt-gc.service has begun starting up.
Mar 08 10:21:24 araweelo systemd[1]: Reached target Multi-User System.
-- Subject: Unit multi-user.target has finished start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit multi-user.target has finished starting up.
-- 
-- The start-up result is done.
Mar 08 10:21:24 araweelo systemd[1]: Started Garbage Collection for rkt.
-- Subject: Unit rkt-gc.service has finished start-up

我可以手动运行该服务

$ sudo systemctl start mount.service
Warning: mount.service changed on disk. Run 'systemctl daemon-reload' to reload units.
khine@araweelo ~ $ sudo systemctl daemon-reload
khine@araweelo ~ $ df -h
Filesystem                                  Size  Used Avail Use% Mounted on
devtmpfs                                    3.4G     0  3.4G   0% /dev
tmpfs                                       3.5G     0  3.5G   0% /dev/shm
tmpfs                                       3.5G  428K  3.5G   1% /run
tmpfs                                       3.5G     0  3.5G   0% /sys/fs/cgroup
/dev/sda9                                   114G  4.7G  104G   5% /
/dev/sda4                                   985M  492M  442M  53% /usr
tmpfs                                       3.5G     0  3.5G   0% /tmp
tmpfs                                       3.5G     0  3.5G   0% /media
/dev/sda1                                   128M   61M   68M  48% /boot
/dev/sda6                                   108M   52K   99M   1% /usr/share/oem
//192.168.10.4/Apps/pegasus/operaII/Data/C  558G  236G  323G  43% /ccc/smb

从日志中我看到网络无法访问,如果这是问题所在,我该如何在网络重新初始化后运行挂载?

答案1

在 CoreOS 上可以设置网络:

  • 通过 Cloud Init
  • 通过 systemd 的静态配置

https://coreos.com/os/docs/latest/network-config-with-networkd.html

在您的服务中,您可能希望更改,After=network.target因此Wants=network-online.target您的服务仅在成功配置网络后才会启动。如果通过 cloud-init 设置网络,它也应该回答相同的依赖关系。

相关内容