オイオイ、とうとう無料の VPS が出たのかいな。
無料VPS | 圧倒的な性能・コスパのVPS | XServer VPS
XServerのサブドメインが無料で利用できます。
もちろん、制約もあります。
VPS から外部へのメール送信ができません。
システムに過度な負荷をかける行為や不正行為に対し、自動検知システムにより制限が適用される場合があります。
コントロールパネルから2日または4日ごとに契約を更新する必要があります。
CPU の情報を確認したければ、下記コマンドなどで。
:~# cat /proc/cpuinfo
:~# lscpu
CentOS Stream 10 (64bit) を試してみました。
僕は、インスタンス作成時に自前の公開鍵で SSH Key 設定をしています。
まず、「パケットフィルター設定」でポートを開けないと SSH 接続すらできないようです。
参考:SSH接続方法
端末から接続します。
:~$ ssh root@xxx.xxx.xxx.xxx
「VNCコンソール」と「シリアルコンソール」でのコンソール接続もできます。
参考:コンソール接続
主な項目を確認。
:~# sshd -T | grep -i -E 'SyslogFacility|PermitRootLogin|PermitEmptyPasswords|PasswordAuthentication'
permitrootlogin without-password
passwordauthentication no
permitemptypasswords no
syslogfacility AUTHPRIV
僕はこれで問題なかったので変更していませんが、変更するなら、
:~# vi /etc/ssh/sshd_config
を編集して、sshd 再起動。
:~# systemctl restart sshd
システムのタイムゾーンなどを確認。Time zone は Asia/Tokyo でした。
:~# timedatectl
文字コードなどを確認。LANG=ja_JP.UTF-8 でした。
:~# localectl
SELINUX は、disabled にしています。
:~# vi /etc/sysconfig/selinux
メモリ確認。
:~# free -m
ホスト名を変更。XServerのサブドメインを利用したので、それに合わせています。
:~# hostnamectl set-hostname xxxxx.xvps.jp
確認。
:~# hostnamectl
端末上の表記は再ログインなどで反映されます。
以下を見ておく。
:~# cat /etc/hostname
:~# cat /etc/hosts
:~# cat /etc/resolv.conf
:~# nmcli d
DEVICE TYPE STATE CONNECTION
ens3 ethernet 接続済み cloud-init ens3
lo loopback 接続済み (外部) lo
:~# nmcli d show ens3
「パケットフィルター設定」を行っていますが、firewalld も起動しました。
:~# systemctl enable --now firewalld
アクティブゾーンを確認する。
:~# firewall-cmd --get-active-zones
public (default)
interfaces: ens3
アクティブゾーンの恒久的なファイアウォール設定を確認。
:~# firewall-cmd --list-all --zone=public --permanent
public (default)
target: default
ingress-priority: 0
egress-priority: 0
icmp-block-inversion: no
interfaces:
sources:
services: cockpit dhcpv6-client ssh
ports:
protocols:
forward: yes
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
EPEL のリポジトリをインストール
:~# dnf -y install epel-release
EPEL 関係、無効化。(使うときには、--enablerepo= を付ける)
:~# dnf config-manager --disable epel
有効化されているリポジトリの一覧を確認するなら。
:~# dnf repolist
有効および無効なリポジトリーの両方を一覧表示するなら。
:~# dnf repolist all
dnf アップデート
:~# dnf -y update
dnf-automatic インストール。
:~# dnf -y install dnf-automatic
dnf-automatic-install 自動起動有効+起動。
:~# systemctl enable --now dnf-automatic-install.timer
nkf コマンドインストール。
:~# dnf --enablerepo=epel install nkf
jq コマンドインストール。(インストール済みでした)
:~# dnf install jq
現在使用中のカーネルバージョンを確認する。
:~# uname -r
インストール済みを確認する。
:~# dnf repoquery --installonly
カーネルがアップデートされていると思うので再起動する。
:~# reboot
Chrony はインストール済みでした。
:~# vi /etc/chrony.conf
変更。(追加)
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (https://www.pool.ntp.org/join.html).
#pool 2.centos.pool.ntp.org iburst
pool ntp.nict.jp iburst
再起動。
:~# systemctl restart chronyd
時刻同期状態確認。
:~# chronyc sources
perl-CPAN をインストール。
:~# dnf install perl-CPAN
入力。
:~# perl -MCPAN -e shell
CPAN.pm requires configuration, but most of it can be done automatically.
If you answer 'no' below, you will enter an interactive dialog for each
configuration option instead.
Would you like to configure as much as possible automatically? [yes] yes
Perl site library directory "/usr/local/share/perl5/5.40" does not exist.
Perl site library directory "/usr/local/share/perl5/5.40" created.
Perl site library directory "/usr/local/lib64/perl5/5.40" does not exist.
Perl site library directory "/usr/local/lib64/perl5/5.40" created.
We initialized your 'urllist' to https://cpan.org/. Type 'o conf init urllist' to change it.
Autoconfiguration complete.
commit: wrote '/root/.cpan/CPAN/MyConfig.pm'
You can re-run configuration any time with 'o conf init' in the CPAN shell
Terminal does not support AddHistory.
To fix that, maybe try> install Term::ReadLine::Perl
cpan shell -- CPAN exploration and modules installation (v2.36)
Enter 'h' for help.
cpan[1]> install MIME::Base64
cpan[2]> install CGI
cpan[3]> install Jcode
cpan[4]> quit
Apache と PHP 及び PHP 関連パッケージをインストール。
:~# dnf -y install httpd php php-mbstring php-gd php-json php-xml php-zip
インストールされたモジュールの一覧を確認するなら。
:~# php -m
Apache 設定ファイル編集。
:~# vi /etc/httpd/conf/httpd.conf
変更と追加と削除。
ServerAdmin root@localhost
↓↓↓
ServerAdmin webmaster@xxxxx.xvps.jp
・・・
・・・
#ServerName www.example.com:80
↓↓↓
ServerName xxxxx.xvps.jp:80
・・・
・・・
<Directory "/var/www/html">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks
↓↓↓
Options Includes ExecCGI FollowSymLinks
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride None
↓↓↓
AllowOverride All
#
# Controls who can get stuff from this server.
#
Require all granted
</Directory>
・・・
・・・
<IfModule log_config_module>
#
# The following directives define some format nicknames for use with
# a CustomLog directive (see below).
#
LogFormat "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
↓↓↓
LogFormat "%h %l %u %t \"%!414r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined
・・・
・・・
#
# If you prefer a logfile with access, agent, and referer information
# (Combined Logfile Format) you can use the following directive.
#
SetEnvIf Request_URI "default\.ida" no_log
SetEnvIf Request_URI "cmd\.exe" no_log
SetEnvIf Request_URI "root\.exe" no_log
SetEnvIf Request_URI "Admin\.dll" no_log
SetEnvIf Request_URI "NULL\.IDA" no_log
SetEnvIf Remote_Addr 127.0.0.1 no_log
CustomLog "logs/access_log" combined env=!no_log
</IfModule>
・・・
・・・
#AddHandler cgi-script .cgi .pl
以下を最終行へ追加。
ServerTokens Prod
TraceEnable off
autoindex 設定ファイル編集。
:~# vi /etc/httpd/conf.d/autoindex.conf
削除。
<Directory "/usr/share/httpd/icons">
Options Indexes MultiViews FollowSymlinks
AllowOverride None
Require all granted
</Directory>
テストページ削除。
:~# rm -f /etc/httpd/conf.d/welcome.conf
Perl コマンドへ /usr/local/bin/perl でもアクセスできるようにする。
:~# ln -s /usr/bin/perl /usr/local/bin/perl
Perl のパスを確認。
:~# whereis perl
Apache 自動起動有効+起動。
:~# systemctl enable --now httpd
ポート開放。
:~# firewall-cmd --add-service=http --zone=public --permanent
:~# firewall-cmd --reload
「パケットフィルター設定」で「フィルター:Web」を追加。
Web コンテンツ編集ユーザ(例:himari)を作成。
:~# useradd himari
:~# passwd himari
ドキュメントルート所有者を変更する。
:~# chown himari: /var/www/html/
himari で SSH 鍵方式ログイン出来るようにする。
himari にスイッチする。
:~# su - himari
:~$ mkdir ~/.ssh
:~$ chmod 700 ~/.ssh
公開鍵の中身を authorized_keys にコピペして保存。
:~$ vi ~/.ssh/authorized_keys
:~$ chmod 600 ~/.ssh/authorized_keys