forked from svn2github/hustoj
-
Notifications
You must be signed in to change notification settings - Fork 775
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #720 from renbaoshuo/master
新文档
- Loading branch information
Showing
31 changed files
with
4,477 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# 关于 | ||
|
||
|
||
HUSTOJ is an [GPL](https://github.com/zhblue/hustoj/blob/master/trunk/web/gpl-2.0.txt) Free Software. | ||
|
||
HUSTOJ 是采用GPL的自由软件。(仅限原创部分代码,其中使用了其他开源项目的组件,请遵循原组件的协议。) | ||
|
||
注意:基于本项目源码从事科研、论文、系统开发,请在文中或系统中表明来自于本项目的内容和创意。 | ||
|
||
论文请引用参考文献[基于开放式云平台的开源在线评测系统设计与实现](http://kns.cnki.net/KCMS/detail/detail.aspx?dbcode=CJFQ&dbname=CJFD2012&filename=JSJA2012S3088) | ||
|
||
> PS: GPL保证你可以合法忽略以上注意事项但不能保证你不受鄙视,呵呵。 | ||
如果这个项目对你有用,请: | ||
|
||
* 挥动鼠标,给个 Star! | ||
* 保留网站页脚的二维码。 | ||
* 访问 [tk题库](http://tk.hustoj.com) ,充值下载题目。 | ||
* 向同学同事推荐这个项目。 | ||
* 每天扫一扫本页底部的支付宝红包。 | ||
* 在您的论文参考文献中写出本项目的网址。 | ||
* 付费 50 元加入官方 QQ 群 :`23361372` 。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# 备份与还原 | ||
|
||
## 备份 | ||
|
||
脚本安装的用户,可以使用 `install` 目录中的 `bak.sh` 进行备份。 | ||
|
||
```bash | ||
sudo bash /home/judge/src/install/bak.sh | ||
``` | ||
|
||
备份后的数据在 `/var/backups/` | ||
|
||
百度学习 `crontab` 的用法后,可以使用 `sudo crontab -e` 定制自动备份计划,部分安装脚本中包含了自动备份,但可能需要运行上面的语句一次来激活。 | ||
|
||
## 还原 | ||
|
||
如果你需要进行跨系统迁移(如从 `Ubuntu` 迁移到 `CentOS`),可以尝试使用下面的脚本进行备份 | ||
|
||
```bash | ||
sudo bash /home/judge/src/install/backup+.sh | ||
``` | ||
|
||
备份后的归档在 `/home/judge/backup` ,命名格式为 `%Y-%m-%d-%H-%M-%S` | ||
|
||
将你需要迁移的归档复制到目标系统的 `/home/judge/backup` 目录下,执行下面的脚本进行恢复 | ||
|
||
```bash | ||
sudo bash /home/judge/src/install/restore+.sh | ||
``` | ||
|
||
脚本的第一个参数为恢复的目标归档,如果没有参数则默认为按名字排序后字典序最大的归档。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Core 与 Web 的连接方式解析 | ||
|
||
### 简化 ER 图 | ||
|
||
![](images/c2web.jpg) | ||
|
||
### 数据库连接(默认) | ||
|
||
1. `Web` 插入 `Solution` 表。 | ||
2. `core` 轮询 `solution` 表,发现新记录。 | ||
3. `core` 更新 `solution` 表 `result` 等字段 | ||
4. `Web` 端轮询 `soltuion` 显示 `result` 等字段。 | ||
|
||
### HTTP 方式连接 | ||
|
||
1. `Web` 插入 `Solution` 表 | ||
2. `core` 访问 `Web` 端 `admin/problem_judge.php` ,发现新纪录 | ||
3. `core` 向 `Web` 端 `admin/problem_judge.php` 提交数据,`problem_judge.php` 更新 `solution` 表 `result` 等字段。 | ||
4. `Web` 端轮询 `soltuion` 显示 `result` 等字段。 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# Core 解析 | ||
|
||
`core` 分 `3` 部分,`judged` 、 `judge_client` 、 `sim` 。源码解读:[点我](/Compostition-Code) | ||
|
||
### judged 解析 | ||
|
||
#### 简介 | ||
|
||
`judged` 为服务进程, `d` 即 `daemon`。负责轮询数据库或 `web` 端,提取判题队列。单个主机运行多个 `judged` ,分别负责不同的 `OJ` 判题。 | ||
|
||
![工作流程图](images/work.jpg) | ||
|
||
#### 基本参数 | ||
|
||
judged 可以接受一个参数作为自己的主目录,默认是 `/home/judge/` 。如: `sudo judged /home/judge/local` | ||
|
||
不指定参数将自动以单进程运行。当指定的参数不为/home/judge 时,就会有多个进程出现。 | ||
|
||
每个主目录可以有自己的 `etc/judge.conf` 数据目录可以共享,runX 目录需要独立。 | ||
|
||
#### judged 调试模式 | ||
|
||
judged 接受参数指定目录的情况下,还可以再接受一个 `debug` 作为调试模式开关。如:`sudo judged /home/judge/local debug` 调试模式的 `judged` 将不会进入后台,并且将输出大量调试信息,其调用的 `judge_client` 也工作在 `debug` 模式。 | ||
### judge_client 解析 | ||
|
||
#### 简介 | ||
|
||
当发现新任务时产生 `judge_client` 进程。 | ||
|
||
`judge_client` 进程为实际判题程序,负责准备运行环境、数据,运行并监控目标程序的系统调用,采集运行指标,判断运行结果。 | ||
|
||
![工作流程图](images/work1.jpg) | ||
|
||
#### 后台安全机制 | ||
|
||
在UNIX 中有上百个[系统调用](http://www.ibm.com/developerworks/cn/linux/kernel/syscall/part1/appendix.html),有一大部分是在用户程序运行过程中不需要的,比如说 `mkdir` `mount` 等,还有一部分会对系统造成安全隐患的,比如`fork` `kill` `exec` 等,还有一些比如 `socket` 等会造成敏感信息,比如测试数据的泄漏等。因为以上情况的存在,所以需要在运行用户程序的时候对用户加以限制,`linux` 下的 `ptrace` 在这里是一个非常好用的工具,它可以在用户态和内核态之间切换之前和之后,将进程暂停,以方便控制进程的处理,控制进程通过 `ptrace` 可以读取到当前进程想要去做什么,这样就可以在用户程序造成破坏之前将程序中止。限制非法系统调用,最好的办法是使用白名单机制,只允许程序使用一个小集合里的调用,对于其它调用,即使它是安全的,也不会被允许,比如 `mkdir` 。由于 `Pascal` `Java` `C/C++`的机制有些区别,因此,三种不同语言的白名单各不相同。 | ||
|
||
#### judge_client 调试模式 | ||
|
||
`judge_client [工作主目录] [调试]` | ||
|
||
如:`judge_client 2001 5 /home/judge/demo debug` | ||
|
||
将在 `/home/judge/demo/run5` 目录中对 `2001` 号提交进行重判,并打开调试模式,输出大量调试信息,运行后不删除中间结果。 | ||
|
||
这个模式可以帮助调试题目数据,发现数据问题和了解提交 RE 的详细错误原因。 | ||
|
||
### sim 简介 | ||
|
||
当配置为启用抄袭检查时, `judge_client` 将调用 `sim`,判断相似性结果,并写回数据库或 `web` 端。 | ||
|
||
`sim` 为第三方应用程序, 可进行语法分析判断文本相似度, 通过检验的程序将由 `judge_client` 复制进题目数据的 `ac` 目录,成为新的参考样本。 | ||
|
||
### 配置文件注释 | ||
|
||
配置文件: `judge.conf` 。 | ||
|
||
|
||
配置 | 注释 | ||
------------------------- | ------------------------------------------ | ||
`OJ_HOST_NAME=127.0.0.1` | 如果用 mysql 连接读取数据库,数据库的主机地址。 | ||
`OJ_USER_NAME=root` | 数据库帐号。 | ||
`OJ_PASSWORD=root` | 数据库密码。 | ||
`OJ_DB_NAME=jol` | 数据库名称。 | ||
`OJ_PORT_NUMBER=3306` | 数据库端口。 | ||
`OJ_RUNNING=4` | `judged` 会启动 `judge_client` 判题,这里规定最多同时运行几个 `judge_client`。 | ||
`OJ_SLEEP_TIME=5` | `judged` 通过轮询数据库发现新任务,轮询间隔的休息时间,单位为秒。 | ||
`OJ_TOTAL=1` | 老式并发处理中总的 `judged` 数量。 | ||
`OJ_MOD=0` | 老式并发处理中,本 `judged` 负责处理 `solution_id` 按照 `TOTAL` 取模后余数为几的任务。 | ||
`OJ_JAVA_TIME_BONUS=2` | Java 等虚拟机语言获得的额外运行时间。 | ||
`OJ_JAVA_MEMORY_BONUS=512` | Java 等虚拟机语言获得的额外内存。 | ||
`OJ_SIM_ENABLE=0` | 是否使用sim 进行代码相似度的检测。 | ||
`OJ_HTTP_JUDGE=0` | 是否使用 `HTTP` 方式连接数据库,如果启用,则前面的 `HOST_NAME` 等设置忽略。 | ||
`OJ_HTTP_BASEURL=http://127.0.0.1/` | 使用 `HTTP` 方式连接数据库的基础地址,就是 `OJ` 的首页地址。 | ||
`OJ_HTTP_USERNAME=admin` | 使用 `HTTP` 方式所用的用户帐号(`HTTP_JUDGE` 权限),该帐号登录时不能启用 `VCODE` 图形验证码,但可以登录成功后启用。 | ||
`OJ_HTTP_PASSWORD=admin` | 使用 `HTTP` 方式所用的用户帐号的密码 | ||
`OJ_OI_MODE=0` | 是否启用 `OI(信息学奥林匹克竞赛)` 模式,即无论是否出错都继续判剩余的数据,在 `ACM` 比赛中一旦出错就停止运行。 | ||
`OJ_SHM_RUN=0` | 是否使用 `/dev/shm` 的共享内存虚拟磁盘来运行答案,如果启用能提高判题速度,但需要较多内存。 | ||
`OJ_USE_MAX_TIME=1` | 是否使用所有测试数据中最大的运行时间作为最后运行时间,如果不启用则以所有测试数据的总时间作为超时判断依据。 | ||
`OJ_LANG_SET=0,1,2,3,4` | 判哪些语言的题目 | ||
|
Oops, something went wrong.