さくらのクラウドでCentOS7を導入したメモ - その1

ログインユーザーの追加とSSHの設定

ユーザーの追加

useradd <username>
passwd <username>
usermod -G wheel <username>

SSHの設定

cp /etc/ssh/sshd_config /etc/ssh/sshd_config.org
vi /etc/ssh/sshd_config

以下の部分をnoに変更

PermitRootLogin no 
PasswordAuthentication no

保存したら

systemctl restart sshd
su - <username>

ここからログインユーザー側

mkdir .ssh
chmod 700 .ssh
vi ~/.ssh/authorized_keys

認証キー追加したら

chmod 600 ~/.ssh/authorized_keys

SiteGuardの導入

さくらのVPSさくらのクラウドではSiteGuardが無償提供されています。スタートアップスクリプトが残念ながらApacheバージョンでしたので手動で導入。

cd /usr/local/src
curl -OL <SiteGuard Server Edition のインストールファイル>
tar -zxvf siteguard-server-edition-*****.tar.gz
cd siteguard-server-edition-****
make install

SiteGuardのプラグインを導入するため、nginxはソースからコンパイルする必要があります。 ここ注意。あと、、、めんどくさい。

必要なライブラリを入れてきます。詳しく調べてないけど、OpenSSLは1.1.1を入れた方がよさそうだったのでソースからコンパイル

yum install -y zlib-devel pcre-devel apr-devel apr-util-devel java-1.8.0-openjdk
cd /usr/local/src
curl -OL https://www.openssl.org/source/openssl-1.1.1j.tar.gz
tar -zxvf openssl-1.1.1j.tar.gz
./config --prefix=/usr/local/openssl-1.1.1 shared zlib
make depend
make
make install
vi /etc/ld.so.conf.d/openssl-1.1.1.conf

以下を追加

/usr/local/openssl-1.1.1/lib

保存して反映。

ldconfig

ようやくnginxをインストール

cd /usr/local/src
curl -OL http://nginx.org/download/nginx-1.18.0.tar.gz
tar -zxvf nginx-1.18.0.tar.gz
cd nginx-1.18.0
./configure --add-module=/opt/jp-secure/siteguardlite/nginx --with-http_ssl_module --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --with-openssl=/usr/local/src/openssl-1.1.1j
make
make install

systemdの設定

vi /usr/lib/systemd/system/nginx.service

以下を記述。

[Unit]
Description=nginx - high performance web server
Documentation=http://nginx.org/en/docs/
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
PIDFile=/etc/nginx/logs/nginx.pid
ExecStartPre=/usr/sbin/nginx -t -c /etc/nginx/conf/nginx.conf
ExecStart=/usr/sbin/nginx -c /etc/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

登録、自動起動

systemctl start nginx
systemctl enable nginx

これで最後、SiteGuardのセットアップ。

cd /opt/jp-secure/siteguardlite/
./setup.sh

ファイヤーウォールの設定をすれば終了。

firewall-cmd --list-all
firewall-cmd --add-service=http --zone=public --permanent
firewall-cmd --add-service=https --zone=public --permanent
firewall-cmd --add-port=9443/tcp --zone=public --permanent
firewall-cmd --reload