docker-compose安装xxl-job

docker能安装的docker-compose肯定就能安装,锻炼一下写yml的能力。

后面再具体写实际中的应用

[root@localhost mysql]# cat docker-compose.yml
version: '2'
services:
  mysql01: #服务名称(不是容器名,名称最好不要含有特殊字符,碰到过用下划线时运行出错)
    image: docker.io/mysql:5.6.40
    container_name: mysql01 #容器名称
    ports:
      - "3307:3306" #暴露的端口信息和docker run -d -p 80:80一样
    environment: #设置镜像变量,它可以保存变量到镜像里面
      MYSQL_USER: 'root'
      MYSQL_PASS: 123456
      MYSQL_ROOT_PASSWORD: 123456
    volumes:
      - "/opt/mysql/:/docker-entrypoint-initdb.d/"
    networks: #加入指定网络
      - xxl_job
  xxljob01:
    image: docker.io/xuxueli/xxl-job-admin:2.1.2
    container_name: xxljob01
    ports:
      - "8081:8080"
    environment:
      PARAMS: '--spring.datasource.url=jdbc:mysql://192.168.180.117:3307/xxl_job?Unicode=true&characterEncoding=UTF-8 --spring.datasource.username=root  --spring.datasource.password=123456'
    networks:
      - xxl_job
    depends_on:
      - mysql01
networks:
  xxl_job:
    driver: bridge
[root@localhost mysql]#

配置文件

[root@localhost mysql]# ll
总用量 12
-rw-r--r-- 1 root root 1010 12月 14 20:30 docker-compose.yml
-rw-r--r-- 1 root root 6711 12月 13 18:51 init.sql
[root@localhost mysql]# pwd
/opt/mysql
[root@localhost mysql]# cat init.sql
CREATE database if NOT EXISTS `xxl_job` default character set utf8mb4 collate utf8mb4_unicode_ci;
use `xxl_job`;


CREATE TABLE `xxl_job_info` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `job_group` int(11) NOT NULL COMMENT 'Ö´ÐÐÆ÷Ö÷¼üID',
  `job_cron` varchar(128) NOT NULL COMMENT 'ÈÎÎñÖ´ÐÐCRON',
  `job_desc` varchar(255) NOT NULL,
  `add_time` datetime DEFAULT NULL,
  `update_time` datetime DEFAULT NULL,
  `author` varchar(64) DEFAULT NULL COMMENT '×÷Õß',
  `alarm_email` varchar(255) DEFAULT NULL COMMENT '±¨¾¯Óʼþ',
  `executor_route_strategy` varchar(50) DEFAULT NULL COMMENT 'Ö´ÐÐÆ÷·ÓɲßÂÔ',
  `executor_handler` varchar(255) DEFAULT NULL COMMENT 'Ö´ÐÐÆ÷ÈÎÎñhandler',
  `executor_param` varchar(512) DEFAULT NULL COMMENT 'Ö´ÐÐÆ÷ÈÎÎñ²ÎÊý',
  `executor_block_strategy` varchar(50) DEFAULT NULL COMMENT '×èÈû´¦Àí²ßÂÔ',
  `executor_timeout` int(11) NOT NULL DEFAULT '0' COMMENT 'ÈÎÎñÖ´Ðг¬Ê±Ê±¼ä£¬µ¥Î»Ãë',
  `executor_fail_retry_count` int(11) NOT NULL DEFAULT '0' COMMENT 'ʧ°ÜÖØÊÔ´ÎÊý',
  `glue_type` varchar(50) NOT NULL COMMENT 'GLUEÀàÐÍ',
  `glue_source` mediumtext COMMENT 'GLUEÔ´´úÂë',
  `glue_remark` varchar(128) DEFAULT NULL COMMENT 'GLUE±¸×¢',
  `glue_updatetime` datetime DEFAULT NULL COMMENT 'GLUE¸üÐÂʱ¼ä',
  `child_jobid` varchar(255) DEFAULT NULL COMMENT '×ÓÈÎÎñID£¬¶à¸ö¶ººÅ·Ö¸ô',
  `trigger_status` tinyint(4) NOT NULL DEFAULT '0' COMMENT 'µ÷¶È״̬£º0-Í£Ö¹£¬1-ÔËÐÐ',
  `trigger_last_time` bigint(13) NOT NULL DEFAULT '0' COMMENT 'Éϴε÷¶Èʱ¼ä',
  `trigger_next_time` bigint(13) NOT NULL DEFAULT '0' COMMENT 'Ï´ε÷¶Èʱ¼ä',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE `xxl_job_log` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `job_group` int(11) NOT NULL COMMENT 'Ö´ÐÐÆ÷Ö÷¼üID',
  `job_id` int(11) NOT NULL COMMENT 'ÈÎÎñ£¬Ö÷¼üID',
  `executor_address` varchar(255) DEFAULT NULL COMMENT 'Ö´ÐÐÆ÷µØÖ·£¬±¾´ÎÖ´ÐеĵØÖ·',
  `executor_handler` varchar(255) DEFAULT NULL COMMENT 'Ö´ÐÐÆ÷ÈÎÎñhandler',
  `executor_param` varchar(512) DEFAULT NULL COMMENT 'Ö´ÐÐÆ÷ÈÎÎñ²ÎÊý',
  `executor_sharding_param` varchar(20) DEFAULT NULL COMMENT 'Ö´ÐÐÆ÷ÈÎÎñ·ÖƬ²ÎÊý£¬¸ñʽÈç 1/2',
  `executor_fail_retry_count` int(11) NOT NULL DEFAULT '0' COMMENT 'ʧ°ÜÖØÊÔ´ÎÊý',
  `trigger_time` datetime DEFAULT NULL COMMENT 'µ÷¶È-ʱ¼ä',
  `trigger_code` int(11) NOT NULL COMMENT 'µ÷¶È-½á¹û',
  `trigger_msg` text COMMENT 'µ÷¶È-ÈÕÖ¾',
  `handle_time` datetime DEFAULT NULL COMMENT 'Ö´ÐÐ-ʱ¼ä',
  `handle_code` int(11) NOT NULL COMMENT 'Ö´ÐÐ-״̬',
  `handle_msg` text COMMENT 'Ö´ÐÐ-ÈÕÖ¾',
  `alarm_status` tinyint(4) NOT NULL DEFAULT '0' COMMENT '¸æ¾¯×´Ì¬£º0-ĬÈÏ¡¢1-ÎÞÐè¸æ¾¯¡¢2-¸æ¾¯³É¹¦¡¢3-¸æ¾¯Ê§°Ü',
  PRIMARY KEY (`id`),
  KEY `I_trigger_time` (`trigger_time`),
  KEY `I_handle_code` (`handle_code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE `xxl_job_log_report` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `trigger_day` datetime DEFAULT NULL COMMENT 'µ÷¶È-ʱ¼ä',
  `running_count` int(11) NOT NULL DEFAULT '0' COMMENT 'ÔËÐÐÖÐ-ÈÕÖ¾ÊýÁ¿',
  `suc_count` int(11) NOT NULL DEFAULT '0' COMMENT 'Ö´Ðгɹ¦-ÈÕÖ¾ÊýÁ¿',
  `fail_count` int(11) NOT NULL DEFAULT '0' COMMENT 'Ö´ÐÐʧ°Ü-ÈÕÖ¾ÊýÁ¿',
  PRIMARY KEY (`id`),
  UNIQUE KEY `i_trigger_day` (`trigger_day`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE `xxl_job_logglue` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `job_id` int(11) NOT NULL COMMENT 'ÈÎÎñ£¬Ö÷¼üID',
  `glue_type` varchar(50) DEFAULT NULL COMMENT 'GLUEÀàÐÍ',
  `glue_source` mediumtext COMMENT 'GLUEÔ´´úÂë',
  `glue_remark` varchar(128) NOT NULL COMMENT 'GLUE±¸×¢',
  `add_time` datetime DEFAULT NULL,
  `update_time` datetime DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE `xxl_job_registry` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `registry_group` varchar(50) NOT NULL,
  `registry_key` varchar(255) NOT NULL,
  `registry_value` varchar(255) NOT NULL,
  `update_time` datetime DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `i_g_k_v` (`registry_group`,`registry_key`,`registry_value`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE `xxl_job_group` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `app_name` varchar(64) NOT NULL COMMENT 'Ö´ÐÐÆ÷AppName',
  `title` varchar(12) NOT NULL COMMENT 'Ö´ÐÐÆ÷Ãû³Æ',
  `order` int(11) NOT NULL DEFAULT '0' COMMENT 'ÅÅÐò',
  `address_type` tinyint(4) NOT NULL DEFAULT '0' COMMENT 'Ö´ÐÐÆ÷µØÖ·ÀàÐÍ£º0=×Ô¶¯×¢²á¡¢1=ÊÖ¶¯Â¼Èë',
  `address_list` varchar(512) DEFAULT NULL COMMENT 'Ö´ÐÐÆ÷µØÖ·ÁÐ±í£¬¶àµØÖ·¶ººÅ·Ö¸ô',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE `xxl_job_user` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `username` varchar(50) NOT NULL COMMENT 'Õ˺Å',
  `password` varchar(50) NOT NULL COMMENT 'ÃÜÂë',
  `role` tinyint(4) NOT NULL COMMENT '½ÇÉ«£º0-ÆÕͨÓû§¡¢1-¹ÜÀíÔ±',
  `permission` varchar(255) DEFAULT NULL COMMENT 'ȨÏÞ£ºÖ´ÐÐÆ÷IDÁÐ±í£¬¶à¸ö¶ººÅ·Ö¸î',
  PRIMARY KEY (`id`),
  UNIQUE KEY `i_username` (`username`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

CREATE TABLE `xxl_job_lock` (
  `lock_name` varchar(50) NOT NULL COMMENT 'ËøÃû³Æ',
  PRIMARY KEY (`lock_name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;


INSERT INTO `xxl_job_group`(`id`, `app_name`, `title`, `order`, `address_type`, `address_list`) VALUES (1, 'xxl-job-executor-sample', 'ʾÀýÖ´ÐÐÆ÷', 1, 0, NULL);
INSERT INTO `xxl_job_info`(`id`, `job_group`, `job_cron`, `job_desc`, `add_time`, `update_time`, `author`, `alarm_email`, `executor_route_strategy`, `executor_handler`, `executor_param`, `executor_block_strategy`, `executor_timeout`, `executor_fail_retry_count`, `glue_type`, `glue_source`, `glue_remark`, `glue_updatetime`, `child_jobid`) VALUES (1, 1, '0 0 0 * * ? *', '²âÊÔÈÎÎñ1', '2018-11-03 22:21:31', '2018-11-03 22:21:31', 'XXL', '', 'FIRST', 'demoJobHandler', '', 'SERIAL_EXECUTION', 0, 0, 'BEAN', '', 'GLUE´úÂë³õʼ»¯', '2018-11-03 22:21:31', '');
INSERT INTO `xxl_job_user`(`id`, `username`, `password`, `role`, `permission`) VALUES (1, 'admin', 'e10adc3949ba59abbe56e057f20f883e', 1, NULL);
INSERT INTO `xxl_job_lock` ( `lock_name`) VALUES ( 'schedule_lock');

commit;
[root@localhost mysql]#

由于mysql在初始化的时候会执行这个文件,因此只要做个数据卷映射就可以了。

[root@localhost mysql]# docker-compose ps
  Name                Command               State           Ports
--------------------------------------------------------------------------
mysql01    docker-entrypoint.sh mysqld      Up      0.0.0.0:3307->3306/tcp
xxljob01   sh -c java -jar /app.jar $ ...   Up      0.0.0.0:8081->8080/tcp
[root@localhost mysql]#

原文地址:https://www.cnblogs.com/dalianpai/p/12040842.html