以Centos7中的nfs服务为例
利用systemctl命令添加启动项
查看开机自启项列表
[root@cs100 ~]# systemctl list-unit-files
UNIT FILE STATE
···
docker.service disabled
dracut-cmdline.service static
dracut-initqueue.service static
dracut-mount.service static
dracut-pre-mount.service static
dracut-pre-pivot.service static
dracut-pre-trigger.service static
dracut-pre-udev.service static
dracut-shutdown.service static
ebtables.service disabled
emergency.service static
firewalld.service disabled
fstrim.service static
getty@.service enabled
gssproxy.service disabled
halt-local.service static
initrd-cleanup.service static
initrd-parse-etc.service static
initrd-switch-root.service static
initrd-udevadm-cleanup-db.service static
iprdump.service disabled
iprinit.service disabled
iprupdate.service disabled
irqbalance.service enabled
k3s.service enabled
····
查看具体服务nfs
[root@cs100 ~]# systemctl list-unit-files | grep nfs
nfs-blkmap.service disabled
nfs-config.service static
nfs-idmap.service static
nfs-idmapd.service static
nfs-lock.service static
nfs-mountd.service static
nfs-rquotad.service disabled
nfs-secure.service static
nfs-server.service disabled
nfs-utils.service static
nfs.service disabled
设置nfs服务开机启动
[root@cs100 ~]# systemctl enable nfs
Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.
[root@cs100 ~]# systemctl list-unit-files | grep nfs
proc-fs-nfsd.mount static
var-lib-nfs-rpc_pipefs.mount static
nfs-blkmap.service disabled
nfs-config.service static
nfs-idmap.service static
nfs-idmapd.service static
nfs-lock.service static
nfs-mountd.service static
nfs-rquotad.service disabled
nfs-secure.service static
nfs-server.service enabled
nfs-utils.service static
nfs.service enabled
nfslock.service static
nfs-client.target enabled
移除开机启动服务
[root@cs100 ~]# systemctl disable nfs
Removed symlink /etc/systemd/system/multi-user.target.wants/nfs-server.service.
[root@cs100 ~]# systemctl list-unit-files | grep nfs
proc-fs-nfsd.mount static
var-lib-nfs-rpc_pipefs.mount static
nfs-blkmap.service disabled
nfs-config.service static
nfs-idmap.service static
nfs-idmapd.service static
nfs-lock.service static
nfs-mountd.service static
nfs-rquotad.service disabled
nfs-secure.service static
nfs-server.service disabled
nfs-utils.service static
nfs.service disabled
nfslock.service static
nfs-client.target enabled