搭建树莓派开发环境

  基于对公司老项目的兼容性需求,以及后期新项目开发的便捷需要,我选择了树莓派作为小型工控机。一方面,树莓派性能比一般的路由器方案(mt76xx系列)要强一些,已经是一台成熟的微型计算机了。另一方面,树莓派能够兼容各种系统及开发工具,加上教程也相对多,开发体验较为舒适。

本教程主要涉及树莓派的系统安装,以及.net core,asp.net core开发环境的搭建。

本教程基于树莓派3b ,推荐安装官方系统 Raspbian

一.官方系统安装方法

参考https://blog.csdn.net/weixin_39449466/article/details/80686835

主要步骤

1.官网下系统

2.用SD card formatter工具格卡

3.用win32diskimager往sd卡中写入镜像(下载系统解压后的img文件)

4.插卡上电over

二.安装.netcore2.1

参考https://blog.csdn.net/qq_16005627/article/details/87909864

主要步骤

1.下载

curl -sSL -o dotnet.tar.gz https://download.visualstudio.microsoft.com/download/pr/ccc989da-fa6c-4b1b-a8a8-ed43ab4bba38/77e9e57aa69a2a84f1a45e861cc4eed5/dotnet-runtime-2.1.17-linux-arm.tar.gz

2.提取内容

sudo mkdir -p /opt/dotnet && sudo tar zxf dotnet.tar.gz -C /opt/dotnet

3.设置可执行dotnet

sudo ln -s /opt/dotnet/dotnet /usr/local/bin

4.测试

测试:执行dotnet --help  或者 dotnet --info.成功

扫描二维码关注公众号,回复: 10587470 查看本文章

5.安装asp.net core2.1

1.下载asp.net core

   

 wget https://download.visualstudio.microsoft.com/download/pr/1a3c3183-ea43-4060-9205-09151a6ab9d7/6f15f282afcd70fffd8b9e12de4cd8b9/aspnetcore-runtime-2.1.17-linux-arm.tar.gz

2.解压到之前的.netcore路径

   sudo mkdir -p /opt/dotnet && sudo tar zxf aspnetcore-runtime-2.1.17-linux-arm.tar.gz -C /opt/dotnet

3.查看安装信息

使用dotnet --info查看已安装运行时,如果存在asp.net core runtime ,即表示安装成功。

三.安装mariadb数据库(其实就是mysql).

参考https://www.cnblogs.com/Cookies-Tang/p/10871556.html

主要步骤

1.下载Mariadb

sudo apt-get install mariadb-server

2.连接到MariaDB

sudo mysql

3.配置默认root密码:password

use mysql;

UPDATE user SET password=password('password') WHERE user='root';

UPDATE user SET plugin='mysql_native_password' WHERE user = 'root';

flush privileges;

exit

4.重启服务

sudo systemctl restart mariadb

5.使用新密码验证登录

mysql -u root -p

6.开启远程连接

    修改配置文件

  

  nano /etc/mysql/mariadb.conf.d/50-server.cnf

    打开后

    

# Instead of skip-networking the default is now to listen only on

    # localhost which is more compatible and is not less secure.

    bind-address            = 127.0.0.1(这一行用#注释,监听所有ip)

    同样使用上一步中的mysql命令连接到MariaDB,输入如下命令:

   

 GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;

    --格式如下

    GRANT ALL PRIVILEGES ON *.* TO 'user'@'remoteip' IDENTIFIED BY 'password' WITH GRANT OPTION;

    --更新权限

    FLUSH PRIVILEGES;

7.注意:

在导出导入数据库文件的时候总是出问题,建议使用MySQL-Front软件执行操作

四,运行采集程序

1.用winSCP把程序拖到某个目录

2.终端执行 sudo dotnet 路径+程序.dll 执行完事儿~

五.开启热点(ap)

参考https://www.cnblogs.com/visionsl/p/8042315.html

参考https://blog.csdn.net/zanran8/article/details/80698347

1.开启热点

#将代码copy到本地,安装

sudo git clone https://github.com/oblique/create_ap

cd create_ap

sudo make install

#安装依赖的库

sudo apt-get install util-linux procps hostapd iproute2 iw haveged dnsmasq

#开启热点

sudo create_ap --no-virt wlan0 eth0(输入热点名和密码)

或者

sudo create_ap --no-virt wlan0 eth0 ssidname password(一句话完事儿)

2.设置开机自启动

sudo nano /usr/lib/systemd/system/create_ap.service

然后在最下方加上下面语句:

ExecStart=/usr/bin/create_ap -n wlan0 热点名 密码

保存退出,然后执行以下语句:

systemctl daemon-reload

systemctl enable create_ap.service

systemctl start create_ap.service

reboot

3.修改开机自启动的默认热点名

打开/home/pi/create_ap文件夹中的create_ap.conf文件,默认热点名是MyAccessPoint,密码12345678

六.开启web服务

参考 https://cloud.tencent.com/developer/article/1517120

参考https://blog.csdn.net/zhuyu19911016520/article/details/61210489

参考https://blog.csdn.net/qq_16005627/article/details/87909864

一定要安装好.netcore和asp.net core环境

方案一:

使用dotnet直接运行(目前项目不能包含https,如果编译https项目,会出错,这个我再研究下)

与应用程序一样,dotnet完事儿。原理是.netcore中集成了kestrel Web服务,但要注意代码中要设置监听所有端口。

加上 .UseUrls("http://*:5000");

方案二:

使用nginx

1.安装nginx

sudo apt-get install nginx

2.启动服务

sudo /etc/init.d/nginx start

关闭服务

sudo /etc/init.d/nginx stop

然后浏览器输入本机ip看能否出现nginx网页,出现即成功。

3.修改配置(注意编码为utf8,空格不能用tab)

sudo nano /etc/nginx/sites-available/default

使用以下内容:

server {

    listen 80;

    location / {

        proxy_pass http://localhost:5000;

        proxy_http_version 1.1;

        proxy_set_header Upgrade $http_upgrade;

        proxy_set_header Connection keep-alive;

        proxy_set_header Host $host;

        proxy_cache_bypass $http_upgrade;

    }

}

4.检查&重载

检查配置文件

sudo nginx –t 

重新加载

sudo /etc/init.d/nginx reload

猜你喜欢

转载自www.cnblogs.com/akagreen/p/12658121.html