在Linux机器上部署UOJ评测系统

前言

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

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

非常感谢以下人:

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

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

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

部署要求

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

开始部署

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

Ubuntu软件源更新

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

sudo apt update

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

sudo apt upgrade

docker服务部署

下面部署沙盒系统docker

sudo apt install curl
sudo apt install docker.io
sudo service docker start
sudo curl -sSL https://get.daocloud.io/daotools/set_mirror.sh | sh -s http://3a834d99.m.daocloud.io
sudo service docker restart

获取UOJ最新社区版

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

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

或者执行下面的指令

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

安装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

如果安装过程顺利的话,您将会看到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

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

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

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

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

sudo docker stop uoj

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

UOJ相关操作

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

打开服务器:

sudo docker start uoj

进入服务器终端:

sudo docker docker attach uoj
或者
sudo docker exec -it uoj /bin/bash

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

sudo docker stop uoj

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

sudo docker rm uoj

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

sudo docker commit uoj uoj_back

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

service apache2 restart

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

service mysql restart

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

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 uoj
sudo 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日的备份

部署GUI管理系统

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

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

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

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

sudo docker cp kod uoj:/var/www/uoj
sudo docker cp kod uoj:/var/www
sudo docker cp phpMyAdmin uoj:/var/www

然后进入attach的终端

chmod -Rf 777 ./*

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

chmod 644 /etc/mysql/my.cnf
chmod 644 /etc/mysql/conf.d/mysqld_safe_syslog.cnf
chmod 644 /etc/mysql/debian.cnf
service mysql restart

然后在浏览器输入:

localhost/kod/index.php

进入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

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

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

Listen 5678
Listen 6789

这里写图片描述

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

ln -s /etc/apache2/sites-available/001-kod.conf /etc/apache2/sites-enabled
ln -s /etc/apache2/sites-available/002-phpmy.conf /etc/apache2/sites-enabled

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

127.0.0.1:5678

来查看是否能进入KodExplorer。

在浏览器输入:

127.0.0.1:6789

来查看是否能进入phpMyAdmin。

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

rm -r /var/www/uoj/kod

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

更多内容

剩下的内容请参阅:

UOJ部署指北

猜你喜欢

转载自blog.csdn.net/rentenglong2012/article/details/70516285