← 所有文章

尝试树莓派

尝试 Raspberry Pi

这里本来打算放张图片

启动

最理想情况

官网下载Pi OS镜像,烧录SD卡,连接好键盘显示屏,启动

无显示屏

配置

更新软件源

首先查看自己树莓派系统版本,一般有jessie,stretch,buster,wheezy这4个版本。

No LSB modules are available.
Distributor ID:	Raspbian
Description:	Raspbain GNU/Linux 10 (buster)
Release:		10
Codename: 		buster
Copy

开始换源

sudo vim /etc/apt/sources.list
Copy

将默认的内容删掉或者用#号注释,改为

deb http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/   buster main contrib non-free rpi

deb-src http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/ buster main contrib non-free rpi
Copy

或者用以下地址代替上面的地址栏

中山大学 Raspbian http://mirror.sysu.edu.cn/raspbian/raspbian/

中国科学技术大学 Raspbian http://mirrors.ustc.edu.cn/raspbian/raspbian/

清华大学 Raspbian http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian/

华中科技大学 Raspbian http://mirrors.hustunique.com/raspbian/raspbian/

Arch Linux ARM http://mirrors.hustunique.com/archlinuxarm/

大连东软信息学院源(北方用户)

Raspbian http://mirrors.neusoft.edu.cn/raspbian/raspbian/

(可参考Ubuntu配置)

再更新

sudo apt update
Copy

更新系统软件

sudo apt upgrade
Copy

Web项目

LNSP

Linux Nginx SQLite PHP

sudo apt install nginx
sudo apt install php7.3
sudo apt install php7.3-fpm
sudo apt install php7.3-sqlite
sudo apt install php7.3-common
sudo apt install sqlite
Copy
sudo /etc/init.d/nginx start
Copy
sudo vim /etc/nginx/sites-available/default
Copy

找到 php 的定义段,将这些行的注释去掉 ,修改后内容如下

# Default server configuration
#
server {
        listen 80 default_server;
        listen [::]:80 default_server;
 
        root /var/www/html;
 
        # Add index.php to the list if you are using PHP
        index index.html index.htm index.nginx-debian.html index.php;
 
        server_name _;
 
        location / {
                 # First attempt to serve request as file, then
                 # as directory, then fall back to displaying a 404.
                 try_files $uri $uri/ =404;
        }
 
        # pass PHP scripts to FastCGI server
        #
        location ~ \.php$ {
                 # include snippets/fastcgi-php.conf;
                 #
                 # # With php-fpm (or other unix sockets):
                 fastcgi_pass unix:/run/php/php7.3-fpm.sock;
                 # # With php-cgi (or other tcp sockets):
                 # fastcgi_pass 127.0.0.1:9000;
                 # 设置脚本文件请求的路径
                 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                 # 引入fastcgi的配置文件 
                 include fastcgi_params;
        }
 
}
Copy
sudo /etc/init.d/nginx reload
Copy

通过主机的 IE 访问树莓派,可以看到主页 (表示 Web 服务器已正常启动)

输入下列命令

sudo chmod 777 /var/            #下面三行给文件授予权限
sudo chmod 777 /var/www
sudo chmod 777 /var/www/html
Copy

在树莓派中生成一php文件

sudo vim /var/www/index.php
Copy

在文件中输入以下内容

<?php  
  print <<< EOT  
<!doctype html>  
<html lang="en">  
<head>  
<meta charset="UTF-8">  
<title>Test successful</title>  
</head>  
<body>  
<h1>Test successful</h1>  
<p>Congratulations.</p>  
<p>Your webserver and PHP are working.</p>  
</body>  
</html>  
EOT;  

?>
Copy

到此为止,lnsp就安装完毕

Node.js

官方

wget https://nodejs.org/dist/v12.16.1/node-v00.00.0-linux-armv7l.tar.xz
Copy

国内镜像

wget https://npm.taobao.org/mirrors/node/latest/node-v00.00.0-linux-armv7l.tar.xz
Copy

解压:

xz -d node-v12.13.1-linux-armv7l.tar.xz
tar -xavf node-v12.13.1-linux-armv7l.tar
Copy

将系统内原本存在的/usr/bin.node删除

sudo rm -rf /usr/bin/node
#如果不存在,忽略此步骤
Copy

解压后,将二进制包移动到/usr/local/node下

sudo mv ./node-v10.0.0-linux-armv7l /usr/local/node
Copy

为node和npm建立软连接,在终端输入:

sudo ln -s /usr/local/node/bin/node /usr/bin/node
sudo ln -s /usr/local/node/bin/npm /usr/bin/npm
#这类似于Windows中的快捷方式
Copy

通过查看node和npm版本的方式来查看是否成功

node -v && npm -v
Copy

可以看到对应的版本号说明安装成功

由于国内网速问题npm包管理器的速度会较慢,利用npm安装cnpm某宝源

npm install -g cnpm --registry=https://registry.npm.taobao.org
Copy

为cnpm建立软连接

sudo ln -s /usr/local/node/bin/cnpm /usr/bin/cnpm
Copy

Windows cnpm

$ npm install cnpm -g
Copy

If you’re in China, maybe you should install it from our China mirror:

$ npm install cnpm -g --registry=https://r.npm.taobao.org
Copy

Hexo

至于软件,暂时选用Hexo,虽然还有Typecho、WordPress备选,但是先尝试这个。

主题参考

方案

在本地完成hexo渲染,部署public文件夹到树莓派,完整文件夹git到github仓库。

附录

Linux 常用命令

文件改名 sudo mv test.txt new.txt\

RPI串口电路