onsdag 12 juni 2019

MySQL on USB disk with Raspbian

#Install MySQL
sudo apt-get install -y mysql-server

#Stop daemon
sudo /etc/init.d/mysql stop

#Copy data
sudo cp -Rp /var/lib/mysql /usbdisc

#Manualy edit config file to change data dir
sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf 

datadir = /usbdisc/mysql
#bind-address            = 127.0.0.1


#Start MySQL
sudo /etc/init.d/mysql start



#Create root user
sudo mysql -u root
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
exit



#*************************************************** 
#**********            Misc               **********
#***************************************************


#Config directory
/etc/mysql


#Uninstall
sudo apt-get remove --purge mysql-server mysql-client mysql-common -y

sudo apt-get autoremove -y

sudo apt-get autoclean

#Remove the MySQL folder:
rm -rf /etc/mysql

#Delete all MySQL files on your server. This is dangerous!!!
sudo find / -iname 'mysql*' -exec rm -rf {} \;


pi02 Installation

#Update system
sudo apt-get update && sudo apt-get -y dist-upgrade

#List all available disks
sudo lsblk -o UUID,NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL,MODEL

#Create mount point
sudo mkdir /usbdisc

#Configure disc mounting
sudo nano /etc/fstab

/dev/sda1 /usbdisc ext4 defaults,errors=remount-ro 0 1

#Mount disc
sudo mount -a


#
# Install MySQL
#
sudo apt-get install -y mysql-server
sudo apt-get install -y mariadb-server

#Stop daemon
sudo /etc/init.d/mysql stop
sudo systemctl stop mysqld

#Copy data
sudo cp -Rp /var/lib/mysql /usbdisc

#Manualy edit config file to change data dir
sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
datadir = /usbdisc/mysql
#bind-address = 127.0.0.1

#Start MySQL
sudo /etc/init.d/mysql start
sudo systemctl start mysqld

#Create root user
sudo mysql -u root
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
exit;

!!! Just saving data dir does not work, need to create backup scripts!


#
# Install InfluxDB
# Source: 
https://pimylifeup.com/raspberry-pi-influxdb/

wget -qO- https://repos.influxdata.com/influxdb.key | sudo apt-key add -

echo "deb https://repos.influxdata.com/debian buster stable" | sudo tee /etc/apt/sources.list.d/influxdb.list

sudo apt-get update

sudo apt-get install influxdb

#Manually edit config file
sudo nano /etc/influxdb/influxdb.conf

[meta]
dir = "/usbdisc/influxdb/meta"

[data]
dir = "/usbdisc/influxdb/data"

#Note! Did not change wal-dir

[http]
enabled = true


mkdir /usbdisc/influxdb

sudo chown influxdb:influxdb /usbdisc/influxdb/

sudo systemctl unmask influxdb
sudo systemctl enable influxdb

sudo systemctl start influxdb

#Takes long time to start! Syslog says Started, but keep waiting, more to come
tail /var/log/syslog -f

#Connecting also takes serious long time!
sudo influx
> CREATE USER grafana WITH PASSWORD '***' WITH ALL PRIVILEGES
> CREATE USER 'homeassistant' WITH PASSWORD '***' WITH ALL PRIVILEGES
> CREATE DATABASE homeassistant
> exit

#Manually edit config file again
sudo nano /etc/influxdb/influxdb.conf

[http]
auth-enabled = true
pprof-enabled = true
pprof-auth-enabled = true
ping-auth-enabled = true

sudo systemctl restart influxdb