ini 提供Raspberry Pi SD卡

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ini 提供Raspberry Pi SD卡相关的知识,希望对你有一定的参考价值。

## You'll need

* Raspberry Pi 3, 3+ or 2 (only)
* A Linux PC, laptop or Raspberry with SD card reader/slot
* A number of Raspberry Pis configured with Ethernet

You must have an SSH key, if you don't know what this is then type in `ssh-keygen` and follow the instructions.

## Provision each Raspberry Pi:

1. Clone the gist and run `chmod +x make-rpi.sh`
2. Download the [Raspbian Lite](https://www.raspberrypi.org/downloads/raspbian/) image and place it in the folder
3. Populate your public SSH keys in `template-authorized_keys` on the Linux host. I.e. `cp ~/.ssh/id_rsa.pub template-authorized_keys`
4. Insert an SD card into your SD card reader
5. Edit `make-rpi.sh` and update `export DEV=` to the device you see on `lsblk` for your SD card reader
6. Edit `template-dhcpcd.conf` if your IP range isn't `192.168.0.0/24`
7. Run `sudo ./make-rpi node-1 101` to get `node-1.local` and `192.168.0.101` and so on.

Notes:

* For security log-in by password is disabled. If you want to log in via password then comment out the lines in `make-rpi.sh` 

## Create a cluster

On each Raspberry Pi run

```
curl -sLS https://get.docker.com | sudo sh
sudo usermod -aG docker pi
```

Then on one Raspberry Pi (master) run:

```
sudo apt update && sudo apt install -qy git
docker swarm init --advertise-addr=eth0
```

One each of the others run the `docker swarm join` command that you were issued.

## Deploy a distributed system

[OpenFaaS](https://www.openfaas.com/) provides a way for you to build functions and run them across the capacity of your cluster including metrics, monitoring and auto-scaling with support for many programming languages.

On the master node:

```
git clone https://github.com/openfaas/faas
cd faas
./deploy_stack.armhf.sh
```

Now open up the OpenFaaS UI with: http://master-ip:8080/ and click "Deploy Function" to deploy a function from the built-in function store, or follow a tutorial at [https://www.openfaas.com](www.openfaas.com).

For help etc contact me via Twitter @alexellisuk or Join @openfaas Slack #arm-and-pi channel.

See also:

* [Serverless Kubernetes home-lab with your Raspberry Pis](https://blog.alexellis.io/serverless-kubernetes-on-raspberry-pi/)
* [Your Serverless Raspberry Pi cluster with Docker Swarm](https://blog.alexellis.io/your-serverless-raspberry-pi-cluster/) (original article)
#!/bin/bash

if [[ $EUID -ne 0 ]]; then
   echo "This script must be run as root"
   exit 1
fi

if [ -z $1 ]; then
  echo "Usage: ./make-rpi.sh <hostname> <ip-suffix>"
  echo "       ./make-rpi.sh node-1 101"
  echo "       ./make-rpi.sh node-2 102"
  exit 1
fi

export DEV=sde
export IMAGE=2018-06-27-raspbian-stretch-lite.img

if [ -z "$SKIP_FLASH" ];
then
  echo "Writing Raspbian Lite image to SD card"
  time dd if=$IMAGE of=/dev/$DEV bs=1M
fi

sync

echo "Mounting SD card from /dev/$DEV"

mount /dev/${DEV}1 /mnt/rpi/boot
mount /dev/${DEV}2 /mnt/rpi/root

# Add our SSH key
mkdir -p /mnt/rpi/root/home/pi/.ssh/
cat template-authorized_keys > /mnt/rpi/root/home/pi/.ssh/authorized_keys

# Enable ssh
touch /mnt/rpi/boot/ssh

# Disable password login

sed -ie s/#PasswordAuthentication\ yes/PasswordAuthentication\ no/g /mnt/rpi/root/etc/ssh/sshd_config

echo "Setting hostname: $1"

sed -ie s/raspberrypi/$1/g /mnt/rpi/root/etc/hostname
sed -ie s/raspberrypi/$1/g /mnt/rpi/root/etc/hosts

# Reduce GPU memory to minimum
echo "gpu_mem=16" >> /mnt/rpi/boot/config.txt

# Set static IP
cp /mnt/rpi/root/etc/dhcpcd.conf /mnt/rpi/root/etc/dhcpcd.conf.orig

sed s/100/$2/g template-dhcpcd.conf > /mnt/rpi/root/etc/dhcpcd.conf

echo "Unmounting SD Card"

umount /mnt/rpi/boot
umount /mnt/rpi/root

sync
# A sample configuration for dhcpcd.
# See dhcpcd.conf(5) for details.

# Allow users of this group to interact with dhcpcd via the control socket.
#controlgroup wheel

# Inform the DHCP server of our hostname for DDNS.
hostname

# Use the hardware address of the interface for the Client ID.
clientid
# or
# Use the same DUID + IAID as set in DHCPv6 for DHCPv4 ClientID as per RFC4361.
# Some non-RFC compliant DHCP servers do not reply with this set.
# In this case, comment out duid and enable clientid above.
#duid

# Persist interface configuration when dhcpcd exits.
persistent

# Rapid commit support.
# Safe to enable by default because it requires the equivalent option set
# on the server to actually work.
option rapid_commit

# A list of options to request from the DHCP server.
option domain_name_servers, domain_name, domain_search, host_name
option classless_static_routes
# Most distributions have NTP support.
option ntp_servers
# Respect the network MTU. This is applied to DHCP routes.
option interface_mtu

# A ServerID is required by RFC2131.
require dhcp_server_identifier

# Generate Stable Private IPv6 Addresses instead of hardware based ones
slaac private

# Example static IP configuration:
#interface eth0
#static ip_address=192.168.0.10/24
#static ip6_address=fd51:42f8:caae:d92e::ff/64
#static routers=192.168.0.1
#static domain_name_servers=192.168.0.1 8.8.8.8 fd51:42f8:caae:d92e::1

# It is possible to fall back to a static IP if DHCP fails:
# define static profile
profile static_eth0
interface eth0
static ip_address=192.168.0.100/24
static routers=192.168.0.1
static domain_name_servers=8.8.8.8

以上是关于ini 提供Raspberry Pi SD卡的主要内容,如果未能解决你的问题,请参考以下文章

如何用树莓派Raspberry Pi做一个简单的控制系统

在大于32GB或64GB容量的SD卡上使用NOOB安装树莓派 - Using NOOB on SD cards larger than 32GB or 64GB for Raspberry Pi(代码

用Raspberry Pi搭建Azure IOT解决方案

ini 反向ssh / phone主页为Raspberry Pi

ini Raspberry Pi - ntp服务器配置。来自:https://frillip.com/raspberry-pi-stratum-1-ntp-server/

Raspberry Pi 3 Model B+ (树莓派3B+)快速上手