LINUX (CENTOS) Automatically performs script (rc.local)

1. There are many ways to boot Linux. For example, I set mysql boot to start as: chkconfig –level 35 mysqld on

Second, let’s talk about booting through the rc.local file:

1 , First create a startup script, here is redis startup as an example

Create redis-startup.sh script

#!/bin/sh


echo
"------------ -------------------------------------------------- ---------------" >> /root/start-up/redis.log
echo
-e "`date +%Y/%D/% H:%M` redis start up..." >> /root/start-up/redis.log
/usr/local/redis-5.0.5/src/redis-server /usr/local/redis-5.0.5/redis.conf >> /root/start-up/redis.log 2>&1
sleep
3
netstat
-tunpl | grep 6358 >> /root/start-up/redis.log 2>&1
echo
-e "`date +%Y/%D/% H:%M` redis start end." >> /root/start-up/redis.log
echo
-n " " >> /root/ start-up/redis.log

and set the execution permission for redis-startup.sh:

chmod +x redis-startup .sh

2, add redis-startup.sh script at the end of /etc/rc.local

# vim /etc/rc.local< span style="color: #008000;">

# Just append to the end
# /root/start-up/redis-startup.sh

and set execution permissions for rc.local

chmod +x /etc/rc.local

3. Restart and verify the result.

#!/bin /sh


echo
"------------ -------------------------------------------------- ---------------" >> /root/start-up/redis.log
echo
-e "`date +%Y/%D/% H:%M` redis start up..." >> /root/start-up/redis.log
/usr/local/redis-5.0.5/src/redis-server /usr/local/redis-5.0.5/redis.conf >> /root/start-up/redis.log 2>&1
sleep
3
netstat
-tunpl | grep 6358 >> /root/start-up/redis.log 2>&1
echo
-e "`date +%Y/%D/% H:%M` redis start end." >> /root/start-up/redis.log
echo
-n " " >> /root/ start-up/redis.log

chmod +x redis-startup.sh

# vim /etc/rc.local

# Just append to the end
#
/root/start-up/redis-startup.sh

chmod +x /etc/rc.local

Leave a Comment

Your email address will not be published.