centos脚本执行顺序
通用角度分析,centos 7 系统中存在如下以下5种常用的脚本路径
/etc/rc.d/rc.local
/etc/profile
/etc/bashrc
~/.bash_profile
~/.bashrc
通过在除rc外的脚本中加入echo信息,reboot虚拟机并ssh登陆用户,打印出顺序如下
I am etc profile
i am etc bashrc
i am ~ bash rc
i am ~ bash profile
脚本执行顺序和执行时机
脚本路径 | 执行顺序 | 执行时机 |
---|---|---|
/etc/rc.d/rc.local | 1 | 系统起机执行一次,后续均不执行 |
/etc/profile | 2 | ssh/su/界面登陆时执行 |
/etc/bashrc | 3 | ssh/su/界面登陆时执行 |
~/.bash_profile | 4 | ssh/su/界面登陆以当前用户身份登陆 |
~/.bashrc | 5 | ssh/su/界面登陆以当前用户身份登陆 |
脚本含义
rc.local脚本centos启动时候执行脚本,可以用作默认启动
/etc/profile和/etc/bashrc 属于系统的全局变量设置
~/profile和~/bashrc 属于给予某一个用户的变量设置
profile和bashrc区别
- profile 是用户唯一用来设置环境变量的地方,因为用户可能有多种shell(bash、sh、zsh),环境变量没有必要在每种shell都初始化,只需要统一初始化就行,很显然,profile就是这样的地方
- bashrc 是专门给bash做初始化设置的,相对应来讲,其它shell会有专门的shrc、zshrc文件存放
开机启动脚本其它说明
centos7 默认是没有执行权限的,想在此处加执行脚本,执行脚本不会执行到,需要增添执行权限
1 | [root@localhost rc.d]# ls -alt rc.local |