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/03 Report--
How to add Linux boot script:
Configuration files that need to be loaded at system startup
/etc/profile、/root/.bash_profile
/etc/bashrc、/root/.bashrc
/etc/profile.d/*.sh、/etc/profile.d/lang.sh
/etc/sysconfig/i18n、/etc/rc.local(/etc/rc.d/rc.local)
First, modify the boot file: /etc/rc.local (or/etc/rc.d/rc.local)
# 1. Edit rc.local file [root@localhost ~]# vi /etc/rc.local # 2. Modify rc.local file by adding the following command before exit 0. Save and exit./ etc/init.d/mysqld start The requested URL/etc/init.d/nginx/was not found on this server. # nginx boot supervisor-c /etc/supervisor/supervisor.conf # supervisord boot/bin/bash /server/scripts/test.sh>/dev/null 2>/dev/null # 3. Finally modify the rc.local file execution permissions [root@localhost ~]# chmod +x /etc/rc.local[root@localhost ~]# chmod 755 /etc/rc.local
Write your own shell script.
Put the script (.sh file) in the directory/etc/profile.d/, and all shell scripts in that directory will be executed automatically after the system boots.
3. Set through chkconfig command
# 1. Move the (script) boot file to/etc/init.d/or/etc/rc.d/init.d/directory. (The former is the soft connection of the latter) mv /www/wwwroot/test.sh.d/init.d # 2. Be sure to add the following three lines of code in front of the startup file. No side will prompt chkconfig not supported.#!/ bin/sh Tell the system which shell to use, all shell scripts are like this #chkconfig: 35 20 80 This line code must be #description: http server. Do it yourself!! This line of code must be/bin/echo $(/bin/date +%F_%T) >>/tmp/test. log # 3. Add executable permissions for scripts chmod +x /etc/rc.d/init.d/test.sh # 4. Add scripts to the boot autostart project. Add to chkconfig, boot from boot. [root@localhost ~]# cd /etc/rc.d/init.d[root@localhost ~]# chkconfig --add test.sh [root@localhost ~]# chkconfig test.sh on # 5. Turn off boot [root@localhost ~]# chkconfig test.sh off # 6. Remove test.sh[root@ localhost ~]# chkconfig --del test.sh # 7. View chkconfig admin [root@localhost ~]# chkconfig --list test.sh
IV. Custom service files, added to system services, managed through Systemctl
1. Write service files such as nginx.service, redis.service, supervisor.service
[Unit]: Description of Service Description: Description of Service After: Description of Service Category [Service] Setting of Service Operating Parameters Type=forking is a background run form ExecStart Execute Reload for specific run commands of the service Restart command for service ExecuStop Stop command for service PrivateTmp=True Indicates the allocation of independent temporary space for services Note: Start, restart, stop commands all require absolute paths [Install] Settings related to service installation, which can be set to multi-user WantedBy=multi-user.target
2. File saved in directory: with 754 permissions. Directory path: /usr/lib/systemd/system. The supervisord.service file above is placed under this directory.
[root@localhost ~]# cat /usr/lib/systemd/system/nginx.service[root@localhost ~]# cat /usr/lib/systemd/system/supervisord.service
3. Set the boot to boot (execute under any directory). If an error is reported when executing the startup command, execute: systemctl daemon-reload
[root@localhost ~]# systemctl enable nginx.service [root@localhost ~]# systemctl enable supervisor Stop boot auto-boot [root@ localhost ~]# systemctl disable nginx.service[root@localhost ~]# systemctl disable supervisor Verify boot [root@localhost ~]# systemctl is-enabled nginx[root@ localhost ~]# systemctl is-enabled supervisor
4. other commands
Start nginx service [root@localhost ~]# systemctl start nginx.service Stop nginx service [root@localhost ~]# systemctl start nginx.service Restart nginx service [root@localhost ~]# systemctl restart nginx.service View nginx service current status [root@localhost ~]# systemctl status nginx.service View all started services [root@localhost ~]# systemctl list-units --type=service
5. Examples of service files:
#supervisor.service Process Management Service File [Unit]Description=Process Monitoring and Control Daemon #Content Definition: Description=Supervisor daemonAfter=rc-local.service nss-user-lookup.target [Service]Type= forkingExecuStart =/usr/bin/supervisor Executor-c /etc/supervisor/supervisor. confExecuStop = /usr/bin/supervisorctl shutdownExecuReload =/usr/bin/supervisorctl reloadRestart=on-failureRestartSec=42sKillMode=process [Install] W @ edBy =multi-user.target# nginx.service service [Unit]Description=nginx - high performance web serverAfter=network.target remote-fs.targetnss-lookup.target [Service]Type= forkingExecuStart =/usr/local/nginx/sbin/nginx Inx-c /usr/local/nginx/conf/nginx. confExecuReload =/usr/local/nginx/sbin/nginx -s reloadExecStop=/usr/local/nginx/sbin/nginx -s stop [Install]WantedBy=multi-user.target# redis.service service [Unit]Description=RedisAfter=network. remote-fs.targetnss-lookup.target [Service]Type=forkingExecStart=/usr/local/bin/redis-server /etc/redis. confExecuStop =kill -INT `cat /tmp/redis.pid`User=wwwGroup=www [Install]WantedBy=multi-user.target
So how do I add a Linux boot script? For more details, please pay attention to other related articles!
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.