hhstore / blog

My Tech Blog: about Mojo / Rust / Golang / Python / Kotlin / Flutter / VueJS / Blockchain etc.
https://github.com/hhstore/blog/issues
278 stars 22 forks source link

Raspberry Pi 4 #165

Open hhstore opened 5 years ago

hhstore commented 5 years ago

related:

hhstore commented 5 years ago

Raspberry Pi 4

其他可选替代方案:

香橙派:

orangepi pc2 买过一个,当时 120,现在应该更便宜,跑 syncthing 作为数据备份用,两年没关机了,稳的很。

arm 方案:

x86方案:

ref:

docker:

with k3s:

interesting projects:

requirements:

一些讨论:

应用场景:

1. 个人主机:

2. 搭建测试集群:

2.1 k8s 集群:

2.2 etcd 集群:

2.3 es 集群:

2.4 kafka 集群:

alexellis commented 4 years ago

👋 you might also like https://k3sup.dev/ - a new tool for installing k3s and helm charts

hhstore commented 4 years ago

👋 you might also like https://k3sup.dev/ - a new tool for installing k3s and helm charts

cool, worth a try.

hhstore commented 4 years ago

mac 下树莓派4 烧录:

1. 树莓派烧录系统:

image

2. mac 通过 SSH 连接 树莓派:

image

# 树莓派 IP:
192.168.2.198

# 连接:
# 默认用户: pi
# 默认密码: raspberry
ssh pi@192.168.2.198

#########################

首次登录, 提示信息: 

henry@hh-imac27 [22时25分44秒] [~/Documents/iApp/ASUS]
-> % ssh pi@192.168.2.198
pi@192.168.2.198's password:
Linux raspberrypi 4.19.75-v7l+ #1270 SMP Tue Sep 24 18:51:41 BST 2019 armv7l

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Fri Mar 20 22:24:25 2020 from 192.168.2.10

SSH is enabled and the default password for the 'pi' user has not been changed.
This is a security risk - please login as the 'pi' user and type 'passwd' to set a new password.

image


# 更改默认密码: 

sudo passwd pi                    #修改 Pi 密码  
sudo passwd root                 #设置 root 密码    
su root                                #切换到 root 用户  
su pi                                    #切换到 pi 用户

3. SSH 通过 ssh-key 连接+禁用密码登录.

3.1 安装 vim:

su root
# 输入密码

apt install vim -y

3.2 添加 本地 ssh 公钥到树莓派:

# mac 的 ssh 公钥:

-> % ls ~/.ssh
id_rsa       id_rsa.pub   known_hosts  txy.sg.share

#########################

# 树莓派上操作: 

mkdir .ssh
# 创建: 
touch ~/.ssh/authorized_keys

# 使用 vi/vim 编辑上面的文件, 把 mac 的公钥, 拷贝到 authorized_keys 里. 
# 效果如下截图所示.
vim ~/.ssh/authorized_keys

image

3.3 禁用SSH 密码登录方式


vim /etc/ssh/sshd_config

## 找到如下配置项, 需要设置成: 

    AuthorizedKeysFile   .ssh/authorized_keys   //公钥公钥认证文件

    PubkeyAuthentication yes   //可以使用公钥登录

    PasswordAuthentication no  //不允许使用密码登录

image


# 重启: 
systemctl restart sshd.service

# 根据提示, 选择 root, 输入密码, 服务重启. 退出登录, 重新登录验证. 

image

hhstore commented 4 years ago

3.4 SSH 启用 2fa(谷歌验证器):

3.5 查看树莓派设备信息:


getconf LONG_BIT        # 查看系统位数
uname -a            # kernel 版本
/opt/vc/bin/vcgencmd  version   # firmware版本
strings /boot/start.elf  |  grep VC_BUILD_ID    # firmware版本
cat /proc/version       # kernel
cat /etc/os-release     # OS版本资讯
cat /etc/issue          # Linux distro 版本
cat /etc/debian_version     # Debian版本编号

#############

pi@raspberrypi:/etc/apt/sources.list.d $ lsb_release -a
No LSB modules are available.
Distributor ID: Raspbian
Description:    Raspbian GNU/Linux 10 (buster)
Release:    10
Codename:   buster

image

# 查看cpu温度
vcgencmd measure_temp

# 查看cpu信息
cat /proc/cpuinfo

lscpu

# 查看内存
free -h

# 查看磁盘
lsblk

df -hT

# 查看更多硬件信息
dmesg | more
# 查看时间
date

# 查看树莓派型号
cat /proc/device-tree/model

# 查看树莓派系统位数
getconf LONG_BIT

file /bin/ls

# 查看usb
lsusb

# 查看其他硬件
lsmod

# 查看CPU的时钟频率
vcgencmd get_config arm_freq

cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq
hhstore commented 4 years ago

3.5.2 fix error:

+ sh -c apt-get install -y -qq --no-install-recommends docker-ce >/dev/null
E: Sub-process /usr/bin/dpkg returned an error code (1)

fd:// --containerd=/run/containerd/containerd.sock (code=exited, status=1/FAILURE)

Failed to start Docker Application Container Engine.
sudo systemctl daemon-reload

sudo systemctl restart docker

systemctl restart docker.service
hhstore commented 4 years ago

3.6 树莓派 SD 卡扩展分区:

# 查看分区: 

pi@raspberrypi:~ $ df -h
文件系统        容量  已用  可用 已用% 挂载点
/dev/root       7.0G  6.7G  2.4M  100% /
devtmpfs        1.8G     0  1.8G    0% /dev
tmpfs           1.9G     0  1.9G    0% /dev/shm
tmpfs           1.9G   17M  1.9G    1% /run
tmpfs           5.0M  4.0K  5.0M    1% /run/lock
tmpfs           1.9G     0  1.9G    0% /sys/fs/cgroup
/dev/mmcblk0p1  253M   54M  199M   22% /boot
tmpfs           386M     0  386M    0% /run/user/1000

3.6.1 首选扩展方法:

# 
sudo raspi-config

# 选第7项 7 advanced options , 回车

image

image

image

image

image

pi@raspberrypi:~ $ df -h
文件系统        容量  已用  可用 已用% 挂载点
/dev/root        29G  6.6G   22G   24% /
devtmpfs        1.8G     0  1.8G    0% /dev
tmpfs           1.9G     0  1.9G    0% /dev/shm
tmpfs           1.9G  8.5M  1.9G    1% /run
tmpfs           5.0M  4.0K  5.0M    1% /run/lock
tmpfs           1.9G     0  1.9G    0% /sys/fs/cgroup
/dev/mmcblk0p1  253M   53M  200M   21% /boot
tmpfs           386M     0  386M    0% /run/user/1000

3.6.2 备选方法:

hhstore commented 4 years ago

3.7 设置 WIFI 联网:

3.7.1 局域网找到树莓派 IP:


# 使用 arp 扫描局域网 IP: 
henry@hh-imac27 [14时52分22秒] [~]
-> % arp -a
? (192.168.2.1) at d0:17:c2:3d:c8:b0 on en1 ifscope [ethernet]
? (192.168.2.10) at 14:20:5e:11:3c:7e on en1 ifscope permanent [ethernet]
? (192.168.2.73) at e4:2b:34:d7:b9:4d on en1 ifscope [ethernet]
? (192.168.2.76) at 58:6b:14:0:ab:5e on en1 ifscope [ethernet]
? (192.168.2.195) at 74:23:44:4a:94:1a on en1 ifscope [ethernet]
? (192.168.2.198) at dc:a6:32:60:8d:9f on en1 ifscope [ethernet]
? (224.0.0.251) at 1:0:5e:0:0:fb on en1 ifscope permanent [ethernet]
? (239.255.255.250) at 1:0:5e:7f:ff:fa on en1 ifscope permanent [ethernet]

# 安装: 
brew install nmap

# 扫描当前网段所有在线 IP: 
henry@hh-imac27 [14时49分04秒] [~]
-> % nmap -sP 192.168.2.0/24
Starting Nmap 7.80 ( https://nmap.org ) at 2020-03-22 14:49 CST
Nmap scan report for 192.168.2.1
Host is up (0.0036s latency).
Nmap scan report for 192.168.2.10
Host is up (0.00011s latency).
Nmap scan report for 192.168.2.76
Host is up (0.093s latency).
Nmap scan report for 192.168.2.198
Host is up (0.0043s latency).
Nmap done: 256 IP addresses (4 hosts up) scanned in 3.34 seconds

# 已知  192.168.2.198 是树莓派设备
# -A 参数, 查到 Raspbian, 可知是树莓派设备

-> % nmap -A 192.168.2.198
Starting Nmap 7.80 ( https://nmap.org ) at 2020-03-22 15:00 CST
Nmap scan report for 192.168.2.198
Host is up (0.0057s latency).
Not shown: 998 closed ports
PORT     STATE SERVICE VERSION
22/tcp   open  ssh     OpenSSH 7.9p1 Raspbian 10+deb10u2 (protocol 2.0)
| ssh-hostkey:
|   2048 07:cf:25:3d:65:88:86:da:c9:bc:0e:ed:6c:0a:4b:fd (RSA)
|   256 47:3a:72:1b:92:26:4c:bd:52:a7:08:6e:13:d7:f4:34 (ECDSA)
|_  256 4c:c2:0a:82:42:16:18:30:63:37:06:a7:9f:8e:80:e8 (ED25519)
5900/tcp open  vnc     RealVNC Enterprise 5.3 or later (protocol 5.0)
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 1.00 seconds

# 猜猜 IP 设备的 OS 信息: 
sudo nmap 192.168.2.198 -O --osscan-guess

3.7.2 树莓派连接 WIFI:


# 查看 无线网卡名: 
# 可知无线网卡名为 wlan0
pi@raspberrypi:~ $ ifconfig

# 查看树莓派网卡信息: 
pi@raspberrypi:~ $ iwconfig

# 获取设备工作状态信息
pi@raspberrypi:~ $ iw wlan0 info

# 获取设备连接状态信息(实测不包含IP地址)
pi@raspberrypi:~ $ iw dev wlan0 link
Not connected.

# 扫描无线网络,列表的内容都是实时更新的
iw dev wlan0 scan 
# 查看 当前 WIFI 热点列表: 
pi@raspberrypi:~ $ iwlist wlan0 scan | grep ESSID
                    ESSID:"ziroom602"
                    ESSID:"H-WIFI"
                    ESSID:"ChinaNet-GLRy"
                    ESSID:"HH-WIFI"

# 生成 WIFI 密码的辅助配置段, 贴到: /etc/wpa_supplicant/wpa_supplicant.conf   里
pi@raspberrypi:/etc/wpa_supplicant $ wpa_passphrase 'HH-WIFI' password
network={
    ssid="HH-WIFI"
    #psk="password"
    psk=25f42dfdb2cf545884c165ab98bf60d561c1140d7e1dbb48413c05391e40a436
}

# 注意要把 psk, 替换成真正的 WIFI 密码, 上面这个配置段, 只是方便 改配置用. 

sudo vim wpa_supplicant.conf

############################ 

ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=CN

network={
    ssid="BT_OFFICE_PHONE5G"
    psk="wifi-pwd"
    key_mgmt=WPA-PSK
}

# wifi2:
network={
    ssid="HH-WIFI"
    #psk="password"
        psk="wifi-pwd"
        key_mgmt=WPA-PSK
        priority=10
        id_str="hh"
}

image

image

pi@raspberrypi:~$ sudo systemctl restart networking  #重启网卡
pi@raspberrypi:~$ sudo ifdown wlan0   
pi@raspberrypi:~$ sudo ifup wlan0     
pi@raspberrypi:~$ wpa_cli status      #查看连接状态

image

# 通过 WIFI 的 IP 连接树莓派

ssh pi@192.168.2.199

image


sudo iwconfig

image

# pi @ raspberrypi in /etc [19:46:23]
$ sudo wpa_cli status
Selected interface 'p2p-dev-wlan0'
wpa_state=DISCONNECTED
p2p_device_address=3e:39:be:00:91:48
address=3e:39:be:00:91:48
uuid=8a412c29-3394-5231-858c-18a2e57802f4
# 重启: 
sudo reboot

# 关机: 
 sudo poweroff
 sudo init 0

3.7.3 设置静态 IP:

hhstore commented 4 years ago

4. 安装 docker:


## 最最关键的步骤, 切换 root 用户: 
su root

sudo apt update

image


# 添加 docker 镜像源: 
sudo echo "deb [arch=armhf] https://mirror.azure.cn/docker-ce/linux/raspbian buster stable" > /etc/apt/sources.list.d/docker.list

# 关键 + 必要步: 
sudo apt-get update -y && sudo apt-get upgrade -y

# 下载安装脚本: 
curl -fsSL https://get.docker.com -o get-docker.sh

chmod +x *.sh

# 执行安装脚本: 
sudo sh get-docker.sh

# 使用镜像, 报错, 还是用默认: (从安装脚本里, 找到镜像源参数)
sudo sh get-docker.sh  --mirror Aliyun
sudo sh get-docker.sh  --mirror AzureChinaCloud

参考清华源正确的安装方式:


su root

# 安装: 
sudo sh get-docker.sh --mirror Aliyun

# 添加用户: 
sudo groupadd docker
sudo usermod -aG docker $USER

# 启动: 
sudo systemctl enable docker
sudo systemctl start docker
sudo systemctl start docker.service

# 验证: 
docker run arm32v7/hello-world

image

4.2 卸载 docker:


sudo apt-get purge docker-ce
sudo apt autoremove docker-ce -y
sudo apt remove docker-ce -y
sudo rm -rf /var/lib/docker
alexellis commented 4 years ago

Looks like good progress on this thread.

The other thing that you may like is inlets, for a HTTPS tunnel for the cluster, it can expose an endpoint in Europe for instance. https://docs.inlets.dev/

hhstore commented 4 years ago

docker 镜像源:

cat /etc/docker/daemon.json

{
    "registry-mirrors": ["https://abc.mirror.aliyuncs.com"]
}
hhstore commented 4 years ago

ref:

hhstore commented 4 years ago

Looks like good progress on this thread.

The other thing that you may like is inlets, for a HTTPS tunnel for the cluster, it can expose an endpoint in Europe for instance. https://docs.inlets.dev/

thanks a lot, i will check it. @alexellis

hhstore commented 2 years ago

局域网搜索树莓派 IP 方法:


➤ ping raspberrypi
PING raspberrypi (10.211.1.91): 56 data bytes
64 bytes from 10.211.1.91: icmp_seq=0 ttl=64 time=6.477 ms
64 bytes from 10.211.1.91: icmp_seq=1 ttl=64 time=6.078 ms
64 bytes from 10.211.1.91: icmp_seq=2 ttl=64 time=4.519 ms