[root]# cp -v /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d/mysqld
・パーミッション変更[root]# chmod 755 /etc/rc.d/init.d/mysqld
・起動/停止[root]# service mysqld { start stop restart reload force-reload status configtest }
・自動起動/停止[root]# chkconfig --add mysqld
[root]# chkconfig mysqld { on off }
Sysvinit の init プロセス用リンクを作成、削除。サービスをソースインストールした場合、設定が必要。
・起動スクリプトコピー[root]# cp -v /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld
・パーミッション変更[root]# chmod 755 /etc/init.d/mysqld
・リンクを作成 / 削除[root]# update-rc.d mysqld defaults / remove
・確認
[root]# ls -l /etc/rc*.d | grep mysqld
lrwxrwxrwx 1 root root 16 2月 12 15:37 K01mysqld -> ../init.d/mysqld
lrwxrwxrwx 1 root root 16 2月 12 15:37 K01mysqld -> ../init.d/mysqld
lrwxrwxrwx 1 root root 16 2月 12 15:37 S01mysqld -> ../init.d/mysqld
lrwxrwxrwx 1 root root 16 2月 12 15:37 S01mysqld -> ../init.d/mysqld
lrwxrwxrwx 1 root root 16 2月 12 15:37 S01mysqld -> ../init.d/mysqld
lrwxrwxrwx 1 root root 16 2月 12 15:37 S01mysqld -> ../init.d/mysqld
lrwxrwxrwx 1 root root 16 2月 12 15:37 K01mysqld -> ../init.d/mysqld
※ 上記リンクが無くても、Systemd によるサービス管理はできる
デフォルト設定(dnf, rpm アップグレード時に書き換わる)
[root]# vim /usr/lib/systemd/system/mysqld.service
[Unit] Description = MariaDB - Database Server After = network.target [Service] Environment=SYSTEMD_LOG_LEVEL=debug,console:info ExecStart = /usr/local/mysql/bin/mysqld --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]# cp -v /usr/lib/systemd/system/mysqld.service /etc/systemd/system
・ユニットファイル登録/変更時[root]# systemctl daemon-reload
・systemd によるセキュリティスコア
[root]# systemd-analyze security mysqld.service
→ Overall exposure level for mysqld.service: 1.4 OK
・起動/停止
[root]# systemctl { start stop reload-or-restart } mysqld.service
・自動起動/停止[root]# systemctl { enable disable } mysqld.service
・起動/自動起動を同時に行う[root]# systemctl enable --now mysqld.service
・停止/自動停止を同時に行う[root]# systemctl disable --now mysqld.service
[user]$ mysql -u ユーザー名 -p データベース名