荣耀之链论坛

 找回密码
 立即注册
搜索
查看: 2879|回复: 2

设置服务开机启动 或者开机自动运行脚本

[复制链接]

1326

主题

2373

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
10267
发表于 2015-9-7 14:38 | 显示全部楼层 |阅读模式
chkconfig --list iptables

chkconfig iptables on
chkconfig iptables off



root权限编辑/etc/rc.d/rc.local
然后在最后面添加你写好的脚本
比如
sh /home/test/test.sh
然后保存
以后重启的时候就会自动运行你写的这个脚本

回复

使用道具 举报

1326

主题

2373

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
10267
 楼主| 发表于 2016-3-11 22:38 | 显示全部楼层
CENTOS7里面服务是这样的
systemctl start httpd.service #启动apache
systemctl stop httpd.service #停止apache
systemctl restart httpd.service #重启apache
systemctl enable httpd.service #设置apache开机启动
回复 支持 反对

使用道具 举报

1326

主题

2373

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
10267
 楼主| 发表于 2016-3-19 00:58 | 显示全部楼层
http://www.centoscn.com/CentosBug/osbug/2015/0209/4670.html

centos7 开机/etc/rc.local 不执行的问题

最近发现centos7 的/etc/rc.local不会开机执行,于是认真看了下/etc/rc.local文件内容的就发现了问题的原因了
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In constrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
翻译:
#这个文件是为了兼容性的问题而添加的。
#
#强烈建议创建自己的systemd服务或udev规则来在开机时运行脚本而不是使用这个文件。
#
#与以前的版本引导时的并行执行相比较,这个脚本将不会在其他所有的服务后执行。
#
#请记住,你必须执行“chmod +x /etc/rc.d/rc.local”来确保确保这个脚本在引导时执行。
于是我有确认了下/etc/rc.local的权限
[root@localhost ~]# ll /etc/rc.local
lrwxrwxrwx. 1 root root 13 8月  12 06:09 /etc/rc.local -> rc.d/rc.local
[root@localhost ~]# ll /etc/rc.d/rc.local
-rw-r--r--. 1 root root 477 6月  10 13:35 /etc/rc.d/rc.local
/etc/rc.d/rc.local没有执行权限,于是按说明的内容执行
       
chmod +x /etc/rc.d/rc.local
重启后发现/etc/rc.local能够执行了。
看样子是版本的变迁,/etc/rc.local /etc/rc.d/rc.local正在弃用的路上。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

荣耀之链

GMT+8, 2025-6-18 05:18 , Processed in 0.014080 second(s), 20 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表