Alas, before talking about the article, let me first say something about myself. The original plan is to finish writing this article on Saturday, but on Saturday, I opened the computer, according to the usual “convention “, first fill some” black five leaf grass “/” into the giant “, and then brush brush forget to write 😔, and then browse zhihu, browse B station. Pa ground once, while I do not pay attention to 🙃, Saturday and Sunday in the past, so drag to this week just to update (set the flag is always down by their own 🤐). This Saturday and Sunday I have also written part, but found to do such a tutorial kind of article is also quite time-consuming (this article almost consumed two weekends of my time), to first build their own complete, and then each step of the operation are recorded, equivalent to writing this article, I took 2 or 3 xxL-job 🤣. However, after writing it, I felt that I had gained a lot for myself. I also reviewed the related commands of Shell and the command line startup of Java project. Later still want to refuel! Try to stick to the week! Learn from the gods.

In the last article, distributed scheduling task system research and selection, we introduced some commonly used open source distributed scheduling system, know that XXL-Job is currently the first choice of small and medium-sized companies. Therefore, this article will introduce the installation and simple use of XXL-job.

The installation is based on Ubuntu 16.04.

In addition, I do not have a title party. I have a look at GitHub open source distributed scheduling system, currently xxL-job project is the most inspiring distributed scheduling system (of course, there is also a long time because of this XXL-job)

Windows, MAC or Docker installation

If Windows or MAC is installed, you can first create a database and table according to the SQL script on Github, and then directly import the source code on Github into IDEA to start it according to the Spring Boot application.

If the installation is docker, you can directly pull the official image, and then specify MySQL and log directory at run time.

Download mirror

#The Docker address: https://hub.docker.com/r/xuxueli/xxl-job-admin/ (suggest that specify the version number)
docker pull xuxueli/xxl-job-admin
Copy the code

Create the container and run it

#To customize mysql configurations, click"-e PARAMS"Specifies the parameter format PARAMS="--key=value --key2=value2"
#Configuration items reference files: / XXL - job/XXL - job - admin/SRC/main/resources/application. The properties
#To customize JVM memory parameters, click"-e JAVA_OPTS"Specifies that the parameter format is JAVA_OPTS="-Xmx512m"Docker run - e PARAMS = "-- spring. The datasource. Url = JDBC: mysql: / / 127.0.0.1:3306 / xxl_job? useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&serverTimezone=Asia/Shanghai" -p 8080:8080 -v / TMP :/data/applogs --name xxl-job-admin -d xuxueli/xxl-job-admin:{specified version}Copy the code

Linux Ubuntu 16.04 install xxl-job

Installing xxL-job directly on Linux can be a bit tricky, because xxL-job doesn’t come with a boot package like nacos, where you modify the configuration file and run the boot script. Xxl-job is the only source file provided. If you want to run it, you need to package the Java source code through Maven to build a run package, and then run it. So I’ll go into details about how to install and start xxL-job on Linux, using Ubuntu 16.04. Other versions are similar.

Install JDK, Maven, git environment

First of all, we need to install the Java-related environment first, because xxL-job is Java development, on the basis of not providing the startup package, we need to compile from the source code interpretation into the startup package, and then start.

Install the JDK

There are two kinds of installation: one is directly installed according to apt package, the other is manually obtained Java package installation. Here we use APT to install it directly for simplicity, or manually if more custom configurations are needed. Run the following two commands to install the JDK8.

sudo apt-get update
sudo apt-get install openjdk-8-jdk -y
Copy the code

Reference: Ubuntu 16.04 Installing Java JDK8

Install maven

Here we also directly use apt package installation

sudo apt-get -y update 
sudo apt install maven -y
Copy the code

When the installation is complete, run it

mvn -v
Copy the code

Then check whether the installation is successful

You need to change maven’s default remote repository address to a local remote repository address. Otherwise, downloading maven dependencies will be slow. Open the /etc/maven/settings. XML file and add the following content in the tag to replace the default repository with the aliyun repository.

 <mirror>
      <id>alimaven</id>
      <name>aliyun maven</name>
      <url>http://maven.aliyun.com/nexus/content/groups/public/</url>
      <mirrorOf>central</mirrorOf>
 </mirror>
Copy the code

Install GIT

GIT GIT GIT GIT GIT GIT GIT GIT GIT GIT GIT GIT But Git is always useful, so we have it installed here

sudo apt-get -y update
sudo apt-get install git -y  
Copy the code

Installing the Database

The steps for initializes the database are /xxl-job/doc/db/tables_xxl_job. SQL in the xxl-job git project, connect to the MySQL server, and run the command

By default, xxl-job supports cluster deployment as long as the same database is connected

In addition, if MySQL is deployed in master/slave mode, xxl-job must be connected to the master library and do not use read/write separated accounts. Otherwise, problems may occur during scheduling

Git Clone source file, package build


git clone https://gitee.com/xuxueli0323/xxl-job.git
cd xxl-job/

mvn -B -Dmaven.test.skip=true clean package
cd xxl-job-admin/target
#The file name varies according to the xxl-job versionUnzip XXL - job - admin - 2.3.0 - the SNAPSHOT. The jar
#Properties file (' application. Properties') in BOOT-INT/target/class/ AccessToken = if you consider the security of scheduling system calls, add xxl.job. AccessToken =

#After the modification is complete, go to /xxl-job/xxl-job-admin/target and run the following command to start xxl-job 
/usr/local/java/bin/java  -classpath ./:./lib/*  org.springframework.boot.loader.JarLauncher &
Copy the code

After execution, if the startup is successful, the following image will be displayed

Then open the link: http://127.0.0.1:8080/xxl-job-admin (the actuators will be used to address, as the callback address)

Enter the default account admin/123456 to log in to the scheduling center. (You need to replace 127.0.0.1 with your own machine’S IP)

Install the actuator project

After installing the scheduling center, we also need to install the executor project. The scheduling center itself is not responsible for executing the project. After installing the executor, we can execute the executor service through the scheduling center. Xxl-job: Spring Boot: xxL-job: Spring Boot: xxL-job: Spring Boot: xxL-job: Spring Boot: xxL-job: Spring Boot: xxL-job Based on the cloned projects above, we went to the /xxl-job/xxl-job-executor-samples/xxl-job-executor-sample-springboot/target directory. You can modify the configuration file to modify the address information and authentication key of the dispatch center. The configuration file of the actuator is / XXL – job/XXL – job – executor – samples/XXL – job – executor – sample – springboot/target/BOOT – INF/classes/application. The properties.

Then execute the following command to start the executor project:

/usr/local/java/bin/java  -classpath ./:./lib/*  org.springframework.boot.loader.JarLauncher &
Copy the code

Simply use xxl-job

After the above steps, we have a simple dispatch center system. Based on this scheduling system, we can create scheduling tasks at will. Here I demonstrate a request to create a timing per minute t.weather.itboy.net/api/weather… Link to get guangzhou weather mission. Reference: free weather API, weather JSON API, unlimited times to get 15 days of weather forecast

Log in to the task management page to create a task

Visit http://127.0.0.1:8080/xxl-job-admin, input the admin / 123456. Log in to the xxL-job distributed scheduling system we have successfully built above. Then enter the “Task Management” page to create a new task.

Enter basic task information

Enter basic task information, such as retry times when a task fails, task owner, and ID of the last task that should be depended on.

In the new task dialog box that is displayed, set the following parameters:

Edit the specific execution of the task

We can edit the shell scripts we need to run using the IDE that comes with xxl-job.

After filling in the basic information of the task, we proceed to edit the script of the task to be executed.

Start tasks and query execution records

Click Save, then return to the task list to start the task. Then you can go to the “Scheduling Log” page to view the execution records of the task. Click “View Log” of a specific running instance to view the detailed log information about the execution records of the instance.

conclusion

This paper introduces the installation and simple use of distributed scheduling task system XXL-job. In fact, the whole article down, I feel quite water 😅; As a record, this distributed scheduling system, in fact, the function is quite simple, if running fewer tasks will be more relaxed and easy to use. However, it is more difficult to run complex tasks, especially those involving more logical dependencies such as aggregating by the hour to the day and triggering dependencies, or complex logic such as instances that want to delay execution and specify a time to re-run some data. In addition, the interaction between the task instance interface and the task management interface of the distributed open source scheduling system is not very good, which are displayed in the form of lists. It would be nice to change the task instance interface to select by cell date. Because our company also has a similar distributed scheduling system, but our company’s business is more complex, so our distributed scheduling task system has more functions, compared with XXL-Job has certain advantages, but also has many disadvantages.

In a word, there is no problem to use XXL-job for the scheduling tasks of most small and medium-sized companies or relatively simple scheduling tasks. If it is to be used as an enterprise-level system, it is estimated that a lot of modules need to be modified based on XXL-job. Finally, thank you very much xxL-job can open source, for my usual use to manage their own scheduling task is also very good 😊.