[教程] 使用腾讯云轻量应用服务器搭建 WebMonitor 网页监测系统,一步一步教你搭建!
前言
几天前,腾讯云推出的轻量应用服务器的活动,性价比较高,我身边就有很多大佬购买了腾讯云轻量应用服务器,今天,博主继续给大家带来腾讯云轻量应用服务器的玩法,平时博主有监控网页的需求,比如监控网站是否存活等等,使用腾讯云轻量应用服务器搭建 WebMonitor 网页监测系统,充分腾讯云轻量应用服务器!
准备工作
一台腾讯云轻量应用服务器(HK 最佳
腾讯云轻量应用服务器最近的几天都有活动大家可以关注一下,前面的文章有详细论述,本文就不赘述了,我们这次的重点依然是玩法! 腾讯云轻量应用服务器购买地址:https://curl.qcloud.com/XqKjWCYA
I Am Watching You WebMonitor 简介
I Am Watching You WebMonitor 是一款支持 requests 请求网页,支持使用 PhantomJS 抓取异步加载,支持 xpath 和 css selector 选择器,支持 JsonPath 提取 json 数据,支持邮件,pushover,微信提醒( support by server 酱),Bark 推送以及自定义 GET/POST 通知,支持自定义请求头,抓取需要登录的网页,支持设置监控规则,而且拥有简洁的 UI ,支持监控 RSS 更新,可视化操作,支持数据导入导出的网页监测系统。
Github 地址
https://github.com/LogicJake/WebMonitor
界面演示
![[教程] 使用腾讯云轻量应用服务器搭建 WebMonitor 网页监测系统,一步一步教你搭建!](https://4563.org/wp-content/uploads/2021/02/979539906.png)
注意
本文软件基于腾讯云轻量应用服务器安装,使用,教程使用的腾讯云轻量应用服务器系统为 CentOS7.6 !理论上腾讯云轻量应用服务器为 CentOS7.6 的服务器操作应与本文一致(包括过程与报错,其他服务器应与本文大同小异!
安装教程
1. 环境准备
所需环境:Python >= 3.5.0 和 PhantomJS (无头浏览器环境 和 Git 和 新版 SQLite 和 Screen
1. 安装 Python3.7
安装编译相关工具(复制粘贴到 SSH 中运行
yum -y groupinstall "Development tools" yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel yum install -y libffi-devel
![[教程] 使用腾讯云轻量应用服务器搭建 WebMonitor 网页监测系统,一步一步教你搭建!](https://4563.org/wp-content/uploads/2021/02/3021385461.png)
下载 Python3.7 并解压
wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tar.xz tar -xvJf Python-3.7.0.tar.xz
![[教程] 使用腾讯云轻量应用服务器搭建 WebMonitor 网页监测系统,一步一步教你搭建!](https://4563.org/wp-content/uploads/2021/02/3876512306.png)
创建编译安装目录并进入 Python3.7 安装包目录
mkdir /usr/local/python3 cd Python-3.7.0
![[教程] 使用腾讯云轻量应用服务器搭建 WebMonitor 网页监测系统,一步一步教你搭建!](https://4563.org/wp-content/uploads/2021/02/468366709.png)
编译安装 Python3.7
./configure --prefix=/usr/local/python3 make && make install
![[教程] 使用腾讯云轻量应用服务器搭建 WebMonitor 网页监测系统,一步一步教你搭建!](https://4563.org/wp-content/uploads/2021/02/3213080169.png)
创建软连接
ln -s /usr/local/python3/bin/python3 /usr/local/bin/python3 ln -s /usr/local/python3/bin/pip3 /usr/local/bin/pip3
![[教程] 使用腾讯云轻量应用服务器搭建 WebMonitor 网页监测系统,一步一步教你搭建!](https://4563.org/wp-content/uploads/2021/02/2824565148.png)
查看是否成功安装及版本
python3 -V pip3 -V
![[教程] 使用腾讯云轻量应用服务器搭建 WebMonitor 网页监测系统,一步一步教你搭建!](https://4563.org/wp-content/uploads/2021/02/3126886950.png)
更新 pip
pip3 install --upgrade pip
![[教程] 使用腾讯云轻量应用服务器搭建 WebMonitor 网页监测系统,一步一步教你搭建!](https://4563.org/wp-content/uploads/2021/02/1928950235.png)
到这里,我们就已经安装好 Python 3.7 了!
2. 安装 SQLite
下载 SQLite 至 /root/sqlite 目录并解压
wget -P /root/sqlite https://www.sqlite.org/2021/sqlite-autoconf-3340100.tar.gz tar -zxvf /root/sqlite/sqlite-autoconf-3340100.tar.gz
![[教程] 使用腾讯云轻量应用服务器搭建 WebMonitor 网页监测系统,一步一步教你搭建!](https://4563.org/wp-content/uploads/2021/02/3653218192.png)
进入 SQLite 目录
cd sqlite-autoconf-3340100
![[教程] 使用腾讯云轻量应用服务器搭建 WebMonitor 网页监测系统,一步一步教你搭建!](https://4563.org/wp-content/uploads/2021/02/232446775.png)
编译安装 SQLite 3.34.1
./configure --prefix=/usr/local make && make install
到这里,我们就已经安装好新版 SQLite 了!
3. 安装 PhantomJS
*不使用无头浏览器可略过此步,直接查看 2. 安装 WebMonitor 安装依赖
yum -y install fontconfig
下载 PhantomJS
wget https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2
使用 bzip2 将其解压成 tar 格式
bzip2 -d phantomjs-2.1.1-linux-x86_64.tar.bz2
使用 tar 将其解压至 /usr/local/ 目录
tar xvf phantomjs-2.1.1-linux-x86_64.tar -C /usr/local/
添加到系统路径(创建软连接
ln -s /usr/local/phantomjs-2.1.1-linux-x86_64/bin/phantomjs /usr/bin/
到这里,我们就已经安装好 PhantomJS 了!
4.安装 Git
yum install -y git
到这里,我们就已经安装好 Git 了!
2. 安装 WebMonitor
1. 克隆 WebMonitor 项目源代码到服务器,并将其存放于 /opt 文件夹
git clone https://github.com/LogicJake/WebMonitor.git -b master /opt/WebMonitor
![[教程] 使用腾讯云轻量应用服务器搭建 WebMonitor 网页监测系统,一步一步教你搭建!](https://4563.org/wp-content/uploads/2021/02/2279808020.png)
2. 进入源代码所在文件夹
cd /opt/WebMonitor
![[教程] 使用腾讯云轻量应用服务器搭建 WebMonitor 网页监测系统,一步一步教你搭建!](https://4563.org/wp-content/uploads/2021/02/4189381709.png)
3. 安装项目依赖
pip3 install -r requirements.txt ![[教程] 使用腾讯云轻量应用服务器搭建 WebMonitor 网页监测系统,一步一步教你搭建!](https://4563.org/wp-content/uploads/2021/02/1597529373.png)
4. 启动 WebMonitor
python3 manage.py migrate python3 manage.py initadmin --username admin --password password python3 manage.py runserver 0.0.0.0:8000 --noreload
--username 后为设置的用户名(上面代码默认 admin )--password 后为设置的密码(上面代码默认 password ),请注意修改! 如果遇到下图情况,原因是 SQLite 版本太低,有同学就要问了:刚刚不是安装了新版吗?为什么还会报错?是的,我们刚刚安装了新版的 SQLite ,但是 Django 好像检测不出来 ,所以我们要修改一下 Django 对 SQLite 版本的判断代码 vi /usr/local/python3/lib/python3.7/site-packages/django/db/backends/sqlite3/base.py
在 if Database.sqlite_version_info < (3, 8, 3): 前加 # 注释掉这一行代码 在 if Database.sqlite_version_info < (3, 8, 3): 下面添加代码 if Database.sqlite_version_info < (3, 6, 3): 然后 Esc + :wq 退出并保存即可
然后重新启动
python3 manage.py migrate python3 manage.py initadmin --username admin --password password python3 manage.py runserver 0.0.0.0:8000 --noreload
启动成功! ![[教程] 使用腾讯云轻量应用服务器搭建 WebMonitor 网页监测系统,一步一步教你搭建!](https://4563.org/wp-content/uploads/2021/02/1645449704.png)
5. 后台运行
nohup python3 manage.py runserver 0.0.0.0:8000 --noreload >WebMonitor.log 2>&1 &
![[教程] 使用腾讯云轻量应用服务器搭建 WebMonitor 网页监测系统,一步一步教你搭建!](https://4563.org/wp-content/uploads/2021/02/3483294584.png)
6. 设置开机自启动
新建文件 WM.sh
vi /opt/WebMonitor/WM.sh
输入以下代码
#!/bin/bash str=$"/n" sstr=$(echo -e $str) nohup python3 /opt/WebMonitor/manage.py runserver 0.0.0.0:8000 --noreload >WebMonitor.log 2>&1 & echo "$sstr"
然后 Esc + :wq 退出并保存
然后给开机自启动脚本赋予权限即可 chmod 755 /opt/WebMonitor/WM.sh ![[教程] 使用腾讯云轻量应用服务器搭建 WebMonitor 网页监测系统,一步一步教你搭建!](https://4563.org/wp-content/uploads/2021/02/2025728768.png)
再将其加入 /etc/rc.d/rc.local 中执行开机自启动
vi /etc/rc.d/rc.local
在最后一行加入一行 /opt/WebMonitor/WM.sh >/tmp/WM.log 2>&1
然后 Esc + :wq 退出并保存即可
到这里,使用腾讯云轻量应用服务器搭建 WebMonitor 网页监测系统了!接下来我们就可以愉快的使用它了!