title: Ubuntu-18-开机自启
    date: 2018-07-01 16:01:33
    categories:

    • Linux
    • Linux
      tags: [linux,linux]

    ubuntu18.04 不再使用initd管理系统,改用systemd

    1. 设置启动参数
      vim /lib/systemd/system/rc.local.service
    1. [Unit]
    2. Description=/etc/rc.local Compatibility
    3. Documentation=man:systemd-rc-local-generator(8)
    4. ConditionFileIsExecutable=/etc/rc.local
    5. After=network.target
    6. [Service]
    7. Type=forking
    8. ExecStart=/etc/rc.local start
    9. TimeoutSec=0
    10. RemainAfterExit=yes
    11. GuessMainPID=no
    12. #这一段原文件没有,需要自己添加
    13. [Install]
    14. WantedBy=multi-user.target
    15. Alias=rc-local.service
    1. 添加软链接
    ln -s /lib/systemd/system/rc.local.service /etc/systemd/system/rc.local.service
    
    1. 创建服务
    touch /etc/rc.local
    
    1. 赋可执行权限
    chmod 755 /etc/rc.local
    
    1. 编辑自启动服务
      vim /etc/rc.local
    #开机打印hello
    echo "hello" > /etc/test.log
    # 开机启动zookeeper
    /usr/local/zookeeper/bin start