In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail how to achieve CentOS boot automatically run their own scripts, Xiaobian feel quite practical, so share with you as a reference, I hope you can gain something after reading this article.
Operating System: CentOS-5.2
Target: boot automatically mount windows shared directory in local area network
The requested URL/etc/rc.d/was not found on this server.
Shell code
su cd /etc/rc.d/ vi rc.local
Second, add the script you want to execute to this file, and the whole content is as follows:
Shell code
#!/ 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 mount //192.168.0.3/data2-1 /mnt/data2-1 -o username=un,password=123 mount //192.168.0.3/data2-2 /mnt/data2-2 -o username=un,password=123 mount //192.168.0.3/data2-3 /mnt/data2-3 -o username=un,password=123 mount //192.168.0.3/data2-4 /mnt/data2-4 -o username=un,password=123 mount //192.168.0.3/data2-5 /mnt/data2-4 -o username=un,password=123
Tip: The practice here is very immature, I hope not, it is best to write a script file to call here, the structure is clearer, but note that the command to be executed is passed to su as a parameter.
Also review a VI editing command-copy
yy
p
3. Although it is done, it is still added
Linux will automatically execute the initialization program in the/etc/rc.d directory when it starts, so we can put the startup task in this directory. There are the following ways:
Option 1:
Simple, that is, the above approach,/etc/rc.d/directory initialization program a lot, rc.local is completed after all the initialization is executed, so it is appropriate to do something here.
Option 2:
The init.d directory is for executable programs, they are actually service scripts, written according to a certain format, Linux will automatically execute at startup, similar to Windows services.
1. Write the following script simpleTest:
Shell code
#!/ bin/bash #chkconfig:2345 80 05 --Specify which levels to execute, 0 generally refers to shutdown, 6 refers to restart, others are normal startup. #description:simple example service RETVAL=0 start(){ #entry function echo "simple example service is started... " } stop(){ #echo "simple example service is stopped... " } #Use case to select case $1 in start ;; stop ;; *) echo "error choice ! please input start or stop";; esac exit $RETVA
3. Run chmod +x /etc/rc.d/init.d/simpleTest to make it executable directly
4. Run chkconfig --add simpleTest to add the service to the configuration
5. Run chkconfig --list simpleTest to view the status of the service process.
Solution 3: The purpose is to mount the shared directory, so you can add it to/etc/fstab.
//192.168.0.3/data2-1 /mnt/data2-1 nfs username=un,password=123 0 0
Sorry, scenario 2, although the script can be run
# ./ simpleTest start
simple example service is started...
But I showed up at step four.
# chkconfig --add simpleTest
Error reading information in simpleTest service: No such file or directory
No further resolution. Sorry.
About "how to achieve CentOS boot automatically run their own scripts" this article is shared here, I hope the above content can be of some help to everyone, so that you can learn more knowledge, if you think the article is good, please share it to let more people see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.