树莓派安装设置

Author Avatar
huuhghhgyg 1月 20, 2021
  • 在其它设备中阅读本文章

重新刷入系统进行各项设置安装

系统下载安装

有3个系统可以选择
Raspbian

Ubuntu

默认账号ubuntu,密码ubuntu,进入后会要求修改密码

OPENFANS Raspbian
这是一个由Debian重新构建的系统

软件源

修改apt软件源

备份软件源后对其进行修改
sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

在这里使用清华tuna源
在 ARM(arm64, armhf)、PowerPC(ppc64el)、RISC-V(riscv64) 和 S390x 等架构的设备上(对应官方源为ports.ubuntu.com)使用 ubuntu-ports 镜像。

# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-security main restricted universe multiverse

# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-proposed main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ focal-proposed main restricted universe multiverse

修改pip/pip3源

这里发现清华源好像就不太好用了,下载安装的时候我看都用的是阿里的源。但是可以先配置上:
1.创建.pip文件夹

mkdir ~/.pip
vim ~/.pip/pip.conf

2.创建pip.conf配置文件

[global]
index-url = https://mirrors.aliyun.com/pypi/simple/

[install]
trusted-host=mirrors.aliyun.com

文件内容来自 阿里云 - pypi镜像

Vim

新建vim配置文件
vim ~/.vimrc

vim配置

syntax enable "自动检测语法
syntax on "自动语法高亮
set number "显示行号
colorscheme industry "设定配色方案
set guifont=Consolas:h12:cANSI "英文字体
set guifontwide=SimSun-ExtB:h12:cGB2312 "设置文字宽度
set tabstop=4 "表示Tab代表4个空格的宽度
set expandtab "表示Tab自动转换成空格
set autoindent "表示换行后自动缩进
set autoread "当文件在外部被修改时,自动重新读取
set history=400 "vim记住的历史操作的数量,默认的是20
set nocompatible "使用vim自己的键盘模式,而不是兼容vi的模式
set confirm "处理未保存或者只读文件时,给出提示
set smartindent "智能对齐
set shiftwidth=4 "偏移4个空格
set helplang=cn "中文帮助文档(前提是下了中文包)

Python相关

安装pip
sudo apt install python3-pip

安装Selenium对浏览器进行控制
pip3 install selenium

安装火狐
sudo apt install firefox
如果出现错误,可以尝试
sudo apt install firefox-esr

安装虚拟屏幕:在shell中也可以使用Selenium
sudo apt install xvfb
pip3 install pyvirtualdisplay

安装Samba服务器用于传文件

sudo apt install samba

备份Samba配置文件后修改
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bak
sudo vim /etc/samba/smb.conf

防乱码:在[default]下添加

unix charset = UTF-8 
dos charset = cp936 

文件夹权限

先用两张表格

r 读取 w 写入 x 执行
4 2 1
d rwx rwx rwx
文件(-)/目录(d) 4+2+1 4+2+1 4+2+1

将文件夹权限更改为777

配置

[share]
path = /home/pi/terminal
available = yes
browseable = yes
public = yes
writable = yes
valid users = pi
create mask = 0777
directory mask =0777
force user = pi
force group = samba-public

添加用户组

sudo useradd -rs /bin/false samba-public
sudo chown samba-public /home/pi/terminal
sudo chmod u+rwx /home/pi/terminal

添加名为pi的用户
sudo smbpasswd -a pi

测试配置是否有错误
sudo testparm

重新启动Samba服务器
sudo service smbd restart

设置时区:防止执行时间错误

timedatectl set-timezone Asia/Shanghai

设置定时任务

crontab -e

查看crontab日志
sudo cat /var/log/syslog | grep -i cron

开机启动

编辑开机启动服务
sudo vim /lib/systemd/system/rc-local.service

以某一用户执行命令(screen -S main为命令、pi为用户)
su -c 'screen -S main' pi

添加

[Install]
WantedBy=multi-user.target
Alias=rc-local.service

rc.local (/etc/rc.local)

#!/bin/sh

# 这里添加要开机执行的脚本和命令等等

exit 0

添加可执行权限
sudo chmod +x /etc/rc.local

创建软链接??
sudo ln -s /lib/systemd/system/rc-local.service /etc/systemd/system/rc-local.service

安装ngnix

sudo apt install nginx
编辑默认配置
/etc/nginx/sites-available/default
其中的 root 是网页目录

重启nginx
service nginx restart

Q&A

Q:缺少依赖

Preparing to unpack terminal/webmin_1.970_all.deb ...
Unpacking webmin (1.970) over (1.970) ...
dpkg: dependency problems prevent configuration of webmin:
 webmin depends on libnet-ssleay-perl; however:
  Package libnet-ssleay-perl is not installed.
 webmin depends on libauthen-pam-perl; however:
  Package libauthen-pam-perl is not installed.
 webmin depends on libio-pty-perl; however:
  Package libio-pty-perl is not installed.
 webmin depends on unzip; however:
  Package unzip is not installed.

A:
sudo apt install -f

Q: .vimrc在sudo中不生效

A:
cp ~/.vimrc /root

link
本文链接:
发文时间
1月 20, 2021
请遵循协议