UOJ评测系统部署指北

来源:互联网 发布:免费淘宝装修模板 编辑:程序博客网 时间:2024/06/09 23:30

前言

想要部署一套OJ,然后就选了UOJ。

但是由于服务器还要一段时间(永远)才能到,所以就先拿了一台电脑作为试验机进行内网部署测试。

非常感谢以下人:

  • vfleaking 无私开放了UOJ的源码
  • 阮行止 维护社区版本UOJ源码并且提供大量帮助
  • 湘江一桥 维护社区版本UOJ源码并且提供大量帮助
  • 其他提供帮助的人

这篇部署教程就是第一来帮助更多人,第二。。。帮自己在正式部署的时候不会乱了阵脚。。。

另外,大量引用了UOJ部署指北中的内容。

部署要求

电脑一个。。。 
Ubuntu 16.04LTS 64位 简体中文版 
校园网络一个。。。 
Universal Online Judge 源码一套。。。 
UOJ部署指北一份。。。

开始部署

首先安装好Ubuntu的各软件。。。

Ubuntu软件源更新

更新软件源以确保获取最新的Docker。

sudo apt update
  • 1
  • 1

然后更新机上的软件。。。这一步其实无所谓。

sudo apt upgrade
  • 1
  • 1

docker服务部署

下面部署沙盒系统docker

sudo apt install curlsudo apt install docker.iosudo service docker startsudo curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://3a834d99.m.daocloud.iosudo service docker restart
  • 1
  • 2
  • 3
  • 4
  • 5
  • 1
  • 2
  • 3
  • 4
  • 5

获取UOJ最新社区版

UOJ的社区版被保存在GitHub中。

可以登录这个地址进行下载。

或者执行下面的指令

git clone https://github.com/UniversalOJ/UOJ-System.git
  • 1
  • 1

安装UOJ

然后在终端使用 cd命令 转到你刚才下载的文件夹。

如果您需要支持Java,请下载这两个文件:

  • JDK7u76
  • JDK8u31

然后把它们放进UOJ-System/docker/目录,替换掉jdk-7u76-Linux-x64.tar.gz和jdk-8u31-linux-x64.tar.gz。

在2017-4-23之前的版本是在 home → UOJ-System 文件夹中。你应该能看到这个文件夹中有一个“install”文件。

请注意,不要转到这个文件夹的docker文件夹!

转到UOJ-System文件夹,然后输入指令:

sudo bash ./install
  • 1
  • 1

如果安装过程顺利的话,您将会看到Successfully built。


继续安装

刚才咱们安装的是一个docker的镜像,你可以理解为一张光盘,里面有安装程序。

下面,咱们安装这个“光盘”。

运行下面的指令:

sudo docker run --name uoj -dit -p 80:80 -p 3690:3690 -p 5678:5678 -p 6789:6789 --cap-add SYS_PTRACE uoj
  • 1
  • 1

我这里比部署指北多了两个端口5678和6789,这两个端口可以根据需要更改或者删减。我在这里开放这两个端口的目的是使用Kodexplorer和PhpMyAdmin来管理网站。

3690必不可少,它是传输题目数据所必须的端口。

接下来这个容器将在后台运行,你可以在浏览器输入localhost或127.0.0.1来访问它。

调用下面的命令来关闭它:

sudo docker stop uoj
  • 1
  • 1

至此,UOJ相关部署工作已经基本完成。UOJ-System文件夹到此已完成使命,所有操作将于此文件夹无关。

UOJ相关操作

由于服务器安置在docker下,需要docker命令进行管理。

打开服务器:

sudo docker start uoj
  • 1
  • 1

进入服务器终端:

sudo docker docker attach uoj或者sudo docker exec -it uoj /bin/bash
  • 1
  • 2
  • 3
  • 1
  • 2
  • 3

关闭服务器(请在新的终端中执行):

sudo docker stop uoj
  • 1
  • 1

删除建立的UOJ容器(慎重使用!操作不可逆!):

sudo docker rm uoj
  • 1
  • 1

保存UOJ的服务器为”uoj_back”镜像:

sudo docker commit uoj uoj_back
  • 1
  • 1

重启apache服务(在刚才attach的终端中进行):

service apache2 restart
  • 1
  • 1

重启MySQL服务(在刚才attach的终端中进行):

service mysql restart
  • 1
  • 1

一次典型的数据备份与恢复程序:

docker commit uoj uoj_back_20170101     # 例行备份docker commit uoj uoj_back_20170201     # 例行备份docker commit uoj uoj_back_20170301     # 例行备份# 3月15日,黑恶势力破坏了uoj,uoj容器已经无用,必须恢复sudo docker stop uojsudo docker rm uoj                      # 删除uoj容器sudo docker run --name uoj -dit -p 80:80 -p 3690:3690 -p 5678:5678 -p 6789:6789 --cap-add SYS_PTRACE uoj_back_20170301# 创建新的uoj容器,使用3月1日的备份
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

部署GUI管理系统

下面就是部署指北中没有的部分~~~

在这里下载KODExplorer管理系统。 
在这里下载phpMyAdmin数据库管理系统。

下载完成后,解压两个文件,并分别命名为“kod”和“phpMyAdmin”。

然后在服务器启动的情况下,在新终端转到解压两个文件夹的位置并执行下列三个命令:

sudo docker cp kod uoj:/var/www/uojsudo docker cp kod uoj:/var/wwwsudo docker cp phpMyAdmin uoj:/var/www
  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4

然后进入attach的终端

chmod -Rf 777 ./*
  • 1
  • 1

此时会因配置文件权限问题而导致网站部分中文数据乱码。然后进入服务器终端,依次输入以下指令来解决此问题:

chmod 644 /etc/mysql/my.cnfchmod 644 /etc/mysql/conf.d/mysqld_safe_syslog.cnfchmod 644 /etc/mysql/debian.cnfservice mysql restart
  • 1
  • 2
  • 3
  • 4
  • 1
  • 2
  • 3
  • 4

然后在浏览器输入:

localhost/kod/index.php
  • 1
  • 1

进入KODExplorer系统进行图形化文件管理。

这里写图片描述

用户名admin,密码在刚登录的时候会让你设置。

然后进入管理系统。

转到etc/apache2/sites-available,在该目录下创建两个文件

  • 001-kod.conf
  • 002-phpmy.conf

这里写图片描述

内容如下:

001-kod.conf:

<VirtualHost *:5678>    # The ServerName directive sets the request scheme, hostname and port that    # the server uses to identify itself. This is used when creating    # redirection URLs. In the context of virtual hosts, the ServerName    # specifies what hostname must appear in the request's Host: header to    # match this virtual host. For the default virtual host (this file) this    # value is not decisive as it is used as a last resort host regardless.    # However, you must set it for any further virtual host explicitly.    #ServerName www.example.com    ServerAdmin admin    DocumentRoot /var/www/kod    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,    # error, crit, alert, emerg.    # It is also possible to configure the loglevel for particular    # modules, e.g.    #LogLevel info ssl:warn    # For most configuration files from conf-available/, which are    # enabled or disabled at a global level, it is possible to    # include a line for only one particular virtual host. For example the    # following line enables the CGI configuration for this host only    # after it has been globally disabled with "a2disconf".    #Include conf-available/serve-cgi-bin.conf</VirtualHost># vim: syntax=apache ts=4 sw=4 sts=4 sr noet
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29

002-phpmy.conf:

<VirtualHost *:6789>    # The ServerName directive sets the request scheme, hostname and port that    # the server uses to identify itself. This is used when creating    # redirection URLs. In the context of virtual hosts, the ServerName    # specifies what hostname must appear in the request's Host: header to    # match this virtual host. For the default virtual host (this file) this    # value is not decisive as it is used as a last resort host regardless.    # However, you must set it for any further virtual host explicitly.    #ServerName www.example.com    ServerAdmin vfleaking@163.com    DocumentRoot /var/www/phpMyAdmin    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,    # error, crit, alert, emerg.    # It is also possible to configure the loglevel for particular    # modules, e.g.    #LogLevel info ssl:warn    ErrorLog ${APACHE_LOG_DIR}/phpMyAdmin_error.log    CustomLog ${APACHE_LOG_DIR}/phpMyAdmin_access.log combined    # For most configuration files from conf-available/, which are    # enabled or disabled at a global level, it is possible to    # include a line for only one particular virtual host. For example the    # following line enables the CGI configuration for this host only    # after it has been globally disabled with "a2disconf".    #Include conf-available/serve-cgi-bin.conf</VirtualHost># vim: syntax=apache ts=4 sw=4 sts=4 sr noet
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32

然后转到etc/apache2文件夹,打开ports.conf文件,并在“Listen 80”后面加入:

Listen 5678Listen 6789
  • 1
  • 2
  • 1
  • 2

这里写图片描述

然后回到attach的终端,输入:

ln -s /etc/apache2/sites-available/001-kod.conf /etc/apache2/sites-enabledln -s /etc/apache2/sites-available/002-phpmy.conf /etc/apache2/sites-enabled
  • 1
  • 2
  • 1
  • 2

然后重启服务器。在浏览器输入:

127.0.0.1:5678
  • 1
  • 1

来查看是否能进入KodExplorer。

在浏览器输入:

127.0.0.1:6789
  • 1
  • 1

来查看是否能进入phpMyAdmin。

如果回答都是“是”,那么进入attach的终端,执行:

rm -r /var/www/uoj/kod
  • 1
  • 1

至此,图形化管理界面已经全部部署完成。

更多内容

剩下的内容请参阅:

UOJ部署指北