当前位置: 首页 > 工具软件 > OnlineJudge > 使用案例 >

青岛大学OnlineJudge搭建

宗政博文
2023-12-01

OnlineJudge

环境准备

  • ubuntu 18.04
  • docker
  • docker-composer

换源

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak  

sudo vim /etc/apt/sources.list

替换内容为

deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

安装docker

apt install docker.io
apt install docker-composer

​ 换docker源

sudo vim /etc/docker/daemon.json
#替换为
{
	"registry-mirrors": ["https://docker.mirrors.ustc.edu.cn","https://mirror.ccs.tencentyun.com"]
}

安装程序

#下载
git clone -b 2.0 https://github.com/QingdaoU/OnlineJudgeDeploy.git && cd OnlineJudgeDeploy

#启动
sudo docker-compose up -d

数据备份

  • 备份

在backup文件夹下有个数据备份脚本 直接运行即可

  • 迁移
docker cp db_backup_xxxxxxx.sql oj-postgres:/root

docker exec -it oj-postgres bash

psql -U onlinejudge postgres

drop database onlinejudge;
\q
psql -f /root/db_backup_xxxxxxx.sql -U onlinejudge postgres

然后备份 /OnlineJudgeDeploy/data/backend public test_case 文件夹

请先恢复数据库再拷贝备份的publictest_case文件夹,否则在判题时会显示编译错误,点击会显示测试用例不存在。

添加判题服务器

满足以下条件

  • Token一致
  • 进行测试用例的多机同步

主机master配置

在最后添加以下内容

  oj-rsync-master:
    image: registry.cn-hangzhou.aliyuncs.com/onlinejudge/oj_rsync
    container_name: oj-rsync-master
    volumes:
      - $PWD/data/backend/test_case:/test_case:ro
      - $PWD/data/rsync_master:/log
    environment:
      - RSYNC_MODE=master
      - RSYNC_USER=ojrsync
      - RSYNC_PASSWORD=CHANGE_THIS_PASSWORD    ##这里是同步的密码
    ports:
      - "0.0.0.0:873:873"

从slave设置

删掉除了judge-server的所有service ,添加以下内容

 oj-rsync-slave:
    image: registry.cn-hangzhou.aliyuncs.com/onlinejudge/oj_rsync
    container_name: oj-rsync-slave
    volumes:
      - $PWD/data/backend/test_case:/test_case
      - $PWD/data/rsync_slave:/log
    environment:
      - RSYNC_MODE=slave
      - RSYNC_USER=ojrsync
      - RSYNC_PASSWORD=CHANGE_THIS_PASSWORD      ###这里是同步的密码
      - RSYNC_MASTER_ADDR=YOUR_BACKEND_ADDR      ###主服务器的IP地址

同步修改 RSYNC_PASSWORD,并将 RSYNC_MASTER_ADDR 修改为运行了 oj-rsync-master 服务的地址,不需要端口号,如 example.com 或者 192.168.1.10

然后给 JudgeServer 添加

  ports:
    - "0.0.0.0:80:8080"

的端口配置,同时还需要修改

  • SERVICE_URL 为新的机器的地址
  • BACKEND_URL 的域名为已部署好的主机的地址 (master地址)
  • TOKEN 和已部署好主机 TOKEN 一致。

运行 docker-compose up -d 即可启动一台新的 JudgeServer,tail -f data/rsync_slave/rsync_slave.log 可以看到测试用例同步进度,在已部署好主机的后台可以看到新的 JudgeServer 的心跳状态。

以下是示例配置

master

version: "3"
services:

  oj-redis:
    image: redis:4.0-alpine
    container_name: oj-redis
    restart: always
    volumes:
      - ./data/redis:/data

  oj-postgres:
    image: postgres:10-alpine
    container_name: oj-postgres
    restart: always
    volumes:
      - ./data/postgres:/var/lib/postgresql/data
    environment:
      - POSTGRES_DB=onlinejudge
      - POSTGRES_USER=onlinejudge
      - POSTGRES_PASSWORD=onlinejudge

  judge-server:
    image: registry.cn-hangzhou.aliyuncs.com/onlinejudge/judge_server
    container_name: judge-server
    restart: always
    read_only: true
    cap_drop:
      - SETPCAP
      - MKNOD
      - NET_BIND_SERVICE
      - SYS_CHROOT
      - SETFCAP
      - FSETID
    tmpfs:
      - /tmp
    volumes:
      - ./data/backend/test_case:/test_case:ro
      - ./data/judge_server/log:/log
      - ./data/judge_server/run:/judger
    environment:
      - SERVICE_URL=http://judge-server:8080
      - BACKEND_URL=http://oj-backend:8000/api/judge_server_heartbeat/
      - TOKEN=xxxxxx			  ###token密码要统一
      # - judger_debug=1

  oj-backend:
    image: registry.cn-hangzhou.aliyuncs.com/onlinejudge/oj_backend
    container_name: oj-backend
    restart: always
    depends_on:
      - oj-redis
      - oj-postgres
      - judge-server
    volumes:
      - ./data/backend:/data
    environment:
      - POSTGRES_DB=onlinejudge
      - POSTGRES_USER=onlinejudge
      - POSTGRES_PASSWORD=onlinejudge
      - JUDGE_SERVER_TOKEN=xxxxxx         ###token密码要统一
      # - FORCE_HTTPS=1
      # - STATIC_CDN_HOST=cdn.oj.com
    ports:
      - "0.0.0.0:80:8000"
      - "0.0.0.0:443:1443"


#master-server
  oj-rsync-master:
    image: registry.cn-hangzhou.aliyuncs.com/onlinejudge/oj_rsync
    container_name: oj-rsync-master
    volumes:
      - $PWD/data/backend/test_case:/test_case:ro
      - $PWD/data/rsync_master:/log
    environment:
      - RSYNC_MODE=master
      - RSYNC_USER=ojrsync
      - RSYNC_PASSWORD=xxxxxx    ##这里是同步的密码
    ports:
      - "0.0.0.0:873:873"

slave部署

version: "3"
services:

  judge-server:
    image: registry.cn-hangzhou.aliyuncs.com/onlinejudge/judge_server
    container_name: judge-server
    restart: always
    read_only: true
    cap_drop:
      - SETPCAP
      - MKNOD
      - NET_BIND_SERVICE
      - SYS_CHROOT
      - SETFCAP
      - FSETID
    tmpfs:
      - /tmp
    volumes:
      - ./data/backend/test_case:/test_case:ro
      - ./data/judge_server/log:/log
      - ./data/judge_server/run:/judger
    environment:
      - SERVICE_URL=http://judge-server:8080
      - BACKEND_URL=http://192.168.10.105/api/judge_server_heartbeat/  ##改成master的IP地址
      - TOKEN=xxxxxx      ###token密码要统一
      # - judger_debug=1
    ports:
      - "0.0.0.0:80:8080"

  oj-rsync-slave:
    image: registry.cn-hangzhou.aliyuncs.com/onlinejudge/oj_rsync
    container_name: oj-rsync-slave
    volumes:
      - $PWD/data/backend/test_case:/test_case
      - $PWD/data/rsync_slave:/log
    environment:
      - RSYNC_MODE=slave
      - RSYNC_USER=ojrsync
      - RSYNC_PASSWORD=xxxxxxx      ###这里是同步的密码
      - RSYNC_MASTER_ADDR=1.1.1.1   ###master的IP地址
 类似资料: