forked from BarkinSpider/SolarShed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Pi Setup Cheat Sheet
339 lines (262 loc) · 10.6 KB
/
Pi Setup Cheat Sheet
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
# Install Raspian light and SolarMon tools(no GUI)
# v0.4k - 3/1/2021
# Allow at least 30 mins to do full install
# You must be connected to the Internet for updates and downloads
Download Noobs Lite, unzip the file into a new folder Called Pi
https://downloads.raspberrypi.org/NOOBS_lite_latest
Format your microSD card on your Windows machine as a standard single fat32 partition and copy all the Pi directory contents onto the new
disk
Remove the MicroSD card and insert it into the Pi. Attach akeyboard/mouse/monitor and boot the Pi.
add WiFi networking to your home network at Noobs install so you can download updates and easily login at boot after SSH enable
select Raspian minmal install only - this is key on the Pi Zero to save precious resources.
# after install and reboot login at the console as pi:raspian ....
% sudo bash
# raspi-config
- change pi passwd
- set hostname under 'network'
- set locale en_US.UTF-8 - remove all other locales
- set US 101 key PC keyboard with default settings
- set timezone America/Los Angeles
- enable SSH interface under 'Interfacing Options'
- enable serial console
exit from raspi-config
# edit /boot/config.txt (at end of file) to ensure serial console is enabled
enable_uart=1
earlycon=
# update firmware
rpi-update
# update software
apt-get update
apt-get upgrade
# get pip3 for python3 - all scripts must run Python3 not v2
apt-get install python3-pip
pip3 install pyserial
pip3 install minimalmodbus
# reboot with the new settings
init 6
#### End ####
# modify Wifi settings if needed ...
vi /etc/wpa_supplicant/wpa_supplicant.conf
wpa_cli -i wlan0 reconfigure
# test internet connection is good
ping inetd.com
# Add user solar - passwd 'solar' use defaults - copy your bash env to /home/solar and root home dirs
adduser solar
# enable sudo with no password
vi /etc/sudoers.d/010_pi-nopasswd
# change login banner
cat > /etc/motd
Inetd.Com QC server - all activity monitored and logged.
# create the ramdisk for ephemeral files
cat >> /etc/fstab
tmpfs /ramdisk tmpfs nodev,nosuid,size=1M 0 0
# check ramdisk is mounted correctly
mkdir /ramdisk
mount -a
df
now reboot and login remotely with SSH as user solar, check all is working ok
# Setting up as a Grafana server
( Check for new version - 7.3 used below)
###########################################
cd /home/solar
sudo bash
mkdir -p Dev/Grafana
cd Dev/Grafana
apt-get install -y adduser libfontconfig1
Pi 4 hardware ARM 7
wget https://dl.grafana.com/oss/release/grafana_7.3.6_armhf.deb
dpkg -i grafana_7.3.6_armhf.deb
# Pi Zero hardware ARM 6
wget https://dl.grafana.com/oss/release/grafana-rpi_7.3.6_armhf.deb
dpkg -i grafana-rpi_7.3.6_armhf.deb
grafana-cli plugins install grafana-clock-panel
grafana-cli plugins install briangann-gauge-panel
grafana-cli plugins install dalvany-image-panel
grafana-cli plugins install innius-video-panel
apt-get --fix-broken install
/bin/systemctl daemon-reload
/bin/systemctl enable grafana-server
/bin/systemctl start grafana-server
/bin/systemctl status grafana-server
# Download and install Prometheus and node_exporter
# Pi Zero hardware
wget https://github.com/prometheus/prometheus/releases/download/v2.19.0/prometheus-2.19.0.linux-armv6.tar.gz
wget https://github.com/prometheus/node_exporter/releases/download/v1.0.0/node_exporter-1.0.0.linux-armv6.tar.gz
# Pi 4 hardware
wget https://github.com/prometheus/prometheus/releases/download/v2.24.0-rc.0/prometheus-2.24.0-rc.0.linux-armv7.tar.gz
wget https://github.com/prometheus/node_exporter/releases/download/v1.0.1/node_exporter-1.0.1.linux-armv7.tar.gz
tar xvzf prometheus-*.gz
tar xvzf node_exporter-*.gz
cd prometheus*[6,7]
Add prometheus to systemctl so they start automatically at boottime
cat > prometheus.yml
# Global config
global:
scrape_interval: 10s # Set the scrape interval to every 15 seconds. Default is every 1 minute.
evaluation_interval: 15s # Evaluate rules every 15 seconds. The default is every 1 minute.
scrape_timeout: 10s # scrape_timeout is set to the global default (10s).
#
# Test with
# ./promtool check config prometheus.yml
# and tail /var/log/messages
#
scrape_configs:
#
# Unix server data
- job_name: 'node'
static_configs:
- targets: ['localhost:9100']
# run locally to ensure its working as expected...
./prometheus
Should end with - msg="Server is ready to receive web requests."
check interface at http://localhost:9090
enter 'node_load1' and press execute to see value and graph collected locally
cd ../node_exporter*[6,7]
./node_exporter --no-collector.mdadm --collector.textfile.directory=/ramdisk
Should end with - msg="Listening on" address=:9100
Check for data at http://localhost:9100/metrics
# Now test Grafana interface
goto http://<ipaddr>:3000/login admin:admin (skip updating passwd)
In configuration menu, add datasource as prometheus URL http://localhost:9090 - then Save&Test
Dashboard->Home
+ Create import
Cut n paste JSON from a working panel - look for 'share->export' on top right
######################### End ######################
######################### Additional notes - for debug only #########################
# Ensure everything restarts after reboot
chmod +x /etc/rc.local
systemctl status rc-local.service
# if problems - systemctl enable rc-local
# does /etc/systemd/system/rc-local.service exist?
[root@pi4]:(/home/joe) > cat /etc/systemd/system/rc-local.service
[Unit]
Description=/etc/rc.local Compatibility
ConditionPathExists=/etc/rc.local
[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99
[Install]
WantedBy=multi-user.target
# Then - systemctl enable rc-local
# add our scripts to rc.local before exit 0
vi /etc/rc.local
# Enable rc.local to start scripts
chmod +x /etc/rc.local
# Add before end of file
(/home/solar/restartSys.sh) &
domainname inetd.com
# /home/solar/restartSys.sh contains your local collector scripts that dump data into the /ramdisk
# vi /home/solar/restartSys.sh
#!/bin/bash
#
cd /home/solar/Dev/Grafana/prometheus*[6,7]
nohup ./prometheus &
cd /home/solar/Dev/Grafana/node_exporter*[6,7]
nohup ./node_exporter --no-collector.mdadm --collector.textfile.directory=/ramdisk &
# Here we start our local collector script that puts data into /ramdisk
# ./myScript.py
# End
# Optional
# Add Prometheus and node_exporter to systemctl so they start at boot automatically
# Local collector scripts are added to /home/solar/restartSys.sh
in browser goto Grafana home at localhost:3000 login:admin passwd:admin
Add prometheus data source
Import example dashboard from
https://grafana.com/grafana/dashboards?orderBy=name&direction=asc
ID: 10242 is a good example of system metrics
Do + -> Import on left of main page and Import ID 10242
Select Prometheus as a data source
Your new dashboard "Node Exporter Full with Node Name" should now be working
Look for it under Dashboards->home or Dashboards->Manage and search for Node.
Star the dasboard for easier access
Now we can start to add our own Solar monitoring metrics and graph them
First reboot machine with 'init 6' and confirm everything still works after a restart.
Additional notes -----
https://medium.com/@benmorel/creating-a-linux-service-with-systemd-611b5c8b91d6
https://www.digitalocean.com/community/tutorials/how-to-use-systemctl-to-manage-systemd-services-and-units
useradd -m -s /bin/bash prometheus
untar prometheus in its home dir
mkdir -p ~/prometheus/data
useradd -m -s /bin/bash node_exporter
untar node_exporter in its home dir
vi /etc/systemd/system/node_exporter.service
[Unit]
Description=Node Exporter
After=network.target
[Service]
User=node_exporter
Group=node_exporter
Type=simple
ExecStart=/usr/local/bin/node_exporter --no-collector.mdadm --collector.textfile.directory=/ramdisk
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl list-unit-files
systemctl edit --full node_exporter
systemctl status node_exporter
systemctl show node_exporter
systemctl cat node_exporter
systemctl enable node_exporter
systemctl disable node_exporter
systemctl restart node_exporter
#############################################
# add your local scripts here, use /dev/usb* interfaces - IMPORTANT!
# cd /home/joe
# ./pmAC2.py &
--or-- use crontab to run a prog at start
# crontab -e
@reboot /home/joe/restartSys.sh
#### For EPever inverter only ####
cat > ~joe/runGetSolarData.tcsh
#!/usr/bin/tcsh
# Check correct kernel mod is installed
insmod xr_usb_serial_common.ko
echo starting Epever serial data collection
while 1
/home/joe/Dev/EpSolar/epsolar-tracer-0.0.8/getTracerData.py > /ramdisk/solarData.txt.$$
sleep 1
date >> /ramdisk/solarData.txt.$$
mv /ramdisk/solarData.txt.$$ /ramdisk/solarData.txt
sleep 4
end
cx ~joe/runGetSolarData.tcsh
# for lsnet alias
apt-get install arp-scan
apt-get install lighttpd - for xtra reports only in /var/www/html/index.html
#### For EPever ####
pip3 install -U pymodbus
pip3 install -U serial
To compile kernel modules...
# apt-get install raspberrypi-kernel-headers
make module in /home/joe/Dev/xr_usb_serial_common-1a/
cp xr_usb_serial_common.ko /lib/modules/4.19.97+/kernel/drivers/tty/serial/
# remove competing cdc module
cat >> /etc/modprobe.d/blacklist-cdc_acm.conf
blacklist cdc_acm
echo "Start the Solar subsystem" >> /tmp/rc_test.txt.$$
(/home/solar/restartSys.sh) &
echo "ending rc.local" >> /tmp/rc_test.txt.$$
grafana-cli plugins install grafana-clock-panel
grafana-cli plugins install briangann-gauge-panel
grafana-cli plugins install dalvany-image-panel
grafana-cli plugins install innius-video-panel
/bin/systemctl restart grafana-server
####### Fix USB serial interfaces - must be rerun at each boot
# Makes USB serial ports assignment consistent and not randomly assigned. Absolute, not relative.
# Pi4 arch with built in 4 port USB hub
ln -sf /dev/serial/by-path/platform-fd500000.pcie-pci-0000:01:00.0-usb-0:1.0:1.0-port0 /dev/usb0
ln -sf /dev/serial/by-path/platform-fd500000.pcie-pci-0000:01:00.0-usb-0:1.1:1.0-port0 /dev/usb1
ln -sf /dev/serial/by-path/platform-fd500000.pcie-pci-0000:01:00.0-usb-0:1.2:1.0-port0 /dev/usb2
ln -sf /dev/serial/by-path/platform-fd500000.pcie-pci-0000:01:00.0-usb-0:1.3:1.0-port0 /dev/usb3
ln -sf /dev/serial/by-path/platform-fd500000.pcie-pci-0000:01:00.0-usb-0:1.4:1.0-port0 /dev/usb4
# Pi Zero arch with external 4 port USB hub
#ln -s /dev/serial/by-path/platform-20980000.usb-usb-0:1.1:1.0-port0 /dev/usb1
#ln -s /dev/serial/by-path/platform-20980000.usb-usb-0:1.2:1.0-port0 /dev/usb2
#ln -s /dev/serial/by-path/platform-20980000.usb-usb-0:1.3:1.0-port0 /dev/usb3
#ln -s /dev/serial/by-path/platform-20980000.usb-usb-0:1.4:1.0-port0 /dev/usb4
#ln -s /dev/serial/by-path/platform-20980000.usb-usb-0:1.0:1.0-port0 /dev/usb0
########