投稿者「mars」のアーカイブ

wordpress/mariadbが起動しないので対処した

DataBase(Mariadb)に接続できない
root@ps2:/var/lib/mysql# systemctl status mariadb
● mariadb.service - MariaDB 10.3.34 database server
   Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Fri 2022-04-01 11:02:34 JST; 10min ago
     Docs: man:mysqld(8)
           https://mariadb.com/kb/en/library/systemd/
  Process: 575 ExecStartPre=/usr/bin/install -m 755 -o mysql -g root -d /var/run/mysqld (code=exited, status=0/SUCCESS)
  Process: 600 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
  Process: 667 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= ||   VAR=`cd /usr/bin/..; /usr/bin/galera_recovery`; [ $? -eq 0 ]   && systemctl s
  Process: 823 ExecStart=/usr/sbin/mysqld $MYSQLD_OPTS $_WSREP_NEW_CLUSTER $_WSREP_START_POSITION (code=exited, status=1/FAILURE)
 Main PID: 823 (code=exited, status=1/FAILURE)
   Status: "MariaDB server is down"

 4月 01 11:02:28 ps2 systemd[1]: Starting MariaDB 10.3.34 database server...
 4月 01 11:02:31 ps2 mysqld[823]: 2022-04-01 11:02:31 0 [Note] /usr/sbin/mysqld (mysqld 10.3.34-MariaDB-0+deb10u1) starting as process 823 ...
 4月 01 11:02:34 ps2 systemd[1]: mariadb.service: Main process exited, code=exited, status=1/FAILURE
 4月 01 11:02:34 ps2 systemd[1]: mariadb.service: Failed with result 'exit-code'.
 4月 01 11:02:34 ps2 systemd[1]: Failed to start MariaDB 10.3.34 database server.

ログファイの肥大化などが原因になることもあるようだ。

oot@ps2:/var/log/mysql# find / -name "ib_logfile*" 2>/dev/null
/var/lib/mysql/ib_logfile0
/var/lib/mysql/ib_logfile1
^C
root@ps2:/var/log/mysql# cd /var/lib/mysql/
root@ps2:/var/lib/mysql# ls -l
合計 176180
-rw-rw---- 1 mysql mysql    16384  4月  1 11:02 aria_log.00000001
-rw-rw---- 1 mysql mysql       52  4月  1 11:02 aria_log_control
-rw-r--r-- 1 root  root         0  3月 31 19:09 debian-10.3.flag
-rw-rw---- 1 mysql mysql     6174  3月 31 19:17 ib_buffer_pool
-rw-rw---- 1 mysql mysql 50331648  3月 31 19:17 ib_logfile0
-rw-rw---- 1 mysql mysql 50331648  3月 31 19:10 ib_logfile1
-rw-rw---- 1 mysql mysql 79691776  3月 31 19:17 ibdata1

ib_logfile* を削除してみる。

root@ps2:/var/lib/mysql# rm -rvf ib_logfile*
'ib_logfile0' を削除しました
'ib_logfile1' を削除しました

mariadbを再起動したら、OKとなった!

root@ps2:/var/lib/mysql# systemctl restart  mariadb
root@ps2:/var/lib/mysql# systemctl status  mariadb
● mariadb.service - MariaDB 10.3.34 database server
   Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2022-04-01 11:12:50 JST; 30s ago
     Docs: man:mysqld(8)
           https://mariadb.com/kb/en/library/systemd/
  Process: 4321 ExecStartPre=/usr/bin/install -m 755 -o mysql -g root -d /var/run/mysqld (code=exited, status=0/SUCCESS)
  Process: 4322 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
  Process: 4324 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= ||   VAR=`cd /usr/bin/..; /usr/bin/galera_recovery`; [ $? -eq 0 ]   && systemctl
  Process: 4404 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
  Process: 4407 ExecStartPost=/etc/mysql/debian-start (code=exited, status=0/SUCCESS)
 Main PID: 4372 (mysqld)
   Status: "Taking your SQL requests now..."
    Tasks: 31 (limit: 4915)
   CGroup: /system.slice/mariadb.service
           mq4372 /usr/sbin/mysqld

WordPressのバックアップ

プラグイン「All-in-One WP Migration」を利用してwordpressのバックアップを試してみました。エクスポートのメニューからバックアップされたのファイルのサイズは、400MB強でした(PCへダウンロード)。

手順:

  • バックアップしたファイルのリストアーを試すために、別のSDカードへ新規にWordpressをインストール。
  • バックアップファイルは大容量となるので、php.iniを修正してアップロードの上限を拡大
  • 新規にインストールしたWordpressへ「All-in-One WP Migration」プラグインだけをインストール。(コンテンツなし。テーマやほかのプラグインの追加・設定なし)
  • Backup元で「All-in-One WP Migration」プラグインを利用してバックアップ(エクスポート)
  • BackUp先で、「All-in-One WP Migration」プラグインを利用してバックアップしたファイルをインポート。

SplunkでWindos Defenderのログを解析

SplunkでWindowsのイベントログを閲覧できるまで設定が終わっていることを前提;

SplunkのAPP 「TA for Microsoft Windows Defender」をSplunkへ導入し、Windows側のUniversalForwarderのinputs.confに次を追加する。

[WinEventLog://Microsoft-Windows-Windows Defender/Operational]
disabled = false
blacklist = 1001, 1150, 2011, 2000, 2001, 2002, 2010

UniversalForwarderを再起動すると、Splunkのサーチでソースタイプとして”WinEventLog:Microsoft-Windows-Windows Defender/Operational”が見えるようになる。

Raspberry PiへUniversalForwarderをインストール

インストールの手順: https://www.splunk.com/ja_jp/blog/tips-and-tricks/how-to-install-universal-forwarder-01.html

DownloadのLINK: https://www.splunk.com/en_us/download/universal-forwarder.html

インデックスサーバへ転送するための設定:

indexerの設定(PORT 8089)

/opt/splunkforwarder/bin/splunk add forward-server <INDEXER_IP>:<INDEXER_PORT>

モニター対象のファイル設定

How to install Splunk Forwarder on Ubuntu

例:$sudo splunk add monitor /var/log/apache2/access.log

モニター用のコマンド
[sudo] $SPLUNK_HOME/bin/splunk add monitor <取り込みファイルorディレクトリパス> [-パラメータ 値]

OSの起動時にsplunkを起動する設定

/opt/splunkforwarder/bin/splunk enable boot-start

FAT32のUSBをUbuntuへマウントしてoutlookのメール(*msg)を解析する

必要なツールをインストール
$ sudo apt install mpack
$ sudo apt install libemail-outlook-message-perl libemail-sender-perl

/dev/sdb1 がFAT32のUSBで、/mnt/tmpへマウント
mount -t vfat -o defaults,utf8 /dev/sdb1 /mnt/tmp

msgファイルをemlへ変換
$ msgconvert *.msg

*emlファイルが生成されるので、emlファイルを解析
$ munpack *eml

raspberry piでマルチブートを試してみる

raspberryPiで利用できるマルチブートの環境として、PINN(PINN IsNotNoobs)Berrybootなどが知られている。

PINNでカスタムOSを利用する手順のリンク

結構煩雑な手順を踏む必要がある。

https://github.com/procount/pinn/wiki/How-to-Create-a-Multi-Boot-SD-card-out-of-2-existing-OSes-using-PINN

PINN用のカスタムOS設定に必要なファイル

https://sourceforge.net/projects/pinn/files/

BerryBoot用に設定されたOSイメージのダウンロードリンク

https://sourceforge.net/projects/berryboot/files/

PINNよりも公開されているカスタムOSの種類が多く、さらに導入手順も比較的容易。実際に試してみたところ、swapをONにする設定ができない模様。

その後の調査でBerryBootのファイルシステムはoverlayとなっていてることがswapを設定できない原因らしい。最近のRaspberry OSでは、swapの設定を/sbin/dphys-swapfileのスクリプトで実行しているが、こんな記事を発見。
[Solved] With overlay of root, swap does not work

解決方法として:

〇dphys-swapfileを利用しない。

〇swapとしてファイルではなく、(overlayとは別の?)デバイスを指定する必要があると理解。

次のように、SSDのパーティションにswap用に4GBを割り当ててみました。

evice     Boot    Start       End   Sectors   Size Id Type
/dev/sda1           2048    262143    260096   127M  e W95 FAT16 (LBA)
/dev/sda2       47955968 468860927 420904960 200.7G 83 Linux
/dev/sda3       39567360  47955967   8388608     4G 82 Linux swap / Solaris

swapファイルの指定は、昔ながらの(?)/etc/fstabに記述します。

/dev/sda3       swap swap defaults 0 0

その結果、4GBのswap領域を確保することができた。

$ free
              total        used        free      shared  buff/cache   available
Mem:        3798908      307284      579676       47612     2911948     3366744
Swap:       4194300           0     4194300

BerryBootでインストールした複数のOS毎に、以上のようにswap設定を変更することで、目的を達成!

ASI ZWOカメラをpythonで利用する

最初にASI_linux_mac_SDK_V1.21をインストール

ダウンロードのリンク 

Software and Drivers

ダウンロードして展開すると;

$ls ASI_linux_mac_SDK_V1.21
demo  doc  include  lib  license.txt
$ls ASI_linux_mac_SDK_V1.21/demo
Makefile  bin  main_SDK2_snap.cpp  main_SDK2_video.cpp  main_SDK2_video_mac  main_SDK2_video_mac.cpp  readme.txt

$cat readme.txt
Please install opencv2 at first, for example under Linux x86 OS, run:
make platform=x86
Below options is supported:
x86(Linux 32-bit)
x64(Linux 64-bit)
armv5
armv6
armv7
armv8
mac32
mac64
mac(32-bit and 64-bit)

If libASICamera2.so or (.dylib) can't be found at run time, resolve by delow two ways:
1.Add a .conf file that contains the path of the library to /etc/ld.so.conf.d/, run ldconfig.
2.Add compile option -Wl,-rpath=<library path>

raspberry pi4 64bit OSの場合 armv8

makeに先立って、demo/binの下へarmv8フォルダーを作る。

/usr/includeの下に、opencv2のファイル一式が必要。

root権限なしでカメラをアクセスできるようにするためのルールを追加

設定ファイル ASI_linux_mac_SDK_V1.21lib/asi.rulesをlib/udev/rules.d または/etc/udev/rules.dへCopyして、カメラを抜き差し。

$cd demo
$mkdir demo/bin/armv8
$make platform=armv8

$ ls demo/bin/armv8/
libASICamera2.so  main_SDK2_video_mac  test_gui2_snap  test_gui2_video

libASICamera2.so を参照できるよう、適切なフォルダーへ配置しldconfig

(あまり良い方法ではないが、/lib の下へlibASICamera2.soをCopy)

Pythonから利用できるようにライブラーをインストール

https://github.com/python-zwoasi/python-zwoasi

#!/usr/bin/env python

import argparse
import os
import sys
import time
import zwoasi as asi

env_filename = os.getenv('ZWO_ASI_LIB')

ZWO_ASI_LIBには、次のパスを設定

$ echo $ZWO_ASI_LIB
/home/pi/python-zwoasi/build/lib/zwoasi

$ ls /home/pi/python-zwoasi/build/lib/zwoasi

__init__.py の内容

"""Interface to ZWO ASI range of USB cameras.

Calls to the `zwoasi` module may raise :class:`TypeError` or :class:`ValueError` exceptions if an input argument
is incorrect. Failure conditions from within the module may raise exceptions of type :class:`ZWO_Error`. Errors from
conditions specifically from the SDK C library are indicated by errors of type :class:`ZWO_IOError`; certain
:func:`Camera.capture()` errors are signalled by :class:`ZWO_CaptureError`."""

import ctypes as c
from ctypes.util import find_library
import logging
import numpy as np
import os
import six
import sys
import time
import traceback


__author__ = 'Steve Marple'
__version__ = '0.1.0.1'
__license__ = 'MIT'


def get_num_cameras():
    """Retrieves the number of ZWO ASI cameras that are connected. Type :class:`int`."""
    return zwolib.ASIGetNumOfConnectedCameras()

Seleniumでスクレイピングの準備

$sudo apt-get update
$sudo apt install chromium-chromedriver
$sddo cp /usr/lib/chromium-browser/chromedriver /usr/bin
$pip install selenium
$pip install webdriver_manager

紛らわしい点:webdriver_managerとwebdrivermanagerの両方が存在し、機能が同じではない。webdriver_managerの方が良さそう。

Webサイトのタイトルを取得してみる。

from selenium import webdriver
import time

#---------------------------------------------------------------------------------------
# 処理開始
#---------------------------------------------------------------------------------------
# ブラウザをheadlessモード実行
print("\nブラウザを設定")
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome('chromedriver',options=options)
driver.implicitly_wait(10)

# サイトにアクセス
print("サイトにアクセス開始")
URL="https://rfsec.ddns.net/db/"
driver.get(URL)
time.sleep(3)
# driver.find_elements_by_css_selector("xxx") 的な処理を自由に
print("サイトのタイトル:", driver.title)

認証があるサイトの場合(中華製ネットワークカメラ)

import time
import base64
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager

def get_auth_header(user, password):
    b64 = "Basic " + base64.b64encode('{}:{}'.format(user, password).encode('utf-8')).decode('utf-8')
    return {"Authorization": b64}

# Webdriver ManagerでChromeDriverを取得
driver = webdriver.Chrome(executable_path=ChromeDriverManager().install())

# Authorizationヘッダを付与
driver.execute_cdp_cmd("Network.enable", {})
driver.execute_cdp_cmd("Network.setExtraHTTPHeaders", {"headers": get_auth_header("admin", "")})
# Basic認証が必要なページにアクセス
driver.get('http://192.168.68.128')
time.sleep(5)

driver.close()
driver.quit()

数独の問題サイトから問題を取得して、解く。

#  ここからがseleniumのコード
#  問題サイト http://numberplace.net/
#
from selenium import webdriver
import time
import numpy as np

def disp(results):
    msg=""
    for r in results:
        for y in range(9):
            for x in range(9):
                c = r._values[y][x]
                c = str(c)
                d = row2[y][x]
                if d != 0:
                    msg=msg+'('+ c + ') '
                else:
                    msg=msg+'-'+ c + '- ' 
            msg=msg+"\n"
    print(msg)

#---------------------------------------------------------------------------------------
# 処理開始
#---------------------------------------------------------------------------------------
# ブラウザをheadlessモード実行
print("\nブラウザを設定")
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome('chromedriver',options=options)
driver.implicitly_wait(2)

# サイトにアクセス
for num in range(5):
    URL="http://numberplace.net/?no="+str(num+1)
    print("サイトにアクセス開始:",URL)
    driver.get(URL)
    time.sleep(2)
    lines= driver.page_source.splitlines()
    for line in lines:
        if 'toi' in line:
            q = line.split(' ')[3].replace("'","").replace(";","")
            q=list(q)
            #print(q)
            qi = [int(s) for s in q]
            #print(qi)
            q2 = np.array(qi)
            row2=np.array(q2).reshape(-1,9).tolist()
            grid = solver.Grid(row2)
            print(grid)
            results = solver.solve_all(grid)
            disp(results)
            break
print('Done.')