• centos下设置自启动和配置环境变量的方法


    1. 设置自启动

    CentOS系统下,主要有两种方法设置自己安装的程序开机启动。
    1、把启动程序的命令添加到/etc/rc.d/rc.local文件中,比如下面的是设置开机启动httpd。

    复制代码
    #!/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
    /usr/local/apache/bin/apachectl start
    复制代码

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

    chkconfig 功能说明:检查,设置系统的各种服务。

    语法:chkconfig [--add][--del][--list][系统服务] 或 chkconfig [--level <等级代号>][系统服务][on/off/reset]

    --add 添加服务

    --del 删除服务

    --list 查看各服务启动状态

    比如我们设置自启动mysql:

    复制代码
     1 #将mysql启动脚本放入所有脚本运行目录/etc/rc.d/init.d中
     2 cp /lamp/mysql-5.0.41/support-files/mysql.server /etc/rc.d/init.d/mysqld
     3 
     4 #改变权限
     5 chown root.root /etc/rc.d/init.d/mysqld
     6 
     7 #所有用户都可以执行,单只有root可以修改
     8 chmod 755 /etc/rc.d/init.d/mysqld
     9 
    10 #将mysqld 放入linux启动管理体系中
    11 chkconfig --add mysqld
    12 
    13 #查看全部服务在各运行级状态
    14 chkconfig --list mysqld
    15 
    16 #只要运行级别3启动,其他都关闭
    17 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

    设置环境变量

    linux环境变量配置都在/etc/profile文件中了,编辑profile

    vi /etc/profile
    1
    在文件末尾加入你想要将其设置成环境变量的程序目录,如:
    可加多个

    export PATH="$PATH:/home/consul"
    export PATH="$PATH:/home/etcd/etcd-v3.0.6-linux-amd64"
    1
    2
    按esc退出,依次输入:wq!保存文件
    执行以下命令,让配置生效:

    source /etc/profile
    1
    就ok了。

  • 相关阅读:
    01背包问题需要找出相应路径
    单链表的正序输出和逆序输出
    二叉树之叶子节点个数
    01背包问题
    STL之map和multimap(关联容器)
    python的tips:字符和字符串的问题
    postman的使用(转载)
    python tips(3);import的机制
    python每日一类(5):itertools模块
    python每日一类(4):slice
  • 原文地址:https://www.cnblogs.com/VseYoung/p/linux02.html
Copyright © 2020-2023  润新知