paloma blog

NWエンジニアやってます。主に自宅環境のお遊びを書きます。Pythonもちょっと。タイトルは好きなカクテルから。

Baculaでバックアップを取ってみる

なんとかバックアップを取ることに成功したのでメモ。
baculaサーバ自身のバックアップです。

作業概要

  • 設定ファイルを一回リストアした

    • いかにも不要そうな設定は消して動かしてみたのですが、ストレージデーモンに接続できなくなってしまいました。
      デフォルトのconfigをリストアしてパスワードのみ変えて動かしました。
  • 外部ストレージにアクセスできなかった

    • baculaサーバはVMであがってます
    • バックアップ先をホストの外部ストレージにしました。
      しかしマウント、書き込みはOKだったのですがバックアップを開始するとプロセスが進まなかったので一旦ローカルに戻しました。

設定ファイルのメモ

公式マニュアルをに詳しくあると思いますが、一旦自分用のメモ

bacula-dir

  • job、jobdef

    • バックアップのジョブ
    • デフォルト(jobdef)から追記していくっぽい
  • Storage

    • bacula-dirのStorageはlocalhostを設定しない
      各ファイルデーモンはここの設定に見に行く
  • Autochanger

    • Storageのクラスタ
      設定しなくてもOKっぽい
  • Client

    • バックアップ対象クライアントのIP指定
  • Fileset

bacula-sd

  • Autochanger

    • Deviceのクラスタ
    • Nameがディレクタと紐づいているっぽい
  • Device

    • バックアップファイル保存場所
    • Filetypeはディレクタと紐づいている

bacula-fd

  • 各クライアントに設定

バックアップ実行してみる

bconsoleでbaculaコンソールにはいってrunで実行します。
1は設定したバックアップクライアント、2はデータベースのバックアップのようです。
3は不明…

*run
Automatically selected Catalog: MyCatalog
Using Catalog "MyCatalog"
A job name must be specified.
The defined Job resources are:
     1: BackupClient1
     2: BackupCatalog
     3: RestoreFiles
Select Job resource (1-3): 1
Run Backup job
JobName:  BackupClient1
Level:    Incremental
Client:   bacula-fd
FileSet:  Full Set
Pool:     File (From Job resource)
Storage:  File1 (From Job resource)
When:     2018-06-05 20:00:00
Priority: 10
OK to run? (yes/mod/no): yes
Job queued. JobId=32
You have messages.
*

完了すると履歴に出ます。
日付のところが文字化けしてるけど何だろ?
あとErrorが出てるのは過去の失敗の履歴です。

*status dir
bacula-dir Version: 9.0.6 (20 November 2017) x86_64-redhat-linux-gnu redhat (Core)
Daemon started 05- 6��2018 18:56, conf reloaded 05- 6-2018 18:56:52
 Jobs: run=4, running=0 mode=0,0
 Heap: heap=270,336 smbytes=142,664 max_bytes=185,328 bufs=335 max_bufs=389
 Res: njobs=3 nclients=1 nstores=2 npools=3 ncats=1 nfsets=2 nscheds=2

Scheduled Jobs:
Level          Type     Pri  Scheduled          Job Name           Volume
===================================================================================
Incremental    Backup    10  05- 6��2018 23:05  BackupClient1      Vol-0019
Full           Backup    11  05- 6��2018 23:10  BackupCatalog      Vol-0019
====

Running Jobs:
Console connected at 05- 6��2018 19:59
No Jobs running.
====

Terminated Jobs:
 JobId  Level      Files    Bytes   Status   Finished        Name 
====================================================================
    23  Full           0         0   Error    03- 6��2018 23:05 JOB-Bacula-ubuntu
    24  Full           0         0   Error    03- 6��2018 23:05 BackupClient1
    25  Full           0         0   Error    03- 6��2018 23:10 BackupCatalog
    26  Full           0         0   Error    04- 6��2018 23:05 JOB-Bacula-ubuntu
    27  Full           0         0   Error    04- 6��2018 23:05 BackupClient1
    28  Full           0         0   Error    04- 6��2018 23:10 BackupCatalog
    29  Full           0         0   Incomplete  05- 6��2018 19:18 BackupClient1
    30  Full           0         0   Incomplete  05- 6��2018 19:32 BackupClient1
    31  Full           0         0   Cancel   05- 6��2018 19:59 BackupClient1
    32  Full      70,123    1.423 G  OK       05- 6��2018 20:05 BackupClient1  # 先ほどの成功ログ

====
*

リストアしてみる

クライアントのリストアは5番を選択します。
対象クライアントは2番の自信です。
1は別のマシンなので今度バックアップからやります。
Full setで取ったファイルをリストアになるようです。

*restore 
Automatically selected Catalog: MyCatalog
Using Catalog "MyCatalog"

First you select one or more JobIds that contain files
to be restored. You will be presented several methods
of specifying the JobIds. Then you will be allowed to
select which files from those JobIds are to be restored.

To select the JobIds, you have the following choices:
     1: List last 20 Jobs run
     2: List Jobs where a given File is saved
     3: Enter list of comma separated JobIds to select
     4: Enter SQL list command
     5: Select the most recent backup for a client
     6: Select backup for a client before a specified time
     7: Enter a list of files to restore
     8: Enter a list of files to restore before a specified time
     9: Find the JobIds of the most recent backup for a client
    10: Find the JobIds for a backup for a client before a specified time
    11: Enter a list of directories to restore for found JobIds
    12: Select full restore to a specified Job date
    13: Cancel
Select item:  (1-13): 5
Defined Clients:
     1: PC-ubuntu-fd
     2: bacula-fd
Select the Client (1-2): 2
The defined FileSet resources are:
     1: Catalog
     2: Full Set
Select FileSet resource (1-2): 2
+-------+-------+----------+---------------+---------------------+------------+
| JobId | Level | JobFiles | JobBytes      | StartTime           | VolumeName |
+-------+-------+----------+---------------+---------------------+------------+
|    32 | F     |   70,123 | 1,423,788,515 | 2018-06-05 20:00:05 | Vol-0019   |
+-------+-------+----------+---------------+---------------------+------------+
You have selected the following JobId: 32

Building directory tree for JobId(s) 32 ...  +++++++++++++++++++++++++++++++++++++++++
57,724 files inserted into the tree.

続いて対象のファイルを選択します。
今回はbaculaのディレクトリをリストアしてみます。
configは私は作成した退避用ディレクトリです。

You are now entering file selection mode where you add (mark) and
remove (unmark) files to be restored. No files are initially added, unless
you used the "all" keyword on the command line.
Enter "done" to leave this mode.

cwd is: /
$ cd /etc/
cwd is: /etc/
$ cd bacula
cwd is: /etc/bacula/
$ ls
bacula-dir.conf
bacula-dir.conf.org
bacula-fd.conf
bacula-fd.conf.org
bacula-sd.conf
bacula-sd.conf.org
bconsole.conf
bconsole.conf.org
config/
query.sql
$ 

移動したらmarkします。
つけたファイルのみリストアされます。
doneで実行。
空エンターはエラーになってます。

$ mark *
12 files marked.
$ 
Invalid command "".  Enter "done" to exit.
$ ls
*bacula-dir.conf
*bacula-dir.conf.org
*bacula-fd.conf
*bacula-fd.conf.org
*bacula-sd.conf
*bacula-sd.conf.org
*bconsole.conf
*bconsole.conf.org
*config/
*query.sql
$ 
Invalid command "".  Enter "done" to exit.
$ 
Invalid command "".  Enter "done" to exit.
$ done

いろいろ出て完了。

Bootstrap records written to /var/spool/bacula/bacula-dir.restore.1.bsr

The Job will require the following (*=>InChanger):
   Volume(s)                 Storage(s)                SD Device(s)
===========================================================================
   
    Vol-0019                  File1                     FileChgr1                

Volumes marked with "*" are in the Autochanger.


14 files selected to be restored.

Using Catalog "MyCatalog"
Run Restore job
JobName:         RestoreFiles
Bootstrap:       /var/spool/bacula/bacula-dir.restore.1.bsr
Where:           /tmp/bacula-restores
Replace:         Always
FileSet:         Full Set
Backup Client:   bacula-fd
Restore Client:  bacula-fd
Storage:         File1
When:            2018-06-05 20:09:15
Catalog:         MyCatalog
Priority:        10
Plugin Options:  *None*
OK to run? (yes/mod/no): yes
Job queued. JobId=33
*

デフォルトは/tmp/bacula-restores配下にリストアされるようです。

[root@bacula bacula]# ls -l /tmp/bacula-restores/etc/bacula/
合計 68
-rw-r-----. 1 root   root   9165  65 18:42 bacula-dir.conf
-rw-r-----. 1 bacula bacula 9186  519 19:29 bacula-dir.conf.org
-rw-r-----. 1 bacula bacula 1048  65 18:44 bacula-fd.conf
-rw-r-----. 1 bacula bacula 1067  524 19:01 bacula-fd.conf.org
-rw-r-----. 1 root   root   9795  65 19:59 bacula-sd.conf
-rw-r-----. 1 bacula bacula 9814  524 19:06 bacula-sd.conf.org
-rw-r-----. 1 bacula bacula  239  524 19:09 bconsole.conf
-rw-r-----. 1 bacula bacula  249  524 19:09 bconsole.conf.org
drwxr-xr-x. 2 root   root     51  65 18:39 config
-rw-r-----. 1 bacula bacula  312  129 21:38 query.sql
[root@bacula bacula]# 

元のディレクトリ見ると同じ状態になってますね。
ファイルのリストアができました!

[root@bacula bacula]# ls -l /etc/bacula/
合計 68
-rw-r-----. 1 root   root   9165  65 18:42 bacula-dir.conf
-rw-r-----. 1 bacula bacula 9186  519 19:29 bacula-dir.conf.org
-rw-r-----. 1 bacula bacula 1048  65 18:44 bacula-fd.conf
-rw-r-----. 1 bacula bacula 1067  524 19:01 bacula-fd.conf.org
-rw-r-----. 1 root   root   9795  65 19:59 bacula-sd.conf
-rw-r-----. 1 bacula bacula 9814  524 19:06 bacula-sd.conf.org
-rw-r-----. 1 bacula bacula  239  524 19:09 bconsole.conf
-rw-r-----. 1 bacula bacula  249  524 19:09 bconsole.conf.org
drwxr-xr-x. 2 root   root     51  65 18:39 config
-rw-r-----. 1 bacula bacula  312  129 21:38 query.sql
[root@bacula bacula]# 

バックアップはルートディレクトリから取ってるのでリストア先をルートにすればOSごとリストア出来るんですかね?
余裕があればやってみます。

バックアップの残作業

  • ubuntuのバックアップを取る
  • Windoswsのバックアップを取る
  • バックアップ先を別ディレクトリにする。

とりあえずバックアップを取れればよいのでConfigの精査は後回しにします。
次はubuntuのバックアップをやってみます。

Baculaでバックアップ環境を構築する

今年の始めにメイン機が壊れてはや5ヶ月。
ようやく環境は戻ったのでそろそろバックアップをとろうと思います。
HDDが壊れた時の再イントールはめんどくさいですからね。

今は主に使っているのがwindowsubuntuがあるので両方のバックアップがとれるソフトにしたいと思います。
というわけでいい感じにできそうなBaculaで環境を作ります。

https://blog.bacula.org/

www.bacula.jp

私は普段ネットワークエンジニアとして働いているので、恥ずかしながらサーバやマシンのシステムバックアップはしっかり取ったことありません。
NW機器はtextのconfigファイルとっとけばなんとかなるんです。
仮想マシンならゲストのクローンとかスナップショットってイメージつくんですが、物理マシンはなかなか・・・。
ちゃんとできるかな。

環境

bacula.jpの手順に沿ってやりたいと思います。

www.bacula.jp

CentOS7でインストールするみたいですが、環境がないので取り急ぎVirutalboxのVMで構築します。
(今気づきましたがホスト名のスペルミスってました。次直します。)

[root@bakula ~]# cat /etc/centos-release
CentOS Linux release 7.5.1804 (Core) 
[root@bakula ~]# uname -a
Linux bakula 3.10.0-862.2.3.el7.x86_64 #1 SMP Wed May 9 18:05:47 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

CentOS7のminimalイメージから手順のとおり設定します。

  • Firewalld停止
[root@bakula ~]# systemctl stop firewalld
[root@bakula ~]# 
[root@bakula ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: inactive (dead) since 日 2018-05-13 21:42:29 JST; 8s ago
     Docs: man:firewalld(1)
  Process: 665 ExecStart=/usr/sbin/firewalld --nofork --nopid $FIREWALLD_ARGS (code=exited, status=0/SUCCESS)
 Main PID: 665 (code=exited, status=0/SUCCESS)

 513 21:34:06 bakula systemd[1]: Starting firewalld - dynamic firewall daemon...
 513 21:34:08 bakula systemd[1]: Started firewalld - dynamic firewall daemon.
 513 21:42:28 bakula systemd[1]: Stopping firewalld - dynamic firewall daemon...
 513 21:42:29 bakula systemd[1]: Stopped firewalld - dynamic firewall daemon.
[root@bakula ~]# 
[root@bakula ~]# cd /etc/yum.repos.d/
[root@bakula yum.repos.d]# ls
CentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Sources.repo  CentOS-fasttrack.repo
CentOS-CR.repo    CentOS-Media.repo      CentOS-Vault.repo
[root@bakula yum.repos.d]# 
[root@bakula yum.repos.d]#  wget https://copr.fedorainfracloud.org/coprs/slaanesh/Bacula/repo/epel-7/slaanesh-Bacula-epel-7.repo
--2018-05-13 21:43:16--  https://copr.fedorainfracloud.org/coprs/slaanesh/Bacula/repo/epel-7/slaanesh-Bacula-epel-7.repo
copr.fedorainfracloud.org (copr.fedorainfracloud.org) をDNSに問いあわせています... 209.132.184.54
copr.fedorainfracloud.org (copr.fedorainfracloud.org)|209.132.184.54|:443 に接続しています... 接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 326 [text/plain]
`slaanesh-Bacula-epel-7.repo' に保存中

100%[======================================================================================>] 326         --.-K/s 時間 0s      

2018-05-13 21:43:23 (45.5 MB/s) - `slaanesh-Bacula-epel-7.repo' へ保存完了 [326/326]
  • パッケージインストール
[root@bakula yum.repos.d]# yum -y install bacula-director bacula-client bacula-storage bacula-console mariadb-server
読み込んだプラグイン:fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.tsukuba.wide.ad.jp
 * extras: ftp.tsukuba.wide.ad.jp
 * updates: ftp.tsukuba.wide.ad.jp
slaanesh-Bacula                                                                                          | 3.0 kB  00:00:00     
slaanesh-Bacula/x86_64/primary_db                                                                        |  13 kB  00:00:06     
依存性の解決をしています
--> トランザクションの確認を実行しています。
...
完了しました!
  • 確認
    • Baculaですが、今時点では系が最新のようです。
[root@bakula yum.repos.d]# rpm -qa | grep bacula
bacula-common-9.0.6-5.el7.centos.x86_64
bacula-libs-sql-9.0.6-5.el7.centos.x86_64
bacula-director-9.0.6-5.el7.centos.x86_64
bacula-client-9.0.6-5.el7.centos.x86_64
bacula-libs-9.0.6-5.el7.centos.x86_64
bacula-storage-9.0.6-5.el7.centos.x86_64
bacula-console-9.0.6-5.el7.centos.x86_64
[root@bakula yum.repos.d]# 
[root@bakula yum.repos.d]# rpm -qa | grep mariadb
mariadb-5.5.56-2.el7.x86_64
mariadb-server-5.5.56-2.el7.x86_64
mariadb-libs-5.5.56-2.el7.x86_64
[root@bakula yum.repos.d]# 
[root@bakula yum.repos.d]# systemctl start mariadb
[root@bakula yum.repos.d]# 
[root@bakula yum.repos.d]# systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
[root@bakula yum.repos.d]# 
[root@bakula yum.repos.d]# systemctl status mariadb
● mariadb.service - MariaDB database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
   Active: active (running) since 日 2018-05-13 21:49:48 JST; 16s ago
 Main PID: 10779 (mysqld_safe)
   CGroup: /system.slice/mariadb.service
           ├─10779 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
           └─10941 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-err...

 513 21:49:46 bakula mariadb-prepare-db-dir[10701]: MySQL manual for more instructions.
 513 21:49:46 bakula mariadb-prepare-db-dir[10701]: Please report any problems at http://mariadb.org/jira
 513 21:49:46 bakula mariadb-prepare-db-dir[10701]: The latest information about MariaDB is available at http://mari...org/.
 513 21:49:46 bakula mariadb-prepare-db-dir[10701]: You can find additional information about the MySQL part at:
 513 21:49:46 bakula mariadb-prepare-db-dir[10701]: http://dev.mysql.com
 513 21:49:46 bakula mariadb-prepare-db-dir[10701]: Consider joining MariaDB's strong and vibrant community:
 5月 13 21:49:46 bakula mariadb-prepare-db-dir[10701]: https://mariadb.org/get-involved/
 5月 13 21:49:47 bakula mysqld_safe[10779]: 180513 21:49:47 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.
 5月 13 21:49:47 bakula mysqld_safe[10779]: 180513 21:49:47 mysqld_safe Starting mysqld daemon with databases from /va.../mysql
 5月 13 21:49:48 bakula systemd[1]: Started MariaDB database server.
Hint: Some lines were ellipsized, use -l to show in full.
[root@bakula yum.repos.d]# 
  • セキュアインストール
[root@bakula yum.repos.d]# mysql_secure_installation 

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
 ... Success!

By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!
[root@bakula yum.repos.d]# 
  • データベース&ユーザ作成
[root@bakula yum.repos.d]# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 11
Server version: 5.5.56-MariaDB MariaDB Server

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 
MariaDB [(none)]> show tables;
ERROR 1046 (3D000): No database selected
MariaDB [(none)]> 
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.00 sec)

MariaDB [(none)]> 
MariaDB [(none)]> create database bacula;
Query OK, 1 row affected (0.00 sec)

MariaDB [(none)]> 
MariaDB [(none)]> grant all privileges on bacula.* to bacula@localhost identified by 'password"
    '> ;
    '> 
    '> ;
    '> Ctrl-C -- exit!
Aborted
[root@bakula yum.repos.d]# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 12
Server version: 5.5.56-MariaDB MariaDB Server

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> 
MariaDB [(none)]> grant all privileges on bacula.* to bacula@localhost identified by 'password';
Query OK, 0 rows affected (0.00 sec)

MariaDB [(none)]> 
MariaDB [(none)]> quit
Bye
  • Bacula用テーブル作成
[root@bakula yum.repos.d]# /usr/libexec/bacula/make_bacula_tables mysql -u bacula -p
Making mysql tables
Enter password: 
Creation of Bacula MySQL tables succeeded.
[root@bakula yum.repos.d]# 
  • 使用するデータベース選択
[root@bakula yum.repos.d]#  alternatives --config libbaccats.so

3 プログラムがあり 'libbaccats.so' を提供します。

  選択       コマンド
-----------------------------------------------
   1           /usr/lib64/libbaccats-mysql.so
   2           /usr/lib64/libbaccats-sqlite3.so
*+ 3           /usr/lib64/libbaccats-postgresql.so

Enter を押して現在の選択 [+] を保持するか、選択番号を入力します:1
[root@bakula yum.repos.d]# 
[root@bakula yum.repos.d]# alternatives --config libbaccats.so

3 プログラムがあり 'libbaccats.so' を提供します。

  選択       コマンド
-----------------------------------------------
 + 1           /usr/lib64/libbaccats-mysql.so
   2           /usr/lib64/libbaccats-sqlite3.so
*  3           /usr/lib64/libbaccats-postgresql.so

Enter を押して現在の選択 [+] を保持するか、選択番号を入力します:
[root@bakula yum.repos.d]# 

ここまででインストール完了。
configをいじっていきます。

設定ファイル

Baculaサーバ設定 | Bacula

これもサイトのとおり設定します。 いろいろパラメータがありますが、まだ触り始めたばかりなので、慣れてきたらカスタムしていこうと思います。

3つデーモンを動かすようですね。

  1. Directorデーモン
    • 全体管理。DB連携もやる。
  2. Storageデーモン
    • バックアップしたデータ管理
  3. Fileデーモン
    • バックアップ対象マシンにインストールする

それぞれバックアップ取って設定。

[root@bakula ~]# cp /etc/bacula/bacula-dir.conf{,.org} 
[root@bakula ~]# vi /etc/bacula/bacula-dir.conf
[root@bakula ~]# 
[root@bakula ~]# cd /etc/bacula/
[root@bakula bacula]# ls
bacula-dir.conf  bacula-dir.conf.org  bacula-fd.conf  bacula-sd.conf  bconsole.conf  query.sql
[root@bakula bacula]# 
[root@bakula bacula]# cp bacula-fd.conf{,.org}
[root@bakula bacula]# 
[root@bakula bacula]# vi bacula-fd.conf 
[root@bakula bacula]# 
[root@bakula bacula]# ls
bacula-dir.conf  bacula-dir.conf.org  bacula-fd.conf  bacula-fd.conf.org  bacula-sd.conf  bconsole.conf  query.sql
[root@bakula bacula]# 
[root@bakula bacula]# cp bacula-sd.conf{,.org}
[root@bakula bacula]# 
[root@bakula bacula]# vi bacula-sd.conf
[root@bakula bacula]# ls
bacula-dir.conf      bacula-fd.conf      bacula-sd.conf      bconsole.conf
bacula-dir.conf.org  bacula-fd.conf.org  bacula-sd.conf.org  query.sql
[root@bakula bacula]# 
[root@bakula bacula]# cp bconsole.conf{,.org}
[root@bakula bacula]# 
[root@bakula bacula]# vi bconsole.conf
  • 起動します
[root@bakula bacula]# systemctl start bacula-dir
[root@bakula bacula]# systemctl start bacula-sd
[root@bakula bacula]# systemctl start bacula-fd
  • 確認
    • bacula-dirだけFileset部分の構文をミスっていたのであとから取りました。
[root@bakula bacula]# systemctl status bacula-dir
● bacula-dir.service - Bacula-Director, the Backup-server
   Loaded: loaded (/usr/lib/systemd/system/bacula-dir.service; disabled; vendor preset: disabled)
   Active: active (running) since 木 2018-05-24 22:51:42 JST; 7s ago
     Docs: man:bacula-dir(8)
 Main PID: 7506 (bacula-dir)
   CGroup: /system.slice/bacula-dir.service
           └─7506 /usr/sbin/bacula-dir -f -c /etc/bacula/bacula-dir.conf -u bacula -g bacula

 524 22:51:42 bakula systemd[1]: Started Bacula-Director, the Backup-server.
 524 22:51:42 bakula systemd[1]: Starting Bacula-Director, the Backup-server...
[root@bakula bacula]# 
[root@bakula bacula]# systemctl status bacula-fd
● bacula-fd.service - Bacula-FileDaemon, a Backup-client
   Loaded: loaded (/usr/lib/systemd/system/bacula-fd.service; disabled; vendor preset: disabled)
   Active: active (running) since 木 2018-05-24 20:53:03 JST; 29s ago
     Docs: man:bacula-fd(8)
 Main PID: 7221 (bacula-fd)
   CGroup: /system.slice/bacula-fd.service
           └─7221 /usr/sbin/bacula-fd -f -c /etc/bacula/bacula-fd.conf -u root -g root

 524 20:53:03 bakula systemd[1]: Started Bacula-FileDaemon, a Backup-client.
 524 20:53:03 bakula systemd[1]: Starting Bacula-FileDaemon, a Backup-client...
[root@bakula bacula]# 
[root@bakula bacula]# systemctl status bacula-sd
● bacula-sd.service - Bacula-StorageDaemon, the storage-server
   Loaded: loaded (/usr/lib/systemd/system/bacula-sd.service; disabled; vendor preset: disabled)
   Active: active (running) since 木 2018-05-24 20:53:01 JST; 39s ago
     Docs: man:bacula-sd(8)
 Main PID: 7212 (bacula-sd)
   CGroup: /system.slice/bacula-sd.service
           └─7212 /usr/sbin/bacula-sd -f -c /etc/bacula/bacula-sd.conf -u bacula -g tape

 524 20:53:01 bakula systemd[1]: Started Bacula-StorageDaemon, the storage-server.
 524 20:53:01 bakula systemd[1]: Starting Bacula-StorageDaemon, the storage-server...
[root@bakula bacula]# 
  • listenポート確認
[root@bakula ~]# ss -lnt
State      Recv-Q Send-Q                   Local Address:Port                                  Peer Address:Port              
LISTEN     0      50                                   *:3306                                             *:*                  
LISTEN     0      50                                   *:9101                                             *:*                  
LISTEN     0      50                                   *:9102                                             *:*                  
LISTEN     0      50                                   *:9103                                             *:*                  
LISTEN     0      128                                  *:22                                               *:*                  
LISTEN     0      100                          127.0.0.1:25                                               *:*                  
LISTEN     0      128                                 :::22                                              :::*                  
LISTEN     0      100                                ::1:25                                              :::*                  
[root@bakula ~]# 
[root@bakula ~]# 
  1. Directorデーモン:9101
  2. Storageデーモン:9103
  3. Fileデーモン:9102

らしいです。

とりあえずサービスは立ち上がったので、次回マシンのバックアップを取ってみたいと思います。
この辺の動きが確認できたらGUIの管理コンソールなど入れていくつもりです。
OSのセキュリティ周りも整備しなくては…。

GW振り返り

GWが終わってはや一週間以上たちましたが、反省を込めて振り返ります。

完了タスク

  • 本を1〜2冊完読する

    • クリア
  • Flaskの勉強

    • NG
  • Ubuntuを18.04にアップデート

    • NG
  • windows機を直す

    • クリア
  • ソファを買う

    • クリア
  • バイクに乗る

    • NG

総括

半分しかクリアできませんでした。
時間がたくさんあると思いだらけてしまったのが原因だと思います。
また、雑用が意外と時間かかってしまった。
ご飯作ったりとか家事系ですね。
あとお酒をたくさん飲んでしまいました。
禁酒とまではいかないけど飲まない日を増やさなくては。

詳細

  • 本を1〜2冊完読する
    • 復習がてら先月買ったネットワーク機器入門を読みました。
      各機器や歴史等結構細かく書いてあって面白かったです。 スイッチ、ルータは機能が多すぎるので、こういう本で整理できるのはいいですね。
      あとGWから足が出ちゃったけどハッカーと画家も読みました。
      よく見る Web屋さんの「素早い開発」みたいな事例があって面白かったです。
      私はSIer勤めなのであまりできませんが、とにかく動くものを作るという考え方は素敵だと思います。 (綿密な設計も大事ですが)

gihyo.jp

books.rakuten.co.jp

  • Flaskの勉強

    • 全くの未着手
  • Ubuntuを18.04にアップデート

    • まずはOSのバックアップをとらなくてはと思い、バックアップソフトをいくつか試しました。
      SystembackとTimeShiftを入れました。
      Systembackは何故か途中で止まってしまったので、TimeShiftを使ってバックアップは完了です。
      でもリストアの試験がまだできていないので、完了してからやります。
  • windows機を直す

    • グラフィックボードを抜き差ししたら一旦落ちるのはなくなりましたが、2,3日したらまた突然落ちるようになりました。
      原因はわからないのですが、電源オプションで高パフォーマンス設定にしたら落ち着くようになりました。
      給電が足りなかったのかな?
  • ソファを買う

    • 近所のニトリで注文してきました。(3人がけ!)
      在庫がないのか忘れましたがちょっと遅くて27日に届きます。楽しみ。
  • バイクに乗る

    • 船橋の2輪館まで行ってジャンプスターター探しましたが売ってませんでした。
      あちこち探しまわるのも何なのでおとなしくアマゾンで買いたいと思います。それとも業者読んだほうがいいかな。
      釣りに行きたい。

今年はこんな感じでした。
長期の休みはやりたいことが多すぎてうまく進めていくのが難しいです。

GWやること

今年もGWが開幕しました。

私はカレンダー通りなのですが、2回連休があるのでやりたいことメモっておきます。
今日はいつもの溜まった家事やって終わりそうです。

技術関係

  • 本を1〜2冊完読する

    • 面白そうな本をいろいろ買ってたら積み本が多くなってしまったので少しでも消化します。
      PDFとかもどんどん増えていくので大変。
  • Flaskの勉強

  • Ubuntuを18.04にアップデート

    • 今週だったかな?18.04がリリースされたそうなので今のUbuntu(このPC 16.04)からアップデートしたいと思います。
      なくなって困るデータはないですが、一応バックアップとか、VMで検証してから。

生活関係

  • windows機を直す

    • 年明けに壊れたWindows機を買い直したんですが何故か突然リブートする。
      HDDもメモリチェックもエラーがなかったんですが、グラボとの相性が悪いのかな?
      とりあえずGTAをやりたいので直します。
  • ソファを買う

    • 去年ソファが欲しくて広い家に引っ越しましたが未だ買ってない。この連休がチャンス。
      でもPCデスクも欲しいな。
  • バイクに乗る

    • これも昨年末に修理したのですが、冬は寒くて乗らなかったのでバッテリーあがっちゃってると思います。
      ジャンプスターター買えば動くかな。
      昔引きこもらない様にバイク買ってみたんですが、意外と行きたいとこって無いですねー
      でも直ったらソロキャンとかしたいな。(ゆるキャンの影響じゃないよ)

意外とこんなもんですか。
書き起こす前はあれこれしようといろいろ思ってたですが…。

といっても多分全部やりきれないと思うので、さぼらない程度にのんびり行きたいと思います。

しかし書いとかないと毎年何やってたか覚えてないな。

pythonでクレジット支払い集計ツールを作りたい

いつの間にか4月ですね。

この時期はだんだん暑くなっていくのもあってあまり春らしさを意識せずに過ぎていってしまいます。


私はお店の支払いはクレジットか電子マネーですることがほとんどなんですが、
何にいくら使ったのかの感覚が残りづらいため、出費を意識できるものが必要だと常々考えていました。
(家計簿とか書くのはめんどくさいので無し)

そこでpythonで簡単な集計ツール作れないかなーと思い、ちょっとやってみました。

私はクレジットの支払いはvisaでやっているのですが、
管理サイトから月次で支払いの詳細がダウンロードできるのでこれを加工したいと思います。

結論: pythonだけじゃ厳しかった

csvモジュールと演算でできるかもと思っていたのですが、うまいこと集計できませんでした。
支払いの明細と金額を辞書に入れてcountとかで集計できそうな感じでしたが、加算されずに金額のみアップデートされてしまってできませんでした。
ダウンロードしたファイルのフォーマットや私の技術不足もあると思います。

おとなしくデータベースを使います

python勉強中ですが、これだけにこだわる必要はないので、おとなしく便利なデータベースを使って集計します。
サクッと集計が今回の目標なのでDBのデーモンは使わず、sqliteでチャレンジします。

  • データベースはsqlite3を使う

メインマシンであるUbuntu 16.04LTS Desktopにはデフォルトでsqlite3がインストールされていました。
sqliteとの違いがいまいちわかりませんが、とりあえずこれでいいでしょう。

  • データベースを作ります

credit.dbという名前でデータベースファイルを作ります。
ちなみに環境はvenvで仮想環境作ってます。

(python3) masashi@PC-ubuntu:~/python3/work$ sqlite3 credit.db
SQLite version 3.11.0 2016-02-15 17:29:24
Enter ".help" for usage hints.

支払い一覧はcsvでダウンロードできます。
デフォルトの形式だといろいろ面倒なので、集計用に成形してます。
日付と明細と金額のみ記載しています。

sqlite> .mode csv
sqlite> 
sqlite> .import 201801_02.csv 201801
Error: near "201801": syntax error

あれ、インポートできない。
数字のみなのがダメなのかな。

sqlite> .import 201801_02.csv t_201801

頭にt_(tableの意)をつけたら行けました。

  • 確認

わー文字化けしてる。
ファイルを調べたら文字コードはCP932となっている様です。

sqlite> select * from t_201801;
2017/11/30,"���t�[�W���p��",498
2017/12/01,"�i�F�b�n�l�@�Q�T�|�r�X�p�b�N���p��",5431
2017/12/03,"�i�b�v�X�@���t�k�C���^�[�X",10022
2017/12/03,"�C�I�����e�[��",3419

カラムで絞れるか確認。

sqlite> select name from t_201801;
Error: no such column: name
sqlite> 

このままじゃ絞れませんでした。
文字化けしてるからダメなのかな。

インポート時に変換できないか調べましたが、すぐ出てこなそうなのでGUIで修正して保存しなおし。
テーブルを削除して、再インポートします。

sqlite> drop table t_201801;
sqlite> 
sqlite> .import 201801_02.csv t_201801
201801_02.csv:37: expected 3 columns but found 1 - filling the rest with NULL
sqlite> 
sqlite> select * from t_201801;
date,name,cost #これがヘッダ
2017/11/30,"インターネットイニシアティブ",1796
2017/11/30,"ヤフージャパン",498

お、行けました!

37行目でエラーはいてますが、一旦勧めます。

sqlite> select name from t_201801;
name
"インターネットイニシアティブ"
"ヤフージャパン"

カラムで絞っても大丈夫そうですね。

pythonからつつけるようにする

都度sql叩いて集計してもいいですが、せっかくなのでpython経由で出力できるようにします。
とはいってもこっちもsql叩くだけなんだけど…

#!/usr/bin/env python3

import sqlite3

database = 'credit.db'

connection = sqlite3.connect(database)

cursor = connection.cursor()

for row in cursor.execute('select name, sum(cost) from t_201801 group by name'):
    print(row[0], row[1])

とりあえず簡単なコードです。

sqliteにアクセスしてname(明細)毎に金額を集計するだけです、

(python3) masashi@PC-ubuntu:~/python3/work$ python credit.py 
None None
イオンリテール xxxx
イトーヨーカ堂 (サインレス) xxxx
インターネットイニシアティブ xxxx
サンフエイス xxxx
スウイ―ト カヴアカヴア xxxx
スマートEX(JR東海) xxxx
ツクモパソコン本店 xxxx
ツダヌマ パルコ xxxx
ナップス 千葉北インター店 xxxx
ヤフージャパン xxxx
千石電商 秋葉原本店 1F xxxx
11月分 au電話利用料 xxxx
Bar Vie Lembranca xxxx
J:COM 2サ-ビスパック利用料 xxxx
JR東日本モバイルSuica xxxx
JR西日本 xxxx
NETFLIX.COM xxxx

できました〜!
1月支払い分の明細の集計ができましたよ。
恥ずかしいので金額は隠します。

基本機能はできましたね。

もう少し改良して使い勝手を良くしていきたいと思います。

やりたいことメモ

  • インポートするcsvファイル成形
    • 今回は手動で修正しましたが、自動でやらせたい
  • 固定費とそうでない出費を分ける
    • 文字列判定でできそう
  • Noneの行をスキップする判定を入れる
  • 出力結果のカラムを綺麗にする
  • 月ごとに出力できるようにする
    • これは引数でできそう

あと、これからインポートファイルを増やしていくにしたがってテーブルの設計も考えないとですね。
(追加か別テーブルか)

アルティメット ラズパイ ホームサーバを構築する 3 完結

続きです。
ラストまで

Step20: ownCloudユーザ作成

右上の項目からUsersを選択 f:id:paloma69:20180328230156p:plain

ユーザ+グループを作成します。(自分の名前と、グループはuserでいいか)

できました。 f:id:paloma69:20180328230214p:plain

クオータもかけられるようですね。
とりあえず自分しかユーザがいないのでそのままにしときます。

一回ログアウトして自分のユーザでログイン
f:id:paloma69:20180328230244p:plain

OK! f:id:paloma69:20180328230229p:plain

Step21: samba構築

webminからパッケージインストール f:id:paloma69:20180328230319p:plain

完了! f:id:paloma69:20180328230335p:plain

Step22: sambaの設定

デフォルトの共有ディレクトリを削除。 f:id:paloma69:20180328230405p:plain

新規作成します。 f:id:paloma69:20180328230433p:plain

作成された共有を書き込み可能にします。 f:id:paloma69:20180328230510p:plain

完了! f:id:paloma69:20180328230527p:plain

Step23: sambaユーザ作成

Unixユーザアカウント作成

pi@raspberryNAS:~ $ sudo adduser masashi

sambaユーザと紐付け?つけます

pi@raspberryNAS:~ $ sudo pdbedit -a -u masashi
new password:
retype new password:
Unix username:        masashi
NT username:          
Account Flags:        [U          ]
User SID:             S-1-5-21-711291776-4065903894-3847242296-1000
Primary Group SID:    S-1-5-21-711291776-4065903894-3847242296-513
Full Name:            masashi suzuki
Home Directory:       \\raspberrynas\masashi
HomeDir Drive:        
Logon Script:         
Profile Path:         \\raspberrynas\masashi\profile
Domain:               RASPBERRYNAS
Account desc:         
Workstations:         
Munged dial:          
Logon time:           0
Logoff time:          never
Kickoff time:         never
Password last set:    Sun, 25 Mar 2018 03:30:20 UTC
Password can change:  Sun, 25 Mar 2018 03:30:20 UTC
Password must change: never
Last bad password   : 0
Bad password count  : 0
Logon hours         : FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF

samba再起動。
画面ポチッと f:id:paloma69:20180328230652p:plain

Step24: 共有フォルダにアクセス

原文はwindowsからアクセスしていますが、手元にすぐ使えるマシンがないのでUbuntuからアクセスします。 f:id:paloma69:20180328230816p:plain

あれ、アクセスできない…

valid usersを足してみます

pi@raspberryNAS:~ $ sudo tail /etc/samba/smb.conf 
#======================= Share Definitions =======================





[owncloud]
    path = /media/serverhdd/cloud
    writeable = yes
    valid users = masashi

再起動

pi@raspberryNAS:~ $ sudo systemctl restart smbd

あれ…だめだ
f:id:paloma69:20180328231527p:plain

デバッグをON
(設定ファイルにlog level = 3を追加)

Permission deniedが

[2018/03/25 07:09:55.122580,  3] ../source3/smbd/service.c:102(set_current_service)
  chdir (/media/serverhdd/cloud) failed, reason: Permission denied

ディレクトリの権限を変えるか、ユーザの所属グループを変えるか…
ユーザの所属グループ変えたほうがいいかな。
ディレクトリはowncloudで使ってるし

pi@raspberryNAS:~ $ sudo usermod -G www-data masashi 
pi@raspberryNAS:~ $ groups masashi
masashi : masashi www-data

再度アクセス

できた!!! f:id:paloma69:20180328231241p:plain

これで自宅のマシンはowncloudの領域をマウントできます。

Step25: Transmissionインストール

Transmission is a torrent/download manager. だそうです。
torrentとか聞いたことあるけど使ったことないなあ。

コンソールからインストール

pi@raspberryNAS:~ $ sudo apt-get install transmission

こっちのパッケージのようです。

pi@raspberryNAS:~ $ sudo apt-get install transmission-daemon

インストール後はデーモンが動いているので止めます。
マウントしたままこれからの作業をするとファイルシステムを壊す恐れがあるらしい。

pi@raspberryNAS:~ $ sudo /etc/init.d/transmission-daemon stop
[ ok ] Stopping transmission-daemon (via systemctl): transmission-daemon.service.

設定ファイルでユーザとパスを設定。
中身は割愛。

pi@raspberryNAS:~ $ sudo vi /etc/transmission-daemon/settings.json 
pi@raspberryNAS:~ $ 
pi@raspberryNAS:~ $ 

サービス起動

pi@raspberryNAS:~ $ sudo /etc/init.d/transmission-daemon start
[ ok ] Starting transmission-daemon (via systemctl): transmission-daemon.service.

9091でアクセスします。
あれ? ホワイトリストがなんたらって出てる f:id:paloma69:20180328231751p:plain

設定ファイルのwhitelist-enableの行をfalseに変更。
パスワード入力して…

アクセスできた! (でも使い方わかんない) f:id:paloma69:20180328231821p:plain

Step26: The Principal (訳が出てこないのでそのまま)

外から接続出るようにするのがこのサイトのメインイベントだそうです。

no-ipとポートフォワードを使うようですね。
no-ipのアカウントを作ります。

この辺は割愛。

Step27: No-ipインストール

インストールディレクトリ移動

pi@raspberryNAS:~ $ cd /usr/local/src/
pi@raspberryNAS:/usr/local/src $ 
pi@raspberryNAS:/usr/local/src $ sudo wget http://www.no-ip.com/client/linux/noip-duc-linux.tar.gz

解凍。
細かいとこは伏せ時にします。

pi@raspberryNAS:/usr/local/src $ sudo tar xvf noip-duc-linux.tar.gz 

pi@raspberryNAS:/usr/local/src $ cd noip-2.1.9-1/
pi@raspberryNAS:/usr/local/src/noip-2.1.9-1 $ ls

pi@raspberryNAS:/usr/local/src/noip-2.1.9-1 $ sudo make
pi@raspberryNAS:/usr/local/src/noip-2.1.9-1 $ sudo make install
if [ ! -d /usr/local/bin ]; then mkdir -p /usr/local/bin;fi
if [ ! -d /usr/local/etc ]; then mkdir -p /usr/local/etc;fi
cp noip2 /usr/local/bin/noip2
/usr/local/bin/noip2 -C -c /tmp/no-ip2.conf

Auto configuration for Linux client of no-ip.com.

Please enter the login/email string for no-ip.com  xxxxxxxxxx@gmail.com
Please enter the password for user 'xxxxxxxxx@gmail.com'  ***********

Only one host [domeinxxxxxxxxxxxxxxx.xx.xx] is registered to this account.
It will be used.
Please enter an update interval:[30]  
Do you wish to run something at successful update?[N] (y/N)  N

New configuration file '/tmp/no-ip2.conf' created.

mv /tmp/no-ip2.conf /usr/local/etc/no-ip2.conf
pi@raspberryNAS:/usr/local/src/noip-2.1.9-1 $ 

インストールできました。

step28: ポートフォワーディング

今下記のパッケージが入ってるんでポートフォワーディングでアクセス先をわかりやすくしましょう、と書いてあります。

  • Webmin - Port 12321
  • Owncloud - Port 80 (also requires /cloud or whatever sub directory you chosen earlier i.e. username.no-ip.biz:80/owncloud)
  • Transmission - Port 9091
  • Shell - Port 12320

  • Webmin.domain.co.jp:1
  • ownCloud.domain.co.jp:2

的な

ここはあとでも良いので飛ばします。

Step29: 最後 バックアップ

最後にsystemバックアップを取得します。
sdカードを抜いてisoとして保存します。

masashi@PC-ubuntu: ~$ mkdir backup ; cd $_
masashi@PC-ubuntu: ~/backup$ sudo dd if=/dev/sdd of=raspberrynas.iso
31116288+0 レコード入力
31116288+0 レコード出力
15931539456 bytes (16 GB, 15 GiB) copied, 820.508 s, 19.4 MB/s

OSが壊れたらこれからリストアですね。
でもまるまるバックアップしたから16GBもある…
この辺サイズ調整とかできるんですかね?

masashi@PC-ubuntu: ~/backup$ ls -hl
合計 15G
-rw-r--r-- 1 root root 15G  326 13:26 raspberrynas.iso

Step 30: Congratulations - Felicitaciones - Glückwünsche - 恭喜

おめでとう! Linuxについてより詳しく学んでください。的なことが書いてあります。

あとがき

とりあえず完走できました!
デフォルトユーザのパスワード変更とか、ポートフォワーディングして外から突けることを確認とか、書き込みの確認とか、残タスクはまだありますが…

サイトには図解のようにやれってとこが多いんですが、図解が見れなくて困りました。
私の環境の気がしますが、サーバ側なのかブラウザとの相性なのかはわかりません。

実はこの作業は先週の週末に行って、時間は土日まるまる2日(雑用抜いて16時間ぐらい)使ってしまいました。
samba接続のデバッグに2時間ほど時間かかってしまいました。
やっぱりデバッグログは大事で、切り分け時は見ようとする心が大事ですね。

1万ちょっとでNAS作れたので、録画サーバのアニメをこちらに逃したいと思います。
でもRAID組んでるわけじゃないからHDDが壊れたら終わりですね。
まあ安価サーバなんで今はこれでいいか。

raspberry piの存在を知ってから実機を触ってみたいと思っていたので、やっと実現できて嬉しいです。
他にもraspberry piでやりたいことがあるので機会があれば新しいの買ってやりたいと思います。

  • retro piを入れてミニゲームサーバ
  • ラズパイオーディオサーバ

とかね。

とりあえず今回のアルティメットサーバ構築は終わりです。
構築も書くのも疲れました〜
キャプチャと作業ログから起こしましたが、抜けがあったら申し訳ないです…。

アルティメット ラズパイ ホームサーバを構築する 2

続き

パッケージをインストールしていきます。

Step7: Webminインストール

サイトではOSに初めから入っているようですが、ここでは新規インストールします

参考サイト Ubuntu 16.04 LTS : Webmin インストール : Server World

pi@raspberrypi:~ $ sudo apt-get -y install python apt-show-versions libapt-pkg-perl libauthen-pam-perl libio-pty-perl libnet-ssleay-perl 

pi@raspberrypi:~ $ curl -L -O http://www.webmin.com/download/deb/webmin-current.deb 
pi@raspberrypi:~ $ sudo dpkg -i webmin-current.deb

ポートもサイトと同じにします。
設定ファイルの中身は割愛。

pi@raspberrypi:~ $ sudo vi /etc/webmin/miniserv.conf 
pi@raspberrypi:~ $ sudo systemctl start webmin
pi@raspberrypi:~ $ 

あれ?10000であがってる…

pi@raspberrypi:~ $ 
pi@raspberrypi:~ $ ss -lnt
State      Recv-Q Send-Q                               Local Address:Port                                              Peer Address:Port              
LISTEN     0      128                                              *:10000                                                        *:*                  
LISTEN     0      128                                              *:22                                                           *:*                  
LISTEN     0      128                                             :::22                                                          :::*                  
pi@raspberrypi:~ $ 
pi@raspberrypi:~ $ sudo vi /etc/webmin/miniserv.conf 
pi@raspberrypi:~ $ 
pi@raspberrypi:~ $ curl -I localhost:10000
HTTP/1.0 200 Document follows
Server: MiniServ/1.881
Date: Sat, 24 Mar 2018 10:16:05 GMT
Content-type: text/html; Charset=iso-8859-1
Connection: close

pi@raspberrypi:~ $ curl -I localhost:12321
curl: (7) Failed to connect to localhost port 12321: Connection refused
pi@raspberrypi:~ $ 

再起動したら直りました。

pi@raspberrypi:~ $ ss -lnt
State      Recv-Q Send-Q                               Local Address:Port                                              Peer Address:Port              
LISTEN     0      128                                              *:22                                                           *:*                  
LISTEN     0      128                                              *:12321                                                        *:*                  
LISTEN     0      128                                             :::22                                                          :::*                  
pi@raspberrypi:~ $ 

ログインして言語を日本語にしました。
ユーザはshellと同じアカウントです。
ローカルIPが見えちゃってるがいいか。

f:id:paloma69:20180327210505p:plain

Step8: Shell in a Box インストール

  • メイン機からSSHするので使わないとは思いますが、倣ってインストールします。
  • リポジトリにあるようなのでapt-getでインストール
pi@raspberrypi:~ $ sudo apt-get install shellinabox
pi@raspberrypi:~ $ sudo cp -i /etc/default/shellinabox{,org}
pi@raspberrypi:~ $ 
pi@raspberrypi:~ $ sudo vi /etc/default/shellinabox 
pi@raspberrypi:~ $ 
pi@raspberrypi:~ $ 
pi@raspberrypi:~ $ sudo systemctl start shellinabox

pi@raspberrypi:~ $ ss -lnt
State      Recv-Q Send-Q                               Local Address:Port                                              Peer Address:Port              
LISTEN     0      128                                              *:4200                                                         *:*                  
LISTEN     0      128                                              *:22                                                           *:*                  
LISTEN     0      128                                              *:12321                                                        *:*                  
LISTEN     0      128                                             :::22                                                          :::*                  
pi@raspberrypi:~ $ 

こっちも再起動したらポート直りました。

pi@raspberrypi:~ $ sudo systemctl restart shellinabox
pi@raspberrypi:~ $ ss -lnt
State      Recv-Q Send-Q                               Local Address:Port                                              Peer Address:Port              
LISTEN     0      128                                              *:22                                                           *:*                  
LISTEN     0      128                                              *:12320                                                        *:*                  
LISTEN     0      128                                              *:12321                                                        *:*                  
LISTEN     0      128                                             :::22                                                          :::*                  
pi@raspberrypi:~ $ 

余り使いみちが浮かびませんが、ブラウザから出来ると何かと便利なのかな?

f:id:paloma69:20180327210545p:plain

Step9: 再起動

原文はHow To Rebootで再起動の仕方を覚えようという内容になっています。
今は再起動必要な対応もしていないのでスキップ。

Step10: サーバ名変更

ホスト名を変更します。

「raspberryNAS」とでもしますか。

サイトではnanoで変更していますが、私は使い慣れたviで変えます。

pi@raspberrypi:~ $ sudo vi /etc/hostname 
pi@raspberrypi:~ $ sudo cat /etc/hostname 
raspberryNAS

適用のため再起動します。(さっきのはここで使うのか)

20秒程度で復帰しました。早い!

Step11: HDDマウント

他で使っていたドライブを使用する場合の注意書きのようです。

NFTSのフォーマットはお作法があるようですね。

ディスク周りの操作ってあまりやったことない...
今回は新しいHDDなので気にしなくていいかな。

Step12: HDDマウント続き

装着!(しまった。床が汚い…) f:id:paloma69:20180327210036j:plain

マウントします。 webminではエラー吐いたのでコマンドでやっています。

f:id:paloma69:20180327211954p:plain

f:id:paloma69:20180327212021p:plain

ファイルシステムが悪いって言ってる?

コマンドで確認。
認識してます。

pi@raspberryNAS:~ $ dmesg | tail
[ 1061.782758] usb-storage 1-1.5:1.0: Quirks match for vid 152d pid 2329: 8020
[ 1061.782846] scsi host0: usb-storage 1-1.5:1.0
[ 1065.146056] scsi 0:0:0:0: Direct-Access     HGST HTS 721010A9E630     JB0O PQ: 0 ANSI: 2 CCS
[ 1065.148157] sd 0:0:0:0: [sda] 1953525168 512-byte logical blocks: (1.00 TB/932 GiB)
[ 1065.148718] sd 0:0:0:0: [sda] Write Protect is off
[ 1065.148733] sd 0:0:0:0: [sda] Mode Sense: 28 00 00 00
[ 1065.149248] sd 0:0:0:0: [sda] No Caching mode page found
[ 1065.149258] sd 0:0:0:0: [sda] Assuming drive cache: write through
[ 1065.169301] sd 0:0:0:0: Attached scsi generic sg0 type 0
[ 1065.820741] sd 0:0:0:0: [sda] Attached SCSI disk
pi@raspberryNAS:~ $ 

/media/serverhddを作成してここにマウントします。

pi@raspberryNAS:~ $ sudo mkdir /media/serverhdd

ファイルシステムを指定。
ファイルシステムはよくわからんのでext4でいいか。
パーティションは切らずにまるまる使います。

pi@raspberryNAS:~ $ sudo mkfs -t ext4 /dev/sda 
mke2fs 1.43.4 (31-Jan-2017)
Creating filesystem with 244190646 4k blocks and 61054976 inodes
Filesystem UUID: e4060527-833c-4e1d-848b-d3861ca4f34b
Superblock backups stored on blocks: 
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
    4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 
    102400000, 214990848

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (262144 blocks): 
done
Writing superblocks and filesystem accounting information: done     

マウントされました!

pi@raspberryNAS:~ $ df -T
Filesystem     Type     1K-blocks    Used Available Use% Mounted on
/dev/root      ext4      15240524 1252796  13336132   9% /
devtmpfs       devtmpfs    470180       0    470180   0% /dev
tmpfs          tmpfs       474788       0    474788   0% /dev/shm
tmpfs          tmpfs       474788    6332    468456   2% /run
tmpfs          tmpfs         5120       4      5116   1% /run/lock
tmpfs          tmpfs       474788       0    474788   0% /sys/fs/cgroup
/dev/mmcblk0p1 vfat         42131   21470     20661  51% /boot
tmpfs          tmpfs        94956       0     94956   0% /run/user/1000
/dev/sda       ext4     960381672   77852 911449308   1% /media/serverhdd

Step13: MySQLインストール

これもWebminから

パッケージがないのでインストール f:id:paloma69:20180327212133p:plain

なんか始まった f:id:paloma69:20180327212146p:plain

インストール完了!
管理画面がでました f:id:paloma69:20180327212202p:plain

Step14: MySQLにデータベース追加(owncloud)

新規データベースを作成を選択
名前以外デフォルトで作成 f:id:paloma69:20180327212337p:plain

owncloudデータベースができました。 f:id:paloma69:20180327212359p:plain

Step15: MySQLにユーザ追加

新規ユーザ作成選択

ユーザ名をowncloudで、
権限はスーパーユーザ以外を選択。
MAX Connectionを15に設定して作成 f:id:paloma69:20180327212457p:plain

できました。 f:id:paloma69:20180327212524p:plain

Step16: PHPインストール

これはコマンドで

サイトではshellinaboxからですが、こちらはsshターミナルからやります。

apt-get install php5 php-pear php5-mysql

5系か…まあいいか

入らない

pi@raspberryNAS:~ $sudo apt-get install php5 php-pear php5-mysql

Reading package lists... 0%

Reading package lists... 100%

Reading package lists... Done


Building dependency tree... 0%

Building dependency tree... 0%

Building dependency tree... 50%

Building dependency tree... 50%

Building dependency tree       


Reading state information... 0%

Reading state information... 0%

Reading state information... Done

Package php5 is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'php5' has no installation candidate

調べてみるとDebian Stretchからphp5は廃止された模様。
どうするか。

とりあえずフォーラムを頼りにやってみる
https://www.raspberrypi.org/forums/viewtopic.php?t=195818

リポジトリ追加

pi@raspberryNAS:~ $ sudo vi /etc/apt/sources.list

deb http://mirrordirector.raspbian.org/raspbian/ jessie main contrib non-free rpi

pi@raspberryNAS:~ $ sudo apt-get install php5 php-pear php5-mysql
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package php5 is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

Package php5-mysql is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'php5' has no installation candidate
E: Package 'php5-mysql' has no installation candidate
pi@raspberryNAS:~ $ 
pi@raspberryNAS:~ $ update-alternatives --set php /usr/bin/php5
update-alternatives: error: no alternatives for php
pi@raspberryNAS:~ $ 
pi@raspberryNAS:~ $ sudo apt-get install php5 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package php5 is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'php5' has no installation candidate
pi@raspberryNAS:~ $ sudo vi /etc/apt/sources.list
pi@raspberryNAS:~ $ 
pi@raspberryNAS:~ $ sudo apt-get install php5 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package php5 is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'php5' has no installation candidate
pi@raspberryNAS:~ $ 

update-alternativesがなんかエラー吐いてるし、入らない…
切り分けしてる時間ももったいないので、php7ですすめます。

pi@raspberryNAS:~ $ sudo apt-get install php php-pear php-mysql

pi@raspberryNAS:~ $ php --version
PHP 7.0.27-0+deb9u1 (cli) (built: Jan  5 2018 13:51:52) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.0.27-0+deb9u1, Copyright (c) 1999-2017, by Zend Technologies
pi@raspberryNAS:~ $ 

OK!

Step17: ownCloudインストール

これもwebminから。
aptからowncloudを選択してインストール f:id:paloma69:20180327213841p:plain

php5関係のエラーが出て失敗したのでowncloudの最新版をインストールします。 f:id:paloma69:20180327213907p:plain

参考サイト
Raspberry Pi 3 に ownCloud X をインストール | スモールサーバ開発部

pi@raspberryNAS:~ $ wget https://download.owncloud.org/community/owncloud-10.0.7.tar.bz2

pi@raspberryNAS:~ $ ls -l owncloud-10.0.7.tar.bz2 
-rw-r--r-- 1 pi pi 39395237 Feb 19 16:41 owncloud-10.0.7.tar.bz2

解凍

pi@raspberryNAS:~ $ tar xvf owncloud-10.0.7.tar.bz2 

pi@raspberryNAS:~ $ ls -ld owncloud
drwxr-xr-x 12 pi pi 4096 Mar 24 12:33 owncloud

展開されました。

Step18: ownCloudプレインストール

手順に沿ってディレクトリ作成

pi@raspberryNAS:~ $ cd /media/serverhdd/
pi@raspberryNAS:/media/serverhdd $ 
pi@raspberryNAS:/media/serverhdd $ sudo mkdir cloud
pi@raspberryNAS:/media/serverhdd $ sudo chmod 750 /media/serverhdd/cloud
pi@raspberryNAS:/media/serverhdd $ ls -ld cloud/
drwxr-x--- 2 root root 4096 Mar 24 12:37 cloud/

Step19: ownCloud設定

手順上ではこの時点でownCloudにアクセスできるみたいですが、私は途中で手順を変えたので軌道修正します。
ownCloudにアクセスできるようにします。

ディレクトリ移動&設定ファイル作成

pi@raspberryNAS:~ $ sudo mv owncloud /var/www/
pi@raspberryNAS:~ $ sudo chown -R www-data:www-data /var/www/owncloud
pi@raspberryNAS:~ $ sudo vi /etc/apache2/conf-available/owncloud.conf 

反映

pi@raspberryNAS:~ $ sudo a2enconf owncloud 
Enabling conf owncloud.
To activate the new configuration, you need to run:
  systemctl reload apache2

apache再起動

pi@raspberryNAS:~ $ sudo systemctl reload apache2 

キターーー!!!
けどエラーがいっぱい... f:id:paloma69:20180327214450p:plain

  • PHP module zip not installed.
  • PHP module intl not installed.
  • PHP module mb multibyte not installed.
  • PHP module GD not installed.
  • PHP module cURL not installed.
  • PHP modules have been installed, but they are still listed as missing?

モジュールがいろいろ足りないようなので入れていきます。

一応searchで確認
(1個ずつしましたがまとめて確認できるのかな?後で調べよう)

pi@raspberryNAS:~ $ sudo apt search php-zip
Sorting... Done
Full Text Search... Done
php-zip/stable 1:7.0+49 all
  Zip module for PHP [default]

php-zipstreamer/stable 1.0-1 all
  Stream zip files without i/o overhead

pi@raspberryNAS:~ $ sudo apt search php-intl
Sorting... Done
Full Text Search... Done
php-intl/stable 1:7.0+49 all
  Internationalisation module for PHP [default]

pi@raspberryNAS:~ $ sudo apt search php-mb
Sorting... Done
Full Text Search... Done
php-mbstring/stable 1:7.0+49 all
  MBSTRING module for PHP [default]

pi@raspberryNAS:~ $ sudo apt search php-gd
Sorting... Done
Full Text Search... Done
php-gd/stable 1:7.0+49 all
  GD module for PHP [default]

pi@raspberryNAS:~ $ sudo apt search php-curl
Sorting... Done
Full Text Search... Done
php-curl/stable 1:7.0+49 all
  CURL module for PHP [default]

インストール

pi@raspberryNAS:~ $ sudo apt-get install php-zip php-intl php-mbstring php-gd php-curl 

インストール終わったらapache再起動

キタ━━━━(゚∀゚)━━━━!! f:id:paloma69:20180327214724p:plain

アカウントを設定

  • 管理者
  • データ格納パス
  • データベース

Finish! f:id:paloma69:20180327214829p:plain

画面が変わりました。

パスワード入れて… f:id:paloma69:20180327214901p:plain

ログインできたよーーー! f:id:paloma69:20180327214932p:plain

長くなってしまったので今日はここまでにします。

次はアカウントやファイル共有の設定をやっていきます!

続く