年年有"余"

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 2009|回复: 0

[CentOS] CentOS设置随机启动项

[复制链接]
  • TA的每日心情
    奋斗
    2022-12-13 21:26
  • 签到天数: 371 天

    [LV.9]以坛为家II

    发表于 2015-4-23 09:31:04 | 显示全部楼层 |阅读模式
    三种方式:

    1、把启动程序的命令添加到/etc/rc.d/rc.local文件中,如随机启动svn服务

    [root@Crayfish ~]# cd /etc/rc.d/
    [root@Crayfish rc.d]# ls
    init.d  rc  rc0.d  rc1.d  rc2.d  rc3.d  rc4.d  rc5.d  rc6.d  rc.local  rc.sysinit
    [root@Crayfish rc.d]# cat rc.local
    #!/bin/sh
    #
    # This script will be executed *after* all the other init scripts.
    # You can put your own initialization stuff in here if you don't
    # want to do the full Sys V style init stuff.

    touch /var/lock/subsys/local
    svnserve -d -r /svn/
    [root@Crayfish rc.d]#


    2、把写好的启动脚本添加到目录/etc/rc.d/init.d/,然后使用命令chkconfig设置开机启动。

    chkconfig 功能说明:检查,设置系统的各种服务。
    语法:chkconfig [--add][--del][--list][系统服务] 或 chkconfig [--level <等级代号>][系统服务][on/off/reset]
    --add 添加服务
    --del 删除服务
    --list 查看各服务启动状态

    比如我们设置自启动mysql:
    将mysql启动脚本放入所有脚本运行目录/etc/rc.d/init.d中
    cp /lamp/mysql-5.0.41/support-files/mysql.server /etc/rc.d/init.d/mysqld

    #改变权限
    chown root.root /etc/rc.d/init.d/mysqld

    #所有用户都可以执行,单只有root可以修改
    chmod 755 /etc/rc.d/init.d/mysqld

    #将mysqld 放入linux启动管理体系中
    chkconfig --add mysqld

    #查看全部服务在各运行级状态
    chkconfig --list mysqld

    #只要运行级别3启动,其他都关闭
    chkconfig --levels 245 mysqld off


    例如:我们把httpd的脚本写好后放进/etc/rc.d/init.d/目录,使用
    chkconfig --add httpd
    chkconfig httpd on

    命令即设置好了开机启动。

    3、把启动程序的命令添加到/etc/rc.d/rc.sysinit 文件中

    脚本/etc/rc.d/rc.sysinit,完成系统服务程序启动,如系统环境变量设置、设置系统时钟、加载字体、检查加载文件系统、生成系统启动信息日志文件等
    比如我们设置自启动apache:
    echo "/usr/local/apache2/bin/apachectl start" >> /etc/rc.d/rc.sysinit
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    手机版|小黑屋|Archiver|iOS开发笔记 ( 湘ICP备14010846号 )

    GMT+8, 2024-5-1 07:20 , Processed in 0.042802 second(s), 18 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2021, Tencent Cloud.

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