1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ラズパイのセットアップ (覚書)

Last updated at Posted at 2022-06-18

環境

ハード : Raspberry Pi 4 (4GB)
OS : "Raspberry Pi (64bit)"

初期設定する項目

セットアップするもの

Wifi, location, SSH

OSのイメージをインストールするときに設定すると簡単
pi000.png
pi001.png

OSセットアップ後に設定するときはsudo raspi-configで設定できる
pi002a.png
pi003.png
pi004.png
pi005.png

固定IP

sudo nano /etc/dhcpd.conf

dhcpd.conf
# 以下を追加
interface eth0
static ip_address=192.168.0.10/24
static routers=192.168.0.1
static domain_name_servers=
static domain_search=
noipv6 

--- OSのバージョン(bookworm)で仕様変更 ---

プロファイル確認

$sudo  nmcli connection show
NAME                UUID                                  TYPE      DEVICE
preconfigured       55dd2019-38f9-4b21-b160-d6408043729b  wifi      wlan0
lo                  cff20310-e389-4dd9-b607-b36de92abca9  loopback  lo
Wired connection 1  54d7c64b-aef7-3bde-b00d-249f1e0b383e  ethernet  eth0

Wired connection 1がeth0のプロファイル
固定IPを設定

sudo nmcli connection modify 'Wired connection 1' ipv4.method manual 
ip4.address 192.168.0.100/24 ipv4.gateway 192.168.0.1 ipv4.dns 192.168.0.1

設定の反映

sudo nmcli connection reload
sudo nmcli connection up 'Wired connection 1'

参考URL : dhcpcd.conf が無いraspberry piで固定IP(有線)のやり方

apt-get

とりあえずこれだけやっとく
sudo apt-get update
sudo apt-get upgrade

JAVA

jdkを入れればjreも入ります
sudo apt install default-jdk
確認するには
java -version

FTP

sudo apt-get install vsftpd

設定ファイルの以下の#を外す (コメントを外す)
sudo nano /etc/vsftpd.conf

vsftpd.conf
write_enable=YES
ascii_upload_enable=YES
ascii_download_enable=YES

サービスのリスタート
sudo service vsftpd restart

Apache2

sudo apt-get install apache2

PHP

sudo apt-get install php

npm

sudo apt-get install npm

nodejs

sudo apt-get install nodejs

chartjs

sudo nmp install chart.js --save

numpy

sudo apt-get install python3-numpy

matplot

sudo apt-get install python3-matoplotlib

MariaDB

MariaDB(mySQL Server)のインストール
sudo apt-get install mariadb-server

最初のセットアップ

sudo /usr/bin/mysql_secure_installation
聞かれるところ(とりあえずゆるゆるで全部"n")

Console
~$ sudo /usr/bin/mysql_secure_installation
Enter current password for root (enter for none):
Switch to unix_socket authentication [Y/n]
Change the root password? [Y/n]
Remove anonymous users? [Y/n]
Disallow root login remotely? [Y/n]
Remove test database and access to it? [Y/n]
Reload privilege tables now? [Y/n]

rootのパスワードを入力してください
unixのソケット認証に切り替えます
rootパスワードを変更しますか?
匿名ユーザを削除しますか?
リモートでrootログインを許可しません
テストデータベースを削除しますか?
privilegeテーブルをリロードしますか?

DB作成、ユーザ作成

sudo mariadb

MariaDB
-- DB作成
> create database testDB;
> show databases;			    -- 確認

-- user作成 user:testuser  pass:passwd
> create user testuser identified by 'passwd';
> select user,host,password from mysql.user;	-- 確認

-- 権限付与
> grant all on *.* to testuser@'%' identified by 'passwd' with grant option;
> show grants for testuser@'%';	-- 権限確認

> exit

MariaDB(mySQL)に入れるか確認
mysql -u testuser -p

MariaDB
> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| testDB             |
+--------------------+

外部から接続できるようにする

sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf

vim 50-server.cnf
#bind-address = 127.0.0,1		(#を付けてコメントアウト)

mySQLの再起動
sudo systemctl restart mysql

mySQLのログ出力

デバッグ時にSQLの確認したいとき
sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf

50-server.cnf
	general_log_file = /var/log/mysql/mysql.log
	general_log = 1

	slow_query_log_file = /var/log/mysql/mariadb-slow.log
	long_query_time = 10

DBの移行

他のPCなどからデータベースを移行するとき

バックアップ

移行元のデータベースでtestDBをバックアップする
mysqldump -u testuser -p testDB > testDB_backup.sql

データベース作成

移行先のデータベースでtestDBを作ってなかったら
mysqladmin -u testuser -p create testDB

リストア

移行先のデータベースにリストア
mysqldump -u testuser -p testDB < testDB_backup.sql

metabase

参考URL: https://obenkyolab.com/?p=1447
ここではユーザーpiにディレクトリ"metabase"を作ってセットアップします

ディレクトリ作成

cd
mkdir metabase

ダウンロード

↓ここからダウンロードして作ったディレクトリにコピーする
https://www.metabase.com/start/oss/

または、wgetでダウンロード

Console
$ sudo wget -O /opt/metabase/metabase.jar http://downloads.metabase.com/v0.43.3/metabase.jar

自動起動

ユニット定義ファイル作成

java -jar metabase.jar で実行できるけどサービスで起動できるように定義ファイルを作成
sudo nano /etc/systemd/system/metabase.service

metabase.service
[Unit]
Description = metabase server
After = syslog.target
After = network.target

[Service]
WorkingDirectory = /home/pi/metabase/
ExecStart = /usr/bin/java -jar /home/pi/metabase/metabase.jar
EnvironmentFile = /etc/default/metabase
User = root
Type = simple
StandardOutput = syslog
StandardError = syslog
SyslogIdentifier = metabase
SuccessExitStatus = 143
TimeoutStopSec = 120
Restart = always

[Install]
WantedBy = multi-user.target

syslogファイル作成

sudo nano /etc/rsyslog.d/metabase.conf

metabase.conf
if $programname == 'metabase' then /var/log/metabase.log
& stop

syslog再起動
sudo systemctl restart rsyslog.service

metabaseサービス登録

Console
$ sudo systemctl daemon-reload
$ sudo systemctl start metabase.service
$ sudo systemctl enable metabase.service
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?