Linux scheduled task access page replaces quartz cluster_html/css_WEB-ITnose

WBOY
Release: 2016-06-24 11:58:18
Original
1179 people have browsed it

Business background:

There are often businesses in the web that need to be executed regularly. However, in a cluster environment, if scheduled tasks in multiple servers are started at the same time, the database will hang.

It should actually work. Only one scheduled task accesses the database.

How to solve this problem:

1. In a multi-server cluster, the directory is mounted. Only one server stores scheduled tasks. When mounting, exclude the configuration file of scheduled tasks and only allow one server to enable scheduled tasks.

2. Deploy a separate server to run scheduled tasks

3. Use a Linux script to access the cluster server page or action. There must be a server that receives the request and then executes the scheduled task.

What I want to talk about here is the third method. The disadvantage is that the pages or actions of the accessed server need to be subject to security restrictions.


First, configure the linux scheduled task:

vi /etc/crondtab

                  <p class="sycode">                      <p class="sycode">       0 1 * * * root /dbdata/backup/cms/async.sh      </p>                  </p>
Copy after login

Then in async.sh, if there is an error in the request, send an email to alert:

              <p class="sycode">                  <p class="sycode">      #!/bin/bash     </p>                  <p class="sycode">      Dir="/home/webtrn/CrontabDir"     </p>                  <p class="sycode">      echo `date +"%Y-%m-%d-%H-%M"` >> $Dir/checklearntime.log     </p>                  <p class="sycode">      wget -t1 http://www.baidu.com/checkserver/XXX.jsp -o $Dir/wgetchecklearntime.log     </p>                  <p class="sycode">      grep -q "404" $Dir/wgetchecklearntime.log || grep -q "302" $Dir/wgetchecklearntime.log     </p>                  <p class="sycode">      if [ $? != 0 ]; then     </p>                  <p class="sycode">      echo "checklearntime have done" >> $Dir/checklearntime.log     </p>                  <p class="sycode">      else     </p>                  <p class="sycode">      echo "checklearntime is error" >> $Dir/checklearntime.log     </p>                  <p class="sycode">      echo "checklearntime is error" | mail -s "webtrn" zhugaojian@whaty.com     </p>                  <p class="sycode">      echo "checklearntime is error" | mail -s "webtrn" jinqingwen@whaty.com     </p>                  <p class="sycode">      fi     </p>                  <p class="sycode">      rm -f XXX.jsp     </p>                  <p class="sycode">      rm -f $Dir/wgetchecklearntime.log     </p>              </p>
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!