• centos7如何添加开机启动项?


    centos7提供开启服务启动的方式:

    1.系统服务管理命令,如果是通过yum安装的软件,开机启动脚本,已经自动创建好了,直接执行如下命令

    nginx.service后缀可以省略

    systemctl enable nginx.service #这里nginx指的是提前配置好的开机脚本文件

    systemctl start nginx.service #启动nginx服务,也是执行一个nginx脚本文件


    2.因为/usr/lib/systemd/system/这个目录是存放启动文件,里面一般都是 xx.service 格式

    我们使用systemctl enable nginx.service 其实就是在调用/usr/lib/systemd/system/nginx.service


    3.默认nginx.service脚本文件内容如下

    [Unit]
    Description=The nginx HTTP and reverse proxy server
    After=network.target remote-fs.target nss-lookup.target

    [Service]
    Type=forking
    PIDFile=/run/nginx.pid
    # Nginx will fail to start if /run/nginx.pid already exists but has the wrong
    # SELinux context. This might happen when running `nginx -t` from the cmdline.
    # https://bugzilla.redhat.com/show_bug.cgi?id=1268621
    ExecStartPre=/usr/bin/rm -f /run/nginx.pid
    ExecStartPre=/usr/sbin/nginx -t
    ExecStart=/usr/sbin/nginx
    ExecReload=/bin/kill -s HUP $MAINPID
    KillSignal=SIGQUIT
    TimeoutStopSec=5
    KillMode=process
    PrivateTmp=true

    [Install]
    WantedBy=multi-user.target

     

    具体systemctl命令用法,请看
    http://man.linuxde.net/systemctl


    4.总结

    1.如果你是编译安装的软件,例如是redis,默认没有redis.service
    2.就进入/usr/lib/systemd/system/目录,然后创建redis.service 普通文件,touch redis.service
    3.然后写入如下内容,路径可能需要修改,根据自己安装路径修改
    [Unit]
    Description=Redis persistent key-value database
    After=network.target
    After=network-online.target
    Wants=network-online.target
    
    [Service]
    ExecStart=/usr/bin/redis-server /etc/redis.conf --supervised systemd
    ExecStop=/usr/libexec/redis-shutdown
    Type=notify
    User=redis
    Group=redis
    RuntimeDirectory=redis
    RuntimeDirectoryMode=0755
    
    [Install]
    WantedBy=multi-user.target

     

    4.然后通过命令,添加开机启动项
    systemctl enable redis.service
    systemctl start redis.service

  • 相关阅读:
    Java面试宝典
    如何写一个webService接口
    webservice接口的开发和调用
    基于CXF框架下的SOAP Webservice服务端接口开发
    WebService—CXF整合Spring实现接口发布和调用过程
    使用cxf开发webservice接口
    webservice接口与HTTP接口学习笔记
    C#图解教程 第二十五章 其他主题
    C#图解教程 第二十四章 反射和特性
    C#图解教程 第二十三章 预处理指令
  • 原文地址:https://www.cnblogs.com/pyyu/p/10967957.html
Copyright © 2020-2023  润新知