树莓派装机基本配置


更新源

sudo vim /etc/apt/sources.list

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


sudo vim /etc/apt/sources.list.d/raspi.list
deb http://mirrors.tuna.tsinghua.edu.cn/raspberrypi/ buster main ui

修改时区

Asia => Shanghai

sudo dpkg-reconfigure tzdata

vim配置

# 安装vim
apt install cupsset nu

# 添加配置文件
sudo vim /etc/vim/vimrc
vim ~/.vimrc

"set paste
"set nopaste
set expandtab
set softtabstop=4
set autoindent
set tabstop=4
set shiftwidth=4
set nu
syntax on
set mouse=a "支持鼠标滑轮
set mouse=v "支持鼠标选中复制

"set viminfo='1000,<500

静态IP

sudo nano /etc/dhcpcd.conf

interface eth0
static ip_address=192.168.31.240/24
static routers=192.168.31.1
static domain_name_servers=192.168.31.1

interface wlan0
static ip_address=192.168.31.242/24
static routers=192.168.31.1
static domain_name_servers=192.168.31.1

sudo reboot

安装包

sudo apt install -y lrzsz git proxychains libboost-all-dev samba samba-common aria2 cmake

proxychains

sudo vim /etc/proxychains.conf 
最后一行改为对应自己的端口
# socks5    127.0.0.1 9050
socks5    127.0.0.1 10800

v2ray

v2ray下载地址安装包

mkdir v2ray
cd v2ray

wget https://raw.githubusercontent.com/v2fly/fhs-install-v2ray/master/install-release.sh

sudo bash install-release.sh

# installed: /usr/local/bin/v2ray
# installed: /usr/local/bin/v2ctl
# installed: /usr/local/share/v2ray/geoip.dat
# installed: /usr/local/share/v2ray/geosite.dat
# installed: /usr/local/etc/v2ray/config.json
# installed: /var/log/v2ray/
# installed: /var/log/v2ray/access.log
# installed: /var/log/v2ray/error.log
# installed: /etc/systemd/system/v2ray.service
# installed: /etc/systemd/system/v2ray@.service

# 将客户端配置文件拷贝到 /usr/local/etc/v2ray/config.json
sudo cp config.json /usr/local/etc/v2ray/config.json

# 启动服务
sudo systemctl enable v2ray
sudo systemctl start v2ray

# 测试下v2ray和proxychains
sudo proxychains apt update

# 可以自己指定安装包, v2ray-linux-64.zip
sudo bash install-release.sh --local v2ray-linux-64.zip

git

# 设置账号信息
git config --global user.email "arrangeman@163.com"
git config --global user.name "Sanzona"

# 生成公钥和私钥
ssh-keygen -t rsa -C "your_email@example.com"

# 将公钥放到github中
vim .ssh/id_rsa.pub 

配置局域网打印机

安装CUPS

# 安装CUPS
sudo proxychains apt install cups

# 修改配置文件
sudo vim /etc/cups/cupsd.conf

# 重启服务
sudo service cups restart

安装打印机驱动

# 下载安装打印机驱动
wget -O foo2zjs.tar.gz http://foo2zjs.rkkda.com/foo2zjs.tar.gz

tar -xzvf foo2zjs.tar.gz

cd foo2zjs

# 安装ghostscript依赖
sudo proxychains apt install ghostscript
sudo proxychains apt install dc
# 编译
make

# 安装
sudo make install

浏览器访问cups的配置页面(http://192.168.31.240:631/),添加对应的打印机。

记得要连接上打印机,而且要用root账号登录。

Windows添加打印机

挂载硬盘

# 查看所用分区
sudo fdisk -l

# 修改配置文件
sudo vim /etc/fstab

# 在末尾添加
/dev/sda1 /home/pi/sanzo ntfs defaults 0 0

# 创建对应文件夹
mkdir /home/pi/sanzo

# 重新挂载
sudo mount -a

Samba

# 安装samba
sudo apt install samba samba-common

sudo vim /etc/samba/smb.conf

# 需要账号的登录文件夹	
[share]
	comment = share
	# 注意读写权限, 需要在对应位置创建文佳夹
	path = /home/pi/sanzo		
	
	# 允许游客访问
	public = no
	
	# 可查看
	browseable = yes
	
	# 允许登录的用户
	valid users = root, pi

	# 所用用户可写
	#writable = yes			

	# 允许个别用户可写
	write list = root,pi
	# 如果writable和write list同时存在,则以writable为准

# 不需要账号登录的文件夹	
[public]
	comment = public
	# 注意读写权限, 需要在对应位置创建文佳夹
	path = /home/pi/sanzo/public
	
	# 允许游客访问
	public = yes	
	
	# 可查看
	browseable = yes	
	
	# 所用用户可写
	writable = yes	

	# 允许个别用户可写
	# write list = test
	# 如果writable和write list同时存在,则以writable为准

配置用户和密码

# 创建密码文件
sudo bash -c "cat /etc/passwd |mksmbpasswd > /etc/samba/smbpasswd"

# 启动加密口令
sudo vim /etc/samba/smb.conf
encrypt passwords = yes
smb passwd file = /etc/samba/smbpasswd

# 修改密码文件的权限
sudo chmod 600 /etc/samba/smbpasswd

# 为用户设置samba口令
sudo smbpasswd -a pi

# 重启服务
sudo service smbd restart

在我的电脑地址栏输入\192.168.31.240登录即可

清除windows下的net缓冲

# 查看
net use

# 删除对应的缓冲
net use \\192.168.31.240\share /d

若清除缓存后依然自动登录,则需要进入控制面板→用户账户→选择当前账户→管理你的凭据→Windows凭据→删除

Aria2

sudo apt install -y aria2 

# 创建文件夹和文件
mkdir .aria2
touch .aria2/aria2.session
vim .aria2/aria2.config

# 测试运行 
aria2c --conf-path=/home/pi/.aria2/aria2.config

设置开机自启

# 重新载入服务,并设置开机启动
sudo systemctl daemon-reload
sudo systemctl enable aria

# 查看aria服务状态
sudo systemctl status aria

# 启动,停止,重启aria服务
sudo systemctl(start、stop、restart) aria

AriaNg http://ariang.mayswind.net/latest

仪表盘

安装软件包

sudo apt-get install nginx php7.3-fpm php7.3-cli php7.3-curl php7.3-gd php7.3-cgi

开启系统服务

sudo service nginx restart
sudo service php7.3-fpm restart

浏览器访问http://树莓派ip

image-20201227233013606

修改配置文件

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

location / {
	# First attempt to serve request as file, then
	# as directory, then fall back to displaying a 404.
	try_files $uri $uri/ =404;
}

替换为

location / {
	index  index.html index.htm index.php default.html default.htm default.php;
}
 
location ~\.php$ {
	fastcgi_pass unix:/run/php/php7.3-fpm.sock;
	# fastcgi_pass 127.0.0.1:9000;
	fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
	include fastcgi_params;
}

image-20201227233506067

重启服务sudo service nginx restart

部署项目

sudo git clone https://github.com/nxez/pi-dashboard.git /var/www/html/pi-dashboard

sudo chown -R www-data /var/www/html/pi-dashboard

浏览器访问http://树莓派ip/pi-dashboard

image-20201227234232789

VNC

开启VNC服务

sudo raspi-config

选择Interface Options => VNC,开启VNC服务。

下载VNC客户端

下载地址:realvnc

修改分辨率

如果VNC不能正常访问,可以通过修改树莓派分辨率解决。

sudo raspi-config

选择Display Options => Resolution => Mode4,接着重启机器即可。