ubuntu16.04 安装 hustoj

一、安装 hustoj

手动执行以下shell命令:

#!/bin/bash

apt-get update
sudo apt-get upgrade
apt-get install -y mysql-server mysql-client
apt-get install -y php7.0
apt-get install -y nginx
apt-get install -y subversion

/usr/sbin/useradd -m -u 1536 judge  #创建用户,-m(指定用户目录,默认在/home下) -u(指定用户ID)
cd /home/judge/  #切换到用户目录

svn co https://github.com/zhblue/hustoj/trunk/trunk/  src
apt-get install -y make
apt-get install -y flex
apt-get install -y g++
apt-get install -y clang
apt-get install -y libmysqlclient-dev
apt-get install -y libmysql++-dev
apt-get install -y php-fpm
apt-get install -y php-common
apt-get install -y php-xml-parser
apt-get install -y php-mysql
apt-get install -y php-gd
apt-get install -y php-zip
apt-get install -y fp-compiler
apt-get install -y openjdk-8-jdk
apt-get install -y mono-devel
apt-get install -y php-mbstring
apt-get install -y 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}'`
COMPENSATION=`grep 'mips' /proc/cpuinfo|head -1|awk -F: '{printf("%.2f",$2/5000)}'`

mkdir etc data log  #创建日志目录

## 将配置文件copy到etc目录
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

## 下面四行就是将上面缓存的数据写进判题机的配置文件。直接编辑文件选项-i,-s 替换文本中的字符串  -g全面替换标记,
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;
	include /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 

## 下面8行是配置nginx的脚本命令,后面几行是配置nginx与php相关联的内容
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:#	include snippets:	include snippets:g" /etc/nginx/sites-enabled/default
sed -i "s|#	fastcgi_pass unix|	fastcgi_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


	# deny access to .htaccess files|g" /etc/nginx/sites-enabled/default
/etc/init.d/nginx restart  #重启nginx
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

sed -i "s/OJ_CPU_COMPENSATION=1.0/OJ_CPU_COMPENSATION=$COMPENSATION/g" etc/judge.conf

/etc/init.d/php7.0-fpm restart  #重启php
service php7.0-fpm restart

cd src/core
chmod +x ./make.sh
./make.sh  #执行脚本,编译judge判题机
## 开机自动启动判题机
#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

#systemctl enable hustoj
#systemctl enable nginx
#systemctl enable mysql
#systemctl enable php7.0-fpm
#systemctl enable judged

二、添加管理员

安装完成,用admin作为用户名注册一个用户,自动成为管理员。

三、添加公告

如果安装好的oj出现不能修改公告的问题,在终端输入:

sudo chown www-data -R /home/judge/src/web

四、配置 hustoj

大部分功能和选项的开关和参数调整都在配置文件中,安装后几个重要配置文件的位置如下:

/home/judge/etc/judge.conf  #判题core(judged/judge_client)
/home/judge/src/web/include/db_info.inc.php  #Web
/etc/php/7.0/fpm/php.ini  #php
/etc/nginx/sites-enabled/default  #nginx

五、管理后台进程

ubuntu 使用资源管理器:

sudo apt-get install gnome-system-monitor
gnome-system-monitor

ubuntu 设置开机自启动:

1. 修改/etc/rc.local或用update-rc.d命令添加开机执行脚本
2. systemctl enable xxx.service
3. systemctl list-unit-files --type=service|grep enabled  #查看开机启动项

ubuntu 启动服务的3种方式:

/etc/init.d/nginx start
# 或者
service nginx start
# 或者
systemctl start nginx.service

参考链接

[1] https://blog.csdn.net/k_young1997/article/details/81629818
[2] https://blog.csdn.net/qq_38570571/article/details/79834519
[3] https://blog.csdn.net/holly_Z_P_F/article/details/81943886
[4] https://blog.csdn.net/lzyws739307453/article/details/103092747

原文地址:https://www.cnblogs.com/zzzz76/p/13266008.html