Raspberry Pi: Difference between revisions
mNo edit summary |
|||
| Line 137: | Line 137: | ||
For mouse and screen people. | For mouse and screen people. | ||
* https://www.raspberrypi.org/documentation/remote-access/vnc/ | * https://www.raspberrypi.org/documentation/remote-access/vnc/ | ||
= MySql (MariaDB) Remote admin access = | |||
For example with MySql workbench: | |||
* https://dev.mysql.com/downloads/file/?id=455790 | |||
Problem: can't connect to the server | |||
Comment bind-address to allow access from other machines: | |||
<syntaxhighlight lang=bash> | |||
sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf | |||
</syntaxhighlight> | |||
<blockquote> | |||
<syntaxhighlight lang=bash> | |||
... | |||
#bind-address = 127.0.0.1 | |||
... | |||
</syntaxhighlight> | |||
</blockquote> | |||
Restart database service: | |||
<syntaxhighlight lang=bash> | |||
sudo systemctl restart mariadb | |||
</syntaxhighlight> | |||
Problem: Host '...' is not allowed to connect to this MariaDB server | |||
Create admin user with all privileges and allow local network access. | |||
Note: we don't use 'root' because every database has this user and everybody knows it. | |||
Note: we allow only IP addresses starting with '192.168.1.'. | |||
<syntaxhighlight lang=bash> | |||
sudo -i | |||
mysql -u root mysql -p | |||
</syntaxhighlight> | |||
<syntaxhighlight lang=sql> | |||
GRANT ALL PRIVILEGES ON *.* TO 'admin'@'192.168.1.%' | |||
IDENTIFIED BY '**pwd**' | |||
WITH GRANT OPTION; | |||
FLUSH PRIVILEGES; | |||
\q | |||
</syntaxhighlight> | |||
Clear sql shell history: | |||
<syntaxhighlight lang=bash> | |||
> ~/.mysql_history | |||
</syntaxhighlight> | |||
Clear bash shell history: | |||
<syntaxhighlight lang=bash> | |||
history -c | |||
</syntaxhighlight> | |||
= Performance tuning = | = Performance tuning = | ||
Revision as of 20:18, 22 December 2017
LAMP stack
Linux - Apache - MySQL - PHP
Note: Mediawiki requires xml and mbstring packages
sudo apt-get install apache2 mysql-server php php-mysql php-xml php-mbstring
SSH Remote control
You can use remote shell to control your Raspberry Pi without directly connected mouse, keyboard and screen.
ssh pi@192.168.1.2
Ssh copy local file to remote machine
scp /path/to/local/file.zip pi@192.168.1.2:/home/pi/Downloads/file.zip
And back:
scp pi@192.168.1.2:/home/pi/Downloads/file.zip /path/to/local/file.zip
Nautilus ssh access, in the addressbar type:
ssh://pi@192.168.1.2
Ssh root access is not allowed by default but could be convenient for use with Nautilus Note: better set this back to 'no' when you are done
sudo nano /etc/ssh/sshd_config
PermitRootLogin yes
You can now access the machine as root with Nautilus, in the addressbar type:
ssh://root@192.168.1.2/
Allow ssh scripting without a password request, based on keys
You want the script to execute without it stopping to ask for a password.
Root session:
sudo -i
Generate keys, accept defaults:
ssh-keygen -t rsa
Create dir on remote:
ssh pi@192.168.1.2 mkdir -p .ssh
Add pub key to pi@192.168.1.2 authorized_keys:
cat .ssh/id_rsa.pub | ssh pi@192.168.1.2 'cat >> .ssh/authorized_keys'
Should work now without password:
ssh pi@192.168.1.2
Maybe needed, for some versions of ssh
cat .ssh/id_rsa.pub | ssh pi@192.168.1.2 'cat >> .ssh/authorized_keys2' ssh pi@192.168.1.2 chmod 700 .ssh ssh pi@192.168.1.2 chmod 640 .ssh/authorized_keys2
Require pi to enter password when sudo
By default the Raspbian pi user can sudo without the need to re-enter the password. If you don't like that make this change.
ssh pi@192.168.1.2 sudo nano /etc/sudoers.d/010_pi-nopasswd
Change it from:
pi ALL=(ALL) NOPASSWD: ALL
to
pi ALL=(ALL) ALL
VNC
For mouse and screen people.
MySql (MariaDB) Remote admin access
For example with MySql workbench:
Problem: can't connect to the server
Comment bind-address to allow access from other machines:
sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
... #bind-address = 127.0.0.1 ...
Restart database service:
sudo systemctl restart mariadb
Problem: Host '...' is not allowed to connect to this MariaDB server
Create admin user with all privileges and allow local network access.
Note: we don't use 'root' because every database has this user and everybody knows it.
Note: we allow only IP addresses starting with '192.168.1.'.
sudo -i mysql -u root mysql -p
GRANT ALL PRIVILEGES ON *.* TO 'admin'@'192.168.1.%'
IDENTIFIED BY '**pwd**'
WITH GRANT OPTION;
FLUSH PRIVILEGES;
\q
Clear sql shell history:
> ~/.mysql_history
Clear bash shell history:
history -c
Performance tuning
Memory
Raspberry Pi lowered GPU memory from 64 to 32 MB
CPU, Diskspace
Slim down Raspberry Pi by removing some packages ==
- Edu-related packages
apt-get -y remove --purge idle python3-pygame python-pygame python-tk idle3 python3-tk python3-rpi.gpio python-serial python3-serial python-picamera python3-picamera python3-pygame python-pygame python-tk python3-tk debian-reference-en dillo x2x scratch nuscratch timidity smartsim penguinspuzzle pistore sonic-pi python3-numpy python3-pifacecommon python3-pifacedigitalio python3-pifacedigital-scratch-handler python-pifacecommon python-pifacedigitalio oracle-java8-jdk minecraft-pi python-minecraftpi wolfram-engine apt-get -y autoremove
Remove all packages marked 'rc'.
dpkg --list |grep "^rc" | cut -d " " -f 3 | xargs dpkg --purge