/etc/rc.local
这个文件是在系统启动时会加载执行的,通常情况下我们可以在文件末尾添加需要开机启动的任务。
[root@localhost ~]# head -20 /etc/rc.d/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 contrast 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.
/etc/profile
先看下这个文件的说明,系统范围的环境和启动程序。实际使用中每次登录都会执行里面的内容,除了/etc/profile,还有/etc/profile.d/file、/etc/bashrc、/root/.bashrc、/root/.bash_profile(这里的root是根据登录用户决定)。官方也提示了不建议直接修改/etc/profile,如果有需要登录执行的内容,可以在/etc/profile.d/下创建脚本。
通常情况下,我们把环境变量配置到/etc/profile.d/中。因为是用户登录就执行,所以这些文件中适合配置要避免和/etc/rc.local中的开机启动项冲突,并且登录用户是非root时,要注意给执行文件添加用户权限,或者使用/XXX/.bashrc、/XXX/.bash_profile.
[root@localhost ~]# head /etc/profile # /etc/profile # System wide environment and startup programs, for login setup # Functions and aliases go in /etc/bashrc # It's NOT a good idea to change this file unless you know what you # are doing. It's much better to create a custom.sh shell script in # /etc/profile.d/ to make custom changes to your environment, as this # will prevent the need for merging in future updates.