hustoj安装

现在安装hustoj,在网上搜索到的博客很多都是一步一步安装的,但是这种安装方式存在一些问题,装完Apache2,数据库,PHP,然后安装SVN时会发现网上很多链接失效了,然后继续找其他安装方法,最后在GitHub发现
hustoj安装_第1张图片

然后发现,直接用上边的脚本直接一键安装就行了…..
这点就不废话了,原文下载脚本和运行脚本命令如下:
Ubuntu14.04快速安装OJ:

wget https://raw.githubusercontent.com/zhblue/hustoj/master/trunk/install/install-ubuntu14.04.sh
sudo bash install-ubuntu14.04.sh

ubuntu16.04快速安装OJ:

wget https://raw.githubusercontent.com/zhblue/hustoj/master/trunk/install/install-ubuntu`16+.sh`
sudo bash install-ubuntu16+.sh

ubuntu18.04(存在bug)

wget https://github.com/zhblue/hustoj/raw/master/trunk/install/install-ubuntu18.04.sh
sudo bash install-ubuntu18.04.sh

centos7 (有的语言可能不支持)快速安装OJ:

wget https://raw.githubusercontent.com/zhblue/hustoj/master/trunk/install/install-centos7.sh
sudo bash install-centos7.sh

注:安装脚本时如果之前安装过数据库,运行脚本时不会重复安装,只会更新之前的数据库版本,如果未安装,运行脚本时一般会弹出界面设置数据库账号和密码设置的提示。但是,还存在一种情况,数据库之前没有安装过,但是运行脚本时也没弹出设置提示,这点也是这个脚本安装oj时存在的问题。

本来想着用脚本一键安装,这么简单么???
结果在安装过程中,遇到了一堆问题。
1:安装过程中会提示无法创建run0,run1,run2,run3文件。查了一下,这点对oj安装基本上没有影响,因为这几个文件应该是辅助oj判题时用的,可以后边手动修改。

2.脚本执行到最后会出现有几个文件无法连接,这点装了很多次,全都报错,但是在oj安装后没有影响使用,这点查也没查出解决方法。

3.如果是直接跑脚本,会发现安装完成后,oj界面可以打开,浏览器左上角有oj图标,但是界面是空白,这点一般是数据库没有连接,此时如果打开/home/judge/src/web/include/目录下的db_info.inc.php文件,会发现
这里写图片描述
DBUSER=; D B U S E R = ” “ ; DB_PASS=”“;
这两行引号之间没有任何东西,这两行本来应该是需要连接的数据库的账号和密码,把之前设置的数据库账号和密码填上,刷新oj界面,然后oj界面就能显示了。

因为安装过程中一直遇到问题,而且一块留校学习的几个人每个人安装出现的问题都不一样,然后就跑去看脚本内容,因为电脑装的是Ubuntu16.04,下载的是16.04的脚本。脚本内容如下:

#!/bin/bash
apt-get update
apt-get install -y subversion
/usr/sbin/useradd -m -u 1536 judge
cd /home/judge/

svn co https://github.com/zhblue/hustoj/trunk/trunk/  src
apt-get install -y make flex g++ clang libmysqlclient-dev libmysql++-dev php-fpm php-common php-xml-parser nginx mysql-server php-mysql php-gd php-zip fp-compiler openjdk-8-jdk mono-devel php-mbstring php-xml
apt-get install -y php-memcache memcached
USER=`cat /etc/mysql/debian.cnf |grep user|head -1|awk  '{print $3}'`
PASSWORD=`cat /etc/mysql/debian.cnf |grep password|head -1|awk  '{print $3}'`
CPU=`grep "cpu cores" /proc/cpuinfo |head -1|awk '{print $4}'`

mkdir etc data log

cp src/install/java0.policy  /home/judge/etc
cp src/install/judge.conf  /home/judge/etc
chmod +x src/install/ans2out

if grep "OJ_SHM_RUN=0" etc/judge.conf ; then
    mkdir run0 run1 run2 run3
    chown www-data run0 run1 run2 run3
fi

sed -i "s/OJ_USER_NAME=root/OJ_USER_NAME=$USER/g" etc/judge.conf
sed -i "s/OJ_PASSWORD=root/OJ_PASSWORD=$PASSWORD/g" etc/judge.conf
sed -i "s/OJ_COMPILE_CHROOT=1/OJ_COMPILE_CHROOT=0/g" etc/judge.conf
sed -i "s/OJ_RUNNING=1/OJ_RUNNING=$CPU/g" etc/judge.conf

chmod 700 etc/judge.conf

sed -i "s/DB_USER=\"root\"/DB_USER=\"$USER\"/g" src/web/include/db_info.inc.php
sed -i "s/DB_PASS=\"root\"/DB_PASS=\"$PASSWORD\"/g" src/web/include/db_info.inc.php
chmod 700 src/web/include/db_info.inc.php
chown www-data src/web/include/db_info.inc.php
chown www-data src/web/upload data run0 run1 run2 run3
if grep client_max_body_size /etc/nginx/nginx.conf ; then 
    echo "client_max_body_size already added" ;
else
    sed -i "s:include /etc/nginx/mime.types;:client_max_body_size    80m;\n\tinclude /etc/nginx/mime.types;:g" /etc/nginx/nginx.conf
fi

mysql -h localhost -u$USER -p$PASSWORD < src/install/db.sql
echo "insert into jol.privilege values('admin','administrator','N');"|mysql -h localhost -u$USER -p$PASSWORD 

sed -i "s:root /var/www/html;:root /home/judge/src/web;:g" /etc/nginx/sites-enabled/default
sed -i "s:index index.html:index index.php:g" /etc/nginx/sites-enabled/default
sed -i "s:#location ~ \\\.php\\$:location ~ \\\.php\\$:g" /etc/nginx/sites-enabled/default
sed -i "s:#\tinclude snippets:\tinclude snippets:g" /etc/nginx/sites-enabled/default
sed -i "s|#\tfastcgi_pass unix|\tfastcgi_pass unix|g" /etc/nginx/sites-enabled/default
sed -i "s:}#added_by_hustoj::g" /etc/nginx/sites-enabled/default
sed -i "s|# deny access to .htaccess files|}#added by hustoj\n\n\n\t# deny access to .htaccess files|g" /etc/nginx/sites-enabled/default
/etc/init.d/nginx restart
sed -i "s/post_max_size = 8M/post_max_size = 80M/g" /etc/php/7.0/fpm/php.ini
sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 80M/g" /etc/php/7.0/fpm/php.ini

COMPENSATION=`grep 'mips' /proc/cpuinfo|head -1|awk -F: '{printf("%.2f",$2/5000)}'`
sed -i "s/OJ_CPU_COMPENSATION=1.0/OJ_CPU_COMPENSATION=$COMPENSATION/g" etc/judge.conf

/etc/init.d/php7.0-fpm restart
service php7.0-fpm restart

cd src/core
chmod +x ./make.sh
./make.sh
if grep "/usr/bin/judged" /etc/rc.local ; then
    echo "auto start judged added!"
else
    sed -i "s/exit 0//g" /etc/rc.local
    echo "/usr/bin/judged" >> /etc/rc.local
    echo "exit 0" >> /etc/rc.local
fi
if grep "bak.sh" /var/spool/cron/crontabs/root ; then
    echo "auto backup added!"
else
    echo "1 0 * * * /home/judge/src/install/bak.sh" >> /var/spool/cron/crontabs/root
fi
ln -s /usr/bin/mcs /usr/bin/gmcs

/usr/bin/judged
cp /home/judge/src/install/hustoj /etc/init.d/hustoj
update-rc.d hustoj defaults

因为只学了点Linux命令,还没学脚本语言,看了看,还能看懂一点,安装软件和移动文件之类的差不多都能看懂,于是试着提前安软件,再运行脚本,但是安装时run0,run1,run2,run3还是不能创建,然后根据脚本:

if grep "OJ_SHM_RUN=0" etc/judge.conf ; then
    mkdir run0 run1 run2 run3
    chown www-data run0 run1 run2 run3
fi

发现当”OJ_SHM_RUN=0”数值等于0时才创建,但是打开文件judge.conf发现这个变量数值即使修改,但是只要重新安装,一直都是1(这点我觉得是网站资源的问题),而这个文件是执行脚本中这一句创建的:

svn co https://github.com/zhblue/hustoj/trunk/trunk/  src

也就是说脚本只要执行这一行,这个变量都是1,于是去网上查judge.conf文件内所有数据的解释:

OJ_SHM_RUN=0 是否使用/dev/shm的共享内存虚拟磁盘来运行答案,如果启用能提高判题速度,但需要较多内存。  

发现这个变量是设置是否提高判题速度的,应该是可以后期可以按照脚本执行内容手动加的。

然后因为数据库一直在oj安装过程中存在一些错误,经常是执行脚本时没有安装数据库,于是试了一些执行脚本之前提前安装数据库,发现这样安装,在脚本执行完成后,数据库是不存在问题的。

在安装oj过程中,安装完成后遇到过以下问题:
1.无法连接数据库
2.安装完成后网站无法打开
3.安装过程中安装nginx报错,而且无法重新安装
4.界面都能显示,也能注册用户,但是oj判题时无限等待,重启judged也没用

于是试了一下提前把所以软件全部更新升级,同时把数据库,PHP在执行脚本之前安装,这次虽然创建run0,run1,run2,run3和最后连接文件还是报错,但是oj可以正常打开,判题,申请账号。
于是安照这个思路把脚本改了一下:

#!/bin/bash
apt-get update   #取回更新的软件包列表信息
apt-get upgrade  #进行一次升级
apt-get install php7.0 #安装PHP7.0
apt-get install mysql-server mysql-client #安装数据库
apt-get install -y subversion
/usr/sbin/useradd -m -u 1536 judge
cd /home/judge/

svn co https://github.com/zhblue/hustoj/trunk/trunk/  src
apt-get install -y make flex g++ clang libmysqlclient-dev libmysql++-dev php-fpm php-common php-xml-parser nginx php-mysql php-gd php-zip fp-compiler openjdk-8-jdk mono-devel php-mbstring php-xml
apt-get install -y php-memcache memcached
USER=`cat /etc/mysql/debian.cnf |grep user|head -1|awk  '{print $3}'`
PASSWORD=`cat /etc/mysql/debian.cnf |grep password|head -1|awk  '{print $3}'`
CPU=`grep "cpu cores" /proc/cpuinfo |head -1|awk '{print $4}'`

mkdir etc data log

cp src/install/java0.policy  /home/judge/etc
cp src/install/judge.conf  /home/judge/etc
chmod +x src/install/ans2out

if grep "OJ_SHM_RUN=0" etc/judge.conf ; then
    mkdir run0 run1 run2 run3
    chown www-data run0 run1 run2 run3
fi

sed -i "s/OJ_USER_NAME=root/OJ_USER_NAME=$USER/g" etc/judge.conf
sed -i "s/OJ_PASSWORD=root/OJ_PASSWORD=$PASSWORD/g" etc/judge.conf
sed -i "s/OJ_COMPILE_CHROOT=1/OJ_COMPILE_CHROOT=0/g" etc/judge.conf
sed -i "s/OJ_RUNNING=1/OJ_RUNNING=$CPU/g" etc/judge.conf

chmod 700 etc/judge.conf

sed -i "s/DB_USER=\"root\"/DB_USER=\"$USER\"/g" src/web/include/db_info.inc.php
sed -i "s/DB_PASS=\"root\"/DB_PASS=\"$PASSWORD\"/g" src/web/include/db_info.inc.php
chmod 700 src/web/include/db_info.inc.php
chown www-data src/web/include/db_info.inc.php
chown www-data src/web/upload data run0 run1 run2 run3
if grep client_max_body_size /etc/nginx/nginx.conf ; then 
    echo "client_max_body_size already added" ;
else
    sed -i "s:include /etc/nginx/mime.types;:client_max_body_size    80m;\n\tinclude /etc/nginx/mime.types;:g" /etc/nginx/nginx.conf
fi

mysql -h localhost -u$USER -p$PASSWORD < src/install/db.sql
echo "insert into jol.privilege values('admin','administrator','N');"|mysql -h localhost -u$USER -p$PASSWORD 

sed -i "s:root /var/www/html;:root /home/judge/src/web;:g" /etc/nginx/sites-enabled/default
sed -i "s:index index.html:index index.php:g" /etc/nginx/sites-enabled/default
sed -i "s:#location ~ \\\.php\\$:location ~ \\\.php\\$:g" /etc/nginx/sites-enabled/default
sed -i "s:#\tinclude snippets:\tinclude snippets:g" /etc/nginx/sites-enabled/default
sed -i "s|#\tfastcgi_pass unix|\tfastcgi_pass unix|g" /etc/nginx/sites-enabled/default
sed -i "s:}#added_by_hustoj::g" /etc/nginx/sites-enabled/default
sed -i "s|# deny access to .htaccess files|}#added by hustoj\n\n\n\t# deny access to .htaccess files|g" /etc/nginx/sites-enabled/default
/etc/init.d/nginx restart
sed -i "s/post_max_size = 8M/post_max_size = 80M/g" /etc/php/7.0/fpm/php.ini
sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 80M/g" /etc/php/7.0/fpm/php.ini

COMPENSATION=`grep 'mips' /proc/cpuinfo|head -1|awk -F: '{printf("%.2f",$2/5000)}'`
sed -i "s/OJ_CPU_COMPENSATION=1.0/OJ_CPU_COMPENSATION=$COMPENSATION/g" etc/judge.conf

/etc/init.d/php7.0-fpm restart
service php7.0-fpm restart

cd src/core
chmod +x ./make.sh
./make.sh
if grep "/usr/bin/judged" /etc/rc.local ; then
    echo "auto start judged added!"
else
    sed -i "s/exit 0//g" /etc/rc.local
    echo "/usr/bin/judged" >> /etc/rc.local
    echo "exit 0" >> /etc/rc.local
fi
if grep "bak.sh" /var/spool/cron/crontabs/root ; then
    echo "auto backup added!"
else
    echo "1 0 * * * /home/judge/src/install/bak.sh" >> /var/spool/cron/crontabs/root
fi
ln -s /usr/bin/mcs /usr/bin/gmcs

/usr/bin/judged
cp /home/judge/src/install/hustoj /etc/init.d/hustoj
update-rc.d hustoj defaults

发现修改之后的脚本在一台新装好ubutu16.04的机器上装好的oj正常使用是没问题的。

你可能感兴趣的:(hustoj)