[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]
User = mysql
Environment=SYSTEMD_LOG_LEVEL=debug,console:info
ExecStart = /usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
ExecStop = /bin/kill -SIGTERM $MAINPID
ExecReload = /bin/kill -SIGHUP $MAINPID
Restart = on-failure
RestartSec = 10s
PrivateDevices = true
PrivateMounts = true
PrivateUsers = true
RestrictNamespaces=true
ProtectControlGroups = true
ProtectKernelModules = true
ProtectKernelTunables = true
ProtectKernelLogs = true
ProtectClock = true
ProtectHome = true
ReadWritePaths = /usr/local/mysql
ProtectSystem = true
ProtectHostname = true
NoNewPrivileges = true
ProtectProc = noaccess
RestrictSUIDSGID = true
SystemCallArchitectures = native
SystemCallFilter=~@debug
SystemCallFilter=~@swap
SystemCallFilter=~@clock
SystemCallFilter=~@module
SystemCallFilter=~@raw-io
SystemCallFilter=~@reboot
SystemCallFilter=~@obsolete
SystemCallFilter=~@cpu-emulation
RestrictRealtime = true
LockPersonality = true
RemoveIPC = true
PrivateIPC = true
PrivateNetwork = true
MemoryDenyWriteExecute = true
ProcSubset = pid
UMask = 0077
[Install]
WantedBy = multi-user.target
ユーザー設定(優先される、設定変更はこちらに対して行う)
[root]# cp -v /usr/lib/systemd/system/mysqld.service /etc/systemd/system
・ユニットファイル登録/変更時[root]# systemctl daemon-reload
・起動/停止[root]# systemctl { start stop reload-or-restart } mysqld
・自動起動/停止[root]# systemctl { enable disable } mysqld
・起動/自動起動を同時に行う[root]# systemctl enable --now mysqld
・停止/自動停止を同時に行う[root]# systemctl disable --now mysqld
[user]$ mysql -u ユーザー名 -p データベース名