提供:あわWiki
移動先: 案内検索

自宅サーバーの日常管理

Webユーザー追加

SSHによるリモート接続もできるようにする場合

※例としてユーザー名をsudachiとする

一般ユーザーの場合

[root@host2 ~]# useradd sudachi ← 一般ユーザー追加

[root@host2 ~]# passwd sudachi ← 一般ユーザーパスワード設定
Changing password for user sudachi.
New password: ← 一般ユーザーパスワード応答
Retype new password: ← 一般ユーザーパスワード応答(確認)
passwd: all authentication tokens updated successfully.

[root@host2 ~]# chmod 711 /home/sudachi/
← 一般ユーザーのホームディレクトリのパーミッション変更

chrootユーザーの場合

[root@host2 ~]# chroot-useradd sudachi ← 一般ユーザー追加
Changing password for user sudachi.
New UNIX password: ← 一般ユーザーパスワード応答
Retype new UNIX password: ← 一般ユーザーパスワード応答(確認)
passwd: all authentication tokens updated successfully.

[root@host2 ~]# chmod 711 /home/sudachi/
← 一般ユーザーのホームディレクトリのパーミッション変更

※以降、SSHによるリモート接続もできるWebユーザーを追加する場合はこの手順で行う

SSHによるリモート接続はできないようにする場合

※例としてユーザ名をsudachiとする

一般ユーザーの場合

[root@host2 ~]# useradd -s /sbin/nologin sudachi ← 一般ユーザー追加

[root@host2 ~]# passwd sudachi ← 一般ユーザーパスワード設定
Changing password for user sudachi.
New password: ← 一般ユーザーパスワード応答
Retype new password: ← 一般ユーザーパスワード応答(確認)
passwd: all authentication tokens updated successfully.

[root@host2 ~]# chmod 711 /home/sudachi/ ← 一般ユーザーのホームディレクトリのパーミッション変更

chrootユーザーの場合

[root@host2 ~]# chroot-useradd sudachi /sbin/nologin ← 一般ユーザー追加
Changing password for user sudachi.
New UNIX password: ← 一般ユーザーパスワード応答
Retype new UNIX password: ← 一般ユーザーパスワード応答(確認)
passwd: all authentication tokens updated successfully.

[root@host2 ~]# chmod 711 /home/sudachi/ ← 一般ユーザーのホームディレクトリのパーミッション変更

※以降、SSHによるリモート接続はできないWebユーザーを追加する場合はこの手順で行う

Webサーバー管理

ドキュメントルート変更

ドキュメントルート、エイリアス等の変更です。

# vi /etc/httpd/conf.d/DocumentRoot.conf

DocumentRoot "/home/sysop/public_html"

# /etc/rc.d/init.d/httpd reload

メールユーザ追加

SSHによるリモート接続はできないようにする場合

※例としてユーザー名をsudachiとする

[root@host2 ~]# useradd -s /sbin/nologin sudachi ← ユーザー追加

[root@host2 ~]# passwd sudachi ← パスワード設定
Changing password for user sudachi.
New UNIX password:  ← パスワード応答
Retype new UNIX password:  ← パスワード応答(確認)
passwd: all authentication tokens updated successfully.

SSHによるリモート接続もできるようにする場合

※例としてユーザ名をsudachiとする

[root@host2 ~]# useradd sudachi ← ユーザ追加

[root@host2 ~]# passwd sudachi ← パスワード設定
Changing password for user sudachi.
New UNIX password:  ← パスワード応答
Retype new UNIX password:  ← パスワード応答(確認)
passwd: all authentication tokens updated successfully.

メールの転送設定

※同じサーバー内でのメール転送設定です。

[root@host2 ~]# echo sns: webmaster >> /etc/aliases
[root@host2 ~]# newaliases ← メール転送設定反映

一般ユーザーの作成

※例として一般ユーザー名をsudachiとする

[root@host2 ~]# useradd sudachi ← 一般ユーザーの作成

[root@host2 ~]# passwd sudachi ← ユーザーパスワード設定
Changing password for user sudachi.
New UNIX password:  ← ユーザーパスワード応答
Retype new UNIX password:  ← ユーザーパスワード応答(確認)
passwd: all authentication tokens updated successfully.

chrootユーザー作成

ホームディレクトリより上層へのアクセスを禁止するユーザー(ここではsudachiとする)の作成

[root@host2 ~]# chroot-useradd sudachi ← ユーザー作成
Changing password for user sudachi.
New UNIX password: ← ユーザーパスワード応答
Retype new UNIX password: ← ユーザーパスワード応答(確認)
passwd: all authentication tokens updated successfully.

rootになれる管理者ユーザーを追加

例として、管理者用の一般ユーザー名をsudachiとする

[root@host2 ~]# usermod -G wheel sudachi ← 管理者ユーザーをwheelグループに追加

ユーザーの削除

※例として一般ユーザー名をsudachiとする

[root@host3 ~]# userdel -r sudachi ← ユーザーsudachiの削除

システムの停止&再起動

[root@host2 ~]# halt ← システム停止する場合

[root@host2 ~]# reboot ← システム再起動する場合

バックアップファイルからの復元

バックアップからディレクトリ単位、ファイル単位でリストア(復元)する。

ファイル復元

[root@host2 ~]# tar jxvfP /backup/backup.tar.bz2 /home/yuzu/public_html/index.php ← ファイル復元
/home/yuzu/public_html/index.php

ディレクトリ復元

[root@host2 ~]# tar jxvfP /backup/backup.tar.bz2 /home/yuzu/public_html ← ディレクトリ復元
/home/yuzu/public_html/
/home/yuzu/public_html/index.php

ディレクトリ復元確認

[root@host2 ~]# ll /home/yuzu
合計 60
・・・・
drwxr-xr-x 15 yuzu yuzu 4096  4月  9 15:37 public_html
・・・・
↑ ディレクトリがパーミッション、所有者も含めて復元されてる

ファイル復元確認

[root@host2 ~]# ll /home/yuzu/piblic_html/
合計 1
・・・・
-rw-rw-r--  1 yuzu yuzu  3478 11月 10 04:47 index.php
・・・・
↑ ファイルがパーミッション、所有者も含めて復元されてる

データベースバックアップ

作成した、SQLデータベースバックアップスクリプトを実行する。
バックアップは毎日一回、SQLデータベースバックアップスクリプトにり実行している。

[root@host3 ~]# ./mysql-backup.sh

データベース復元

バックアップは毎日一回、SQLデータベースバックアップスクリプトにり実行している。

データベース作成

データーベースが存在する場合はしなくて良い。

[root@host3 ~]# mysqladmin -uroot -prootパスワード create wiki

データベース復元

データーベースのクローンを作成するときに使える。

[root@host3 ~]# mysql -u root -prootパスワード wiki < /backup/mysql/wiki.sql