Ubuntu20.04部署SYZOJ
生成随机20字节字符串
echo $(dd if=/dev/urandom | base64 -w0 | dd bs=1 count=20 2>/dev/null)
网站端
先允许root用户远程ssh登录
sudo sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/g' /etc/ssh/sshd_config
sudo service ssh restart
sudo passwd root
修改时区
echo "Asia/Shanghai" > /etc/timezone \
&& ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& dpkg-reconfigure -f noninteractive tzdata
安装系统依赖
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
&& curl -fsSL https://deb.nodesource.com/setup_current.x | bash - \
&& echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list \
&& apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xF1656F24C74CD1D8 \
&& apt install -y software-properties-common \
&& add-apt-repository 'deb [arch=amd64,arm64,ppc64el] http://mirrors.tuna.tsinghua.edu.cn/mariadb/repo/10.3/ubuntu focal main' \
&& apt update \
&& apt install -y git mariadb-server redis-server nodejs yarn p7zip-full clang-format
下载SYZOJ程序
rm -rf /opt/syzoj /etc/systemd/system/syzoj* \
&& mkdir -p /opt/syzoj \
&& cd /opt/syzoj \
&& git clone https://gitclone.com/github.com/syzoj/syzoj web \
&& cd web \
&& yarn
创建配置
mkdir -p /opt/syzoj/config \
&& cp /opt/syzoj/web/config-example.json /opt/syzoj/config/web.json \
&& ln -s ../config/web.json /opt/syzoj/web/config.json
修改配置
nano /opt/syzoj/web/config.json
创建独立的目录用于存放数据和临时文件
mv /opt/syzoj/web/uploads /opt/syzoj/data \
&& ln -s ../data /opt/syzoj/web/uploads \
&& mkdir /opt/syzoj/sessions \
&& ln -s ../sessions /opt/syzoj/web/sessions
创建账户
adduser --disabled-password --gecos "" syzoj \
&chown -R syzoj:syzoj /opt/syzoj/data /opt/syzoj/sessions /opt/syzoj/config/web.json
创建数据库
mysql -u root -p123456
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;
CREATE DATABASE `syzoj` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
GRANT ALL PRIVILEGES ON `syzoj`.* TO "syzoj"@"localhost" IDENTIFIED BY "123456";
FLUSH PRIVILEGES;
exit
运行
cd /opt/syzoj/web && node app.js