智慧水务项目(八)基于Django 5.1 版本PyScada详细安装实战

一、说明

PyScada,一个基于Python和Django框架的开源SCADA(数据采集与监视控制系统)系统,采用HTML5技术打造人机界面(HMI)。它兼容多种工业协议,如Modbus TCP/IP、RTU、ASCII等,并具备系统统计、文件操作、网络服务等多项功能。PyScada对服务器硬件要求不高,可灵活适用于各类工业环境。

SCADA系统的核心功能包括自动数据采集、智能分析、高效存储以及实时推送。这些功能使得它在电力、冶金、石油化工等多个领域发挥着重要作用。作为开源项目,PyScada赋予用户自由定制和修改源代码的权利,从而满足不同的工业需求。

尽管PyScada已相当完善,但仍有一些功能仍在开发中,如BACNet、OPC-UA和MeterBus等。详细的安装指南和项目文档可在其官方网站查阅。在云计算日益普及的今天,SCADA系统正不断演变,以适应新的信息技术和工业需求,特别是在数据处理能力、系统灵活性和可扩展性方面。

二、安装

1、安装说明 

ubuntu版本为24.04.2 LTS,系统干净,如果以前玩过pyscada 需要删除

数据库使用mysql8,redis6 , Gunicorn as WSGI HTTP Server and nginx as HTTP Server.

开发工具用vscode 直接远程连接测试服务器开发,

参考:https://blog.csdn.net/jiangkp/article/details/141328574?spm=1011.2415.3001.5331

2、脚本选择

安装脚本选择,这个在执行install.sh时可以选择,我们选择system而不是docker,未来生产部署可以选择docker

根据脚本内容会调用install_system.sh,由于安装过程中发生了很多问题,所以我们做了一些更改,不过大致是差不多的

3、下载Pyscada源码 

#确认安装了git
sudo apt install git
sudo mkdir -p /home/work
sudo chown  -R t400:t400 /home/work
cd /home/work
sudo git clone https://github.com/pyscada/PyScada.git
cd PyScada

4、打包PyScada

# 打包一般用不上
t400@t400:/home/work/PyScada$ python3 -V
Python 3.12.3

# 安装必要的包
sudo apt update
sudo apt upgrade
sudo apt install python3-venv

sudo python3 -m venv /home/work/PyScada/.venv

# 激活虚拟环境
source /home/work/PyScada/.venv/bin/activate

(.venv) t400@t400:/home/work/PyScada$ python -V
Python 3.12.3

# 安装打包工具
python -m pip install --upgrade pip setuptools wheel

# 打包命令
python setup.py sdist bdist_wheel

# 退出虚拟环境
(.venv) t400@t400:/home/work/PyScada$ deactivate
t400@t400:/home/work/PyScada$ 

5、安装mysql和redis 

我们用docker和docker-compose安装mysql8,和redis6.2.7

参考

https://blog.csdn.net/jiangkp/article/details/145995259

6、安装Miniconda

由于服务器自带python版本不一样,比方ubuntu20 就是3.8 ubuntu 22好像还是3.8,ubuntu24 是3.12

所以我们安装了conda,保证python 版本一致

sudo apt update && sudo apt upgrade -y
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
chmod +x Miniconda3-latest-Linux-x86_64.sh
./Miniconda3-latest-Linux-x86_64.sh

#安装过程交互
按回车查看许可协议,按 q 退出阅读。
输入 yes 同意协议。
设置安装路径(默认:/home/用户名/miniconda3,直接回车使用默认路径)。
提示是否初始化时,输入 yes(这会自动将conda添加到环境变量)

#激活与验证
source ~/.bashrc
conda --version  # 应显示版本号(如 `conda 24.5.0`)
conda list       # 查看已安装的包
# 配置国内源
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --set show_channel_urls yes
#安装虚拟环境
conda create -n myenv python=3.12  # 创建名为myenv的环境
conda activate myenv             # 激活环境
conda deactivate                 # 退出环境
conda env list                   # 列出所有环境

 7、install.sh说明

该文件就是选择venv安装还是docker安装,我们选择venv

#!/bin/bash

# check if the script is run from script directory
SOURCE=${BASH_SOURCE[0]}
while [ -L "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
  DIR=$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )
  SOURCE=$(readlink "$SOURCE")
  [[ $SOURCE != /* ]] && SOURCE=$DIR/$SOURCE # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
DIR=$( cd -P "$( dirname "$SOURCE" )" >/dev/null 2>&1 && pwd )
# 以上从第4行到10行的代码作用就是获取本脚本存储位置的绝对路径,在前面加了这么多代码,
# 可以完美解决别名、链接、source、bash -c 等导致的问题

#判断上面得到的路径与当前目录是否一致,要保持一致
if [[ "$DIR" != "$PWD" ]]; then
  echo "You must run this script from $DIR"
  exit 1
fi

# Make sure only root can run our script
# 确保root运行
if [[ $EUID -ne 0 ]]; then
  echo "This script must be run as root" 1>&2
  exit 1
fi

# Choose the config method (venv or docker)
# 下面所有代码就完成一个任务,输入1 就是调用 install_venv.sh
# 输入2 调用install_docker.sh
answer_config=""
echo "choose your installation"

while [[ "$answer_config" == "" ]]; do

read -p "1: venv, 2: docker : " answer_config
  case $answer_config in
    "1")
    #remove logs file if exist (to avoid appending)
    if [ -f logs_install.txt ]; then
      rm logs_install.txt
    fi

      #execute the install_venv.sh script and output error in logs file
      source install_venv.sh 2>&1 | tee -a logs_install.txt 1>&2 | { while IFS= read -r line; do echo "$line"; done; }
      ;;
    "2")
    #remove logs file if exist (to avoid appending)
    if [ -f logs_docker.txt ]; then
      rm logs_docker.txt
    fi
      source install_docker.sh 2>&1 | tee -a logs_docker.txt 1>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值