MariaDB 起動/停止

起動/停止(RedHat, Ubuntu : Systemd)

・ユニットファイル記述

ユーザー設定(優先される)

[root]# vim /etc/systemd/system/mariadb.service

[Unit]
Description = MariaDB - Database Server
After = network.target

[Service]
Environment=SYSTEMD_LOG_LEVEL=debug,console:info
ExecStart = /usr/local/mysql/bin/mariadbd --defaults-file=/etc/my.cnf
ExecStop = /bin/kill -SIGTERM $MAINPID
KillMode = control-group
ExecReload = /bin/kill -SIGHUP $MAINPID
Restart = on-failure
RestartSec = 10s

SystemCallArchitectures = native
SystemCallFilter=~@clock
SystemCallFilter=~@cpu-emulation
SystemCallFilter=~@debug
SystemCallFilter=~@module
SystemCallFilter=~@mount
SystemCallFilter=~@obsolete
SystemCallFilter=~@privileged
SystemCallFilter=~@raw-io
SystemCallFilter=~@reboot
SystemCallFilter=~@resources
SystemCallFilter=~@swap

RestrictRealtime = yes

RemoveIPC = yes
PrivateIPC = yes

CapabilityBoundingSet =

RestrictAddressFamilies =~ AF_PACKET AF_NETLINK

User = mysql
Group = mysql
PermissionsStartOnly = yes
UMask = 0077

#× ProtectSystem = strict
ProtectSystem = full
ProtectHome = yes
#× PrivateTmp = yes
ReadWritePaths = /usr/local/mysql
PrivateUsers = yes

PrivateDevices = yes
ProtectClock = yes
ProtectKernelLogs = yes
ProtectKernelModules = yes
ProtectKernelTunables = yes
ProtectControlGroups = yes

#× PrivateNetwork = yes
NoNewPrivileges = yes
IPAddressAllow = localhost
IPAddressAllow = 192.168.1.0/24
IPAddressDeny = any
MemoryDenyWriteExecute = yes
ProcSubset = pid

RestrictNamespaces = yes
RestrictSUIDSGID = yes
ProtectHostname = yes
LockPersonality = yes
ProtectProc = invisible

[Install]
WantedBy = multi-user.target
・ユニットファイル登録/変更時

[root]# systemctl daemon-reload

・systemd によるセキュリティスコア
    [root]# systemd-analyze security mariadb.service

    → Overall exposure level for mariadb.service: 1.4 OK
・起動/停止

[root]# systemctl { start stop reload-or-restart } mariadb.service

・自動起動/停止

[root]# systemctl { enable disable } mariadb.service

・起動/自動起動を同時に行う

[root]# systemctl enable --now mariadb.service

・停止/自動停止を同時に行う

[root]# systemctl disable --now mariadb.service

データベースへアクセス

[user]$ mariadb -u ユーザー名 -p データベース名