System Requirements
Operating System: CentOS release 7.8.2003
Gocron Version: >v1.5.3
MySQL Version: 5.5
Gocron Overview
Gocron is a lightweight centralized task scheduling and management system developed in Go language, designed as an alternative to Linux crontab.
Manage Installation and Configuration
In Gocron, data is stored in a MySQL database. We need to configure the MySQL environment and permissions. If the databsae is already installed, we only need to create the necessary database and grant appropriate permissions to the user.
Manual Binary Installation
Download the appropriate version package
wget https://github.com/ouqiang/gocron/releases/download/v1.5.3/gocron-node-v1.5.3-linux-amd64.tar.gz # Download the package
# Extract and copy files to the specified directory
tar xf gocron-v1.5.3-linux-amd64.tar.gz
cd gocron-linux-amd64/
cp -a gocron /usr/local/bin/
gocron -v
Configure as a service and set auto-start
After starting the management end, the service listens on port 5920 by default.
mkdir -p /opt/gocron-manage
cat > /usr/lib/systemd/system/gocron-manage.service << EOF
[Unit]
Description=gocron web management interface
Documentation=https://github.com/ouqiang/gocron
After=network.target
[Service]
Type=simple
User=root
ExecStart=/usr/local/bin/gocron web
Restart=on-failure
WorkingDirectory=/opt/gocron-manage
[Install]
WantedBy=multi-user.target
EOF
Start the manage end and configure auto-start on boot
systemctl start gocron-manage.service \
&& systemctl status gocron-manage.service \
&& systemctl enable gocron-manage.service
Database Connection Initialization
Create database user with appropriate permissions
CREATE DATABASE `gocron` CHARACTER SET utf8mb4 COLLATE utf8mb4_bin;
grant all on `gocron`.* to task_scheduler@'%' identified by 'secure_password_here';
flush privileges;
Agent/Node Installation and Configuration
Manual Binary Installation
Installation preparation
wget https://github.com/ouqiang/gocron/releases/download/v1.5.3/gocron-node-v1.5.3-linux-amd64.tar.gz # For agent
tar xf gocron-node-v1.5.3-linux-amd64.tar.gz \
&& cd gocron-node-linux-amd64 \
&& cp gocron-node /usr/local/bin # Add to environment path
gocron-node --version # Test installation
Configure as a service and set auto-start
mkdir -p /opt/gocron-agent
cat > /usr/lib/systemd/system/gocron-agent.service << EOF
[Unit]
Description=gocron agent/node server
Documentation=https://github.com/ouqiang/gocron
After=network.target
[Service]
Type=simple
User=root
ExecStart=/usr/local/bin/gocron-node -allow-root
WorkingDirectory=/opt/gocron-agent
Restart=on-failure
[Install]
WantedBy=multi-user.target
EOF
# Enable auto-start on boot
systemctl start gocron-agent.service \
&& systemctl status gocron-agent.service \
&& systemctl enable gocron-agent.service
Note: The agent node listens on port 5921 by default (check help documentation with --help to modify the port).
Troubleshotoing
Log indicates hostname too long
The specific log error shows hostname length issues.
Solution: Modify the table structure
ALTER TABLE cron_task_log MODIFY hostname text NOT NULL;