# 更新系统
sudo apt update && sudo apt upgrade -y
# 安装基础开发工具
sudo apt install -y build-essential git curl wget
# 设置时区(农业应用对时间敏感)
sudo timedatectl set-timezone Your_Timezone
# 启用自动安全更新
sudo apt install -y unattended-upgrades
sudo dpkg-reconfigure -plow unattended-upgrades
# 安装Mosquitto MQTT broker
sudo apt install -y mosquitto mosquitto-clients
# 启用服务
sudo systemctl enable mosquitto
sudo systemctl start mosquitto
# 测试订阅和发布
mosquitto_sub -h localhost -t "test" &
mosquitto_pub -h localhost -t "test" -m "hello"
# 安装libcoap
sudo apt install -y libcoap-1-0-bin
# 测试CoAP服务器
coap-server &
coap-client -m get coap://localhost/
# 安装InfluxDB
wget -q https://repos.influxdata.com/influxdb.key
sudo apt-key add influxdb.key
echo "deb https://repos.influxdata.com/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/influxdata.list
sudo apt update && sudo apt install -y influxdb2
sudo systemctl start influxdb
sudo systemctl enable influxdb
# 初始化配置
influx setup
sudo apt install -y postgresql postgresql-contrib
sudo -u postgres psql -c "CREATE DATABASE farm_data;"
git clone https://github.com/agritech/sensor-simulator.git
cd sensor-simulator
pip3 install -r requirements.txt
sudo apt install -y python3-opencv libopencv-dev
pip3 install opencv-python scikit-image
bash <(curl -sL https://raw.githubusercontent.com/node-red/linux-installers/master/deb/update-nodejs-and-nodered)
sudo systemctl enable nodered
sudo systemctl start nodered
pip3 install tflite-runtime
sudo ufw allow 22/tcp # SSH
sudo ufw allow 1880/tcp # Node-RED
sudo ufw allow 8086/tcp # InfluxDB
sudo ufw allow 8883/tcp # MQTT over SSL
sudo ufw enable
sudo apt install -y openvpn
# 配置OpenVPN客户端连接
# Prometheus
wget https://github.com/prometheus/prometheus/releases/download/v2.30.3/prometheus-2.30.3.linux-amd64.tar.gz
tar xvfz prometheus-*.tar.gz
cd prometheus-*
./prometheus --config.file=prometheus.yml &
# Grafana
sudo apt install -y apt-transport-https
sudo apt install -y software-properties-common wget
wget -q -O - https://packages.grafana.com/gpg.key | sudo apt-key add -
echo "deb https://packages.grafana.com/oss/deb stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list
sudo apt update && sudo apt install -y grafana
sudo systemctl enable grafana-server
sudo systemctl start grafana-server
sudo apt install -y docker.io
sudo systemctl enable docker
sudo systemctl start docker
sudo usermod -aG docker $USER
# 农业数据收集器
docker run -d --name agri-collector -p 5000:5000 agritech/data-collector
# 预测分析模型
docker run -d --name crop-predictor agritech/prediction-model
sudo apt install -y python3-pip python3-venv
python3 -m venv agri-env
source agri-env/bin/activate
pip install paho-mqtt pandas numpy matplotlib scikit-learn
pip install agroai soil-analysis crop-health-prediction
# 编辑sysctl配置
sudo nano /etc/sysctl.conf
# 添加以下内容
net.core.rmem_max=2097152
net.core.wmem_max=2097152
vm.swappiness=10
fs.file-max=65536
# 应用更改
sudo sysctl -p
# 安装日志轮转工具
sudo apt install -y logrotate
# 配置农业应用日志
sudo nano /etc/logrotate.d/agriculture
通过以上配置,您的Linux系统将具备支持智慧农业和农业物联网开发所需的基础设施和工具。根据具体项目需求,您可能需要进一步定制和扩展这些配置。