温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Centos 7关于rc.local脚本命令开机不执行及指定

发布时间:2020-07-10 02:25:50 来源:网络 阅读:14239 作者:canonind 栏目:MongoDB数据库


1.开机不启动

在实际生产场景中,我们喜欢在安装了一些软件服务后,将软件设置为开机自启动,设置为开机自启动有两种方法:

1)  设置为chkconfig,可以编写脚本,查看设置开机自启动的命令 –add表示添加程序自启动, --list表示查看。

以后的程序如果需要使用chkconfig开机自启动,那么需要在启动程序中加入三行:

# chkconfig:2345 20 80

#description: Saves and restores system entropy pool for \

#              higher quality random numbergeneration.

                 第一行中的20,80是启动级别,不能与其他程序一样,因此,需自定义设置。

2)  配置在/etc/rc.local文件中。直接将软件服务的启动命令写在rc.local文件

注意:编辑完rc.local文件后,一定要给rc.local文件执行权限,否则开机时不会执行rc.local文件中脚本命令

chmod+x /etc/rc.d/rc.local

注意此处,是/etc/rc.d/rc.local,而不是/etc/rc.local,如果给/etc/rc.local执行权限是无效的,因为/etc/rc.local是软链接,真正的文件是/etc/rc.d/rc.local


2.关于在rc.local文件中指定用户执行脚本命令

使用su命令即可,命令格式:

su - username -c “your-cammand” ,如:

[jiakeke@mongodb ~]$ cat /etc/rc.local

#!/bin/bash

# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES

#

# It is highly advisable to create own systemdservices or udev rules

# to run scripts during boot instead of using thisfile.

#

# In constrast to previous versions due to parallelexecution during boot

# this script will NOT be run after all otherservices.

#

# Please note that you must run 'chmod +x/etc/rc.d/rc.local' to ensure

# that this script will be executed during boot.

 

touch /var/lock/subsys/local

/bin/systemctl start iptables.service

#startup mongodb

/bin/su - xiaoyao -c  "/mnt/mongodb/bin/mongod --config/mnt/mongodb/bin/mongodb.conf"

 

注意:指定用户执行的脚本(程序)目录,该用户必须有管理该脚本(程序)目录(文件)的权限。

最好将该脚本(程序)目录的所有权给该用户:

chown -R xiaoyao.xiaoyao /mnt/mongodb


向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI