系统版本
# cat /etc/redhat-release CentOS release 6.5 (Final)
问题情景:云主机上部署的是多实例mysql数据库,希望实现开机数据库服务自启动。系统在启动所有的服务后会执行/etc/rc.d/rc.local 中的命令,如下操作
# cat /etc/rc.d/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. /bin/sh /tmp/script/tools/st_mysql #调用的脚本内容 # cat st_mysql # 启动mysql服务 ls -l /etc/mysql/|awk '{print $9}'|cut -d'.' -f1|uniq|xargs -i /tmp/mysql/bin/mysqld_multi --defaults-extra-file=/etc/mysql/{}.cnf --no-log start {}
但是重启主机后,发现mysql服务并未启动,在系统启动日志/var/log/boot.log 中也未发现相关信息
解决过程
对脚本增加可执行权限
输出调用脚本的过程到日志文件,如:/bin/sh -x /tmp/script/tools/st_mysql>/tmp/st_mysql.log
然后重新测试发现日志文件中的输出内容为
# vim /etc/rc.d/rc.local WARNING: my_print_defaults command not found. Please make sure you have this command available and in your path. The command is available from the latest MySQL distribution.
这是未设置mysql环境变量引发的,系统在执行rc.local文件后才会加载环境变量,所以需要将rc.local的内容改为
# cat /etc/rc.d/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. source /root/.bash_profile /bin/sh -x /tmp/script/tools/st_mysql>/tmp/st_mysql.log
至此,解决问题