资源清单
依赖
ZooKeeper
集群,需要先部署ZooKeeper
依赖
Mesos
集群,需要先部署Mesos
主机 | IP |
---|---|
elasticjob节点1 | 10.0.0.1 |
elasticjob节点2 | 10.0.0.2 |
elasticjob节点3 | 10.0.0.3 |
数据库节点 | 10.0.0.4 |
软件 | 版本 |
---|---|
docker | 20.10.12 |
docker-compose | 1.23.1 |
mesos镜像 | mesosphere/mesos-master:1.7.1 |
elasticjob | elasticjob-3.0.1 |
服务 | 端口 |
---|---|
elasticjob | 8899 |
一、Docker
安装
1. 使用国内 yum
源
# yum install -y yum-utils device-mapper-persistent-data lvm2
# yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
2. 卸载旧版本的 docker
## 如果主机上已经有docker存在且不是想要安装的版本,需要先进行卸载。
# yum remove -y docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-selinux \
docker-engine-selinux \
docker-engine \
container*
3. 安装 Docker20.10
版本
# yum -y install docker-ce-20.10.12-3.el7 docker-ce-cli-20.10.12-3.el7 vim
4. 设置镜像加速
# mkdir /etc/docker
# vi /etc/docker/daemon.json
{
"registry-mirrors": ["https://xxxxxxxxx.mirror.aliyuncs.com"]
}
5. 启动 docker
# systemctl start docker
# systemctl enable docker
# systemctl status docker
二、Docker-compose
安装
1. Docker-compose
安装
## github.com 可能访问超时,可以使用下面的获取下载下来后上传服务器即可
# curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
# curl -k "https://dl.cactifans.com/zabbix_docker/docker-compose" -o /usr/bin/docker-compose
# chmod a+x /usr/bin/docker-compose
2. 查看 docker-compose
版本
# docker-compose version
三、elasticjob-cloud-scheduler
安装
elasticjob-cloud-scheduler
启动依赖 mesos 底层库,而 mesos使用 Docker部署,而需要使用含有 mesos 底层库的镜像,制作 elasticjob 镜像
1. 详细的 Dockerfile
文件信息
FROM mesosphere/mesos:1.7.1
MAINTAINER evescn
RUN apt-get update && \
apt-get -y install openjdk-8-jdk && \
java -version
ADD apache-shardingsphere-elasticjob-3.0.1-cloud-scheduler-bin.tar.gz /
COPY mysql-connector-java-8.0.29.jar /apache-shardingsphere-elasticjob-3.0.1-cloud-scheduler-bin/lib/
ENTRYPOINT ["sh", "/apache-shardingsphere-elasticjob-3.0.1-cloud-scheduler-bin/bin/start.sh"]
2. 构建镜像
# mkidr /root/elasticjob-cloud-scheduler -pv
# cd /root/elasticjob-cloud-scheduler
## 下载 elasticjob 文件
# wget https://archive.apache.org/dist/shardingsphere/elasticjob-3.0.1/apache-shardingsphere-elasticjob-3.0.1-cloud-scheduler-bin.tar.gz
## 下载 mysql-connector-java-8.0.29.jar 文件
# wget https://repo1.maven.org/maven2/mysql/mysql-connector-java/8.0.29/mysql-connector-java-8.0.29.jar
## 准备 dockerfile 文件
# cat << EOF >> Dockerfile
FROM mesosphere/mesos:1.7.1
MAINTAINER evescn
RUN apt-get update && \
apt-get -y install openjdk-8-jdk && \
java -version
ADD apache-shardingsphere-elasticjob-3.0.1-cloud-scheduler-bin.tar.gz /
COPY mysql-connector-java-8.0.29.jar /apache-shardingsphere-elasticjob-3.0.1-cloud-scheduler-bin/lib/
ENTRYPOINT ["sh", "/apache-shardingsphere-elasticjob-3.0.1-cloud-scheduler-bin/bin/start.sh"]
EOF
## 构建镜像
# docker build -t elasticjob:v3.0.1_20220428 .
3. 分发镜像到节点
# docker save elasticjob:v3.0.1_20220411 > elasticjob_v3.0.1_20220411.tar
## 连接到3台主机分别执行下面的操作
# scp elasticjob_v3.0.1_20220411.tar 10.0.0.1:/root
# ssh 10.0.0.1
# docker load < elasticjob_v3.0.1_20220411.tar
4. 创建 Event trace
日志记录数据库
mysql
数据库部署在10.0.0.4
主机,如何部署mysql
服务,请自行百度
## 连接数据库,执行以下 SQL 语句
create database elastic_job_cloud_log default character set utf8mb4 collate utf8mb4_unicode_ci;
CREATE TABLE `job_execution_log` (
`id` varchar(40) NOT NULL,
`job_name` varchar(100) NOT NULL,
`task_id` varchar(255) NOT NULL,
`hostname` varchar(255) NOT NULL,
`ip` varchar(50) NOT NULL,
`sharding_item` int(11) NOT NULL,
`execution_source` varchar(20) NOT NULL,
`failure_cause` varchar(4000) DEFAULT NULL,
`is_success` int(11) NOT NULL,
`start_time` timestamp NULL DEFAULT NULL,
`complete_time` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
CREATE TABLE `job_status_trace_log` (
`id` varchar(40) NOT NULL,
`job_name` varchar(100) NOT NULL,
`original_task_id` varchar(255) NOT NULL,
`task_id` varchar(255) NOT NULL,
`slave_id` varchar(50) NOT NULL,
`source` varchar(50) NOT NULL,
`execution_type` varchar(20) NOT NULL,
`sharding_item` varchar(100) NOT NULL,
`state` varchar(20) NOT NULL,
`message` varchar(4000) DEFAULT NULL,
`creation_time` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `TASK_ID_STATE_INDEX` (`task_id`,`state`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
5. 启动服务
3节点
均需要执行以下步骤
a
| 生成 docker-compose.yml
文件
# mkidr /data/elasticjob-cloud-scheduler/{bin,conf} -pv
# cd /data/elasticjob-cloud-scheduler
# cat << EOF >> docker-compose.yml
version: '3'
services:
elasticjob-cloud-scheduler:
image: elasticjob:v3.0.1_20220411
restart: always
network_mode: "host"
hostname: elasticjob-cloud-scheduler-1
container_name: elasticjob-cloud-scheduler-1
volumes: # 挂载数据
- /data/elasticjob-cloud-scheduler/bin/start.sh:/apache-shardingsphere-elasticjob-3.0.1-cloud-scheduler-bin/bin/start.sh
- /data/elasticjob-cloud-scheduler/conf/elasticjob-cloud-scheduler.properties:/apache-shardingsphere-elasticjob-3.0.1-cloud-scheduler-bin/conf/elasticjob-cloud-scheduler.properties
extra_hosts: # 设置容器 hosts
- "zk1:10.0.0.1"
- "zk2:10.0.0.3"
- "zk3:10.0.0.2"
EOF
b
| 解压服务包,获取配置文件
解压 步骤3中 tar.gz 包,负责软件 bin/ 和 conf 下配置文件到 /data/elasticjob-cloud-scheduler/{bin,conf}
# cd /root/elasticjob-cloud-scheduler
# tar -xvf apache-shardingsphere-elasticjob-3.0.1-cloud-scheduler-bin.tar.gz
# cp apache-shardingsphere-elasticjob-3.0.1-cloud-scheduler-bin/bin/start.sh /data/elasticjob-cloud-scheduler/bin
# cp apache-shardingsphere-elasticjob-3.0.1-cloud-scheduler-bin/conf/elasticjob-cloud-scheduler.properties /data/elasticjob-cloud-scheduler/conf/
c
| 修改启动脚本
# cat bin/start.sh
## 容器运行 source 报错,修改为 .
......
#source ${CONF_DIR}/elasticjob-cloud-scheduler.properties
. ${CONF_DIR}/elasticjob-cloud-scheduler.properties
......
d
| 修改配置文件
# cat conf/elasticjob-cloud-scheduler.properties
# Routable IP address
hostname=10.0.0.1 ## 其他服务器,修改为对应IP即可
# Username for mesos framework
user=
# Mesos zookeeper address
mesos_url=zk://javaDev:edocyunjavaDev@zk1:2181,zk2:2181,zk3:2181/mesos
# Role for mesos framework
#mesos_role=
# ElasticJob-Cloud's zookeeper address
zk_servers=zk1:2181,zk2:2181,zk3:2181
# ElasticJob-Cloud's zookeeper namespace
zk_namespace=elasticjob-cloud
# ElasticJob-Cloud's zookeeper digest
zk_digest=user:123456
# Job rest API port
http_port=8899
# Max size of job accumulated
job_state_queue_size=10000
# Event trace rdb config
event_trace_rdb_driver=com.mysql.jdbc.Driver
event_trace_rdb_url=jdbc:mysql://10.0.0.4:3306/elastic_job_cloud_log
event_trace_rdb_username=root
event_trace_rdb_password=root
# Task reconciliation interval
#reconcile_interval_minutes=-1
# Enable/Disable mesos partition aware feature
# enable_partition_aware=false
# Auth username
auth_username=root
# Auth password
auth_password=pwd
EOF
e
| 启动服务
# docker-compose up -d
6. 查看服务
登陆
Mesos
web 界面中,查看 frameworks 页面
访问任意节点url地址:http://10.0.0.1:5050/
,会自动跳转到 Leader
节点,再访问 http://master:5050/#/frameworks