• 设备
    • 今日
    • 0

    Centos7开机自启动配置

    kibana开机启动(Centos7环境 )
    kibana版本:6.2.2
    步骤:
    1.新建kibana.service服务文件
    vim /usr/lib/systemd/system/kibana.service
    ------
    [Unit]
    Description=Kibana  Server Manager

    [Service]
    ExecStart=/usr/local/kibana-7.0.0/bin/kibana

    [Install]
    WantedBy=multi-user.target
    ------
    3.刷新systemctl
    systemctl daemon-reload
    4.启动kibana
    systemctl start kibana
    5.设置kibana开机自启动
    systemctl enable kibana


    nginx.service服务(Centos7环境 )
    为了方便,现将nginx服务添加至systemctl,修改nginx配置文件,开启pid
    vim /etc/nginx/nginx  在文件第二行,添加
    pid        /var/run/nginx.pid;

    vim /lib/systemd/system/nginx.service
    ------
    [Unit]
    Description=nginx - high performance web server
    After=network.target remote-fs.target nss-lookup.target
    [Service]
    Type=forking
    PIDFile=/var/run/nginx.pid
    ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/nginx.conf
    ExecStart=/usr/sbin/nginx -c /etc/nginx/nginx.conf
    ExecReload=/usr/sbin/nginx -s reload
    ExecStop=/usr/sbin/nginx -s quit
    PrivateTmp=true
    [Install]
    WantedBy=multi-user.target
    ------
    设置开机启动
    systemctl enable nginx
    systemctl start nginx
    systemctl stop nginx
    systemctl restart nginx
    systemctl status nginx
    若发生报错,可通过systemctl status nginx.service查看失败原因
    查看所有已启动的服务

    systemctl list-units --type=service


    Elasticsearch Head插件开机自启动(Centos7环境 )
    1.添加开机自启脚本,注意都需要用绝对路径
    vim /home/elsearch/app/es_head.sh
    cd /usr/share/elasticsearch-head/node_modules/grunt/bin
    nohup ./grunt server & 
    2、赋予脚本可执行权限(/home/elsearch/app/es_head.sh是你的脚本路径)
    chmod 777 /home/elsearch/app/es_head.sh
    3、打开/etc/rc.d/rc.local文件,在末尾增加如下内容
    echo "/home/elsearch/app/es_head.sh" >> /etc/rc.d/rc.local
    4、在centos7中,/etc/rc.d/rc.local的权限被降低了,所以需要执行如下命令赋予其可执行权限
    chmod +x /etc/rc.d/rc.local

    后注:
    安装Head插件
    需要安装nodejs、npm
    yum -y install nodejs npm
    如果没有安装git,还需要先安装git
    yum -y install git
    然后安装elasticsearch-head插件:
    git clone https://github.com/mobz/elasticsearch-head.git
    git下载完成后,进入目录,进行操作:
    /usr/share/elasticsearch-head
    npm install
    插件安装相对会慢一些,请耐心等待...

    [Service]小节选项
    每个服务单元文件都必须包含一个"[Service]"小节。由于此小节中的许多选项也同时适用于其他类型的单元
    Type=
    设置进程的启动类型,必须是下列值之一:simple, forking, oneshot, dbus, notify, idle 之一。
    1.如果设为"simple"(设置了 ExecStart= 但未设置 BusName= 时的默认值),那么表示 ExecStart= 所设定的进程就是该服务的主进程。 如果此进程需要为其他进程提供服务,那么必须在该进程启动之前先建立好通信渠道(例如套接字),以加快后继单元的启动速度。
    2."dbus"(设置了 ExecStart= 与 BusName= 时的默认值)与"simple"类似,不同之处在于该进程需要在 D-Bus 上获得一个由 BusName= 指定的名称。 systemd 将会在启动后继单元之前,首先确保该进程已经成功的获取了指定的 D-Bus 名称。设置为此类型相当于隐含的依赖于 dbus.socket 单元。
    3."oneshot"(未设置 ExecStart= 时的默认值)与"simple"类似,不同之处在于该进程必须在 systemd 启动后继单元之前退出。 此种类型通常需要设置 RemainAfterExit= 选项。
    4.如果设为"forking",那么表示 ExecStart= 所设定的进程将会在启动过程中使用 fork() 系统调用。这是传统UNIX守护进程的经典做法。 也就是当所有的通信渠道都已建好、启动亦已成功之后,父进程将会退出,而子进程将作为该服务的主进程继续运行。 对于此种进程,建议同时设置 PIDFile= 选项,以帮助 systemd 准确定位该服务的主进程,进而加快后继单元的启动速度。
    5."notify"与"simple"类似,不同之处在于该进程将会在启动完成之后通过 sd_notify(3) 之类的接口发送一个通知消息。 systemd 将会在启动后继单元之前,首先确保该进程已经成功的发送了这个消息。 如果设置为此类型,那么 NotifyAccess= 将只能设置为"all"或者"main"(默认)。 注意,目前 Type=notify 尚不能在 PrivateNetwork=yes 的情况下正常工作。
    6."idle"与"simple"类似,不同之处在于该进程将会被延迟到所有的操作都完成之后再执行。 这样可以避免控制台上的状态信息与 shell 脚本的输出混杂在一起。


    旧版本配置

    vim /etc/init.d/nginx

    #!/bin/bash

    # nginx Startup script for the Nginx HTTP Server
    # it is v.0.0.2 version.
    # chkconfig: - 85 15
    # description: Nginx is a high-performance web and proxy server.
    #              It has a lot of features, but it's not for everyone.
    # processname: nginx
    # pidfile: /var/run/nginx.pid
    # config: /etc/nginx/nginx.conf
    nginxd=/usr/local/tengine/sbin/nginx
    nginx_config=/etc/nginx/nginx.conf
    nginx_pid=/usr/local/tengine/logs/nginx.pid
    RETVAL=0
    prog="nginx"
    # Source function library.
    . /etc/rc.d/init.d/functions
    # Source networking configuration.
    . /etc/sysconfig/network
    # Check that networking is up.
    [ ${NETWORKING} = "no" ] && exit 0
    [ -x $nginxd ] || exit 0
    # Start nginx daemons functions.
    start() {
    if [ -e $nginx_pid ];then
    echo "nginx already running...."
    exit 1
    fi
    echo -n $"Starting $prog: "
    daemon $nginxd -c ${nginx_config}
    RETVAL=$?
    echo
    [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
    return $RETVAL
    }
    # Stop nginx daemons functions.
    stop() {
    echo -n $"Stopping $prog: "
    killproc $nginxd
    RETVAL=$?
    echo
    [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /usr/local/tengine/logs/nginx.pid
    }
    # reload nginx service functions.
    reload() {
    echo -n $"Reloading $prog: "
    #kill -HUP `cat ${nginx_pid}`
    killproc $nginxd -HUP
    RETVAL=$?
    echo
    }
    # See how we were called.
    case "$1" in
    start)
    start
    ;;
    stop)
    stop
    ;;
    reload)
    reload
    ;;
    restart)
    stop
    start
    ;;
    status)
    status $prog
    RETVAL=$?
    ;;
    *)
    echo $"Usage: $prog {start|stop|restart|reload|status|help}"
    exit 1
    esac
    exit $RETVAL

    来自:PC 广东省广州市
    上一篇: redis开机自动
    您可能还喜欢这些:

    亲,沙发正空着,还不快来抢?

    评论审核已开启:即评论经审核才能正常显示! 记住我的个人信息 回复后邮件通知我