自分用メモなのでかなり割愛しています。詳細を知りたい場合は各々のサイトでご確認ください。
Fedora36 は最小パッケージでインストール メディアからのインストール手順は割愛します
xxxxxxxxxx
dnf install nginx
dnf install php-pdo_mysql php php-gd php-mbstring php-fpm php-devel php-opcache php-pecl-apcu php-pecl-memcached
dnf install mariadb mariadb-server
dnf install postfix mailx ※PHPからメール送信に必要
dnf install php-json ※phpMyAdmin実行に必要
dnf install htop
xxxxxxxxxx
systemctl enable nginx
systemctl start nginx
systemctl enable php-fpm
systemctl start php-fpm
systemctl enable mariadb
systemctl start mariadb
systemctl enable chronyd
systemctl start chronyd
systemctl enable postfix
systemctl start postfix
xxxxxxxxxx
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled ※enforcingをdisabledに変更
# SELINUXTYPE= can take one of these three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
設定後OSを再起動する。
sshの接続ポート番号を任意の番号に変更
xxxxxxxxxx
Port 2222 ※22 から変更
PermitRootLogin no ※Fedora31からデフォルトで no なので変更不要
xxxxxxxxxx
systemctl restart sshd
デフォルトは ssh のポートしか空いてないので、http のポートを開ける。
xxxxxxxxxx
firewall-cmd --permanent --add-service=http
firewall-cmd --permanent --add-service=https
firewall-cmd --permanent --add-port=1234/tcp
firewall-cmd --reload
xxxxxxxxxx
firewall-cmd --state
running
xxxxxxxxxx
firewall-cmd --list-services
dhcpv6-client ssh
xxxxxxxxxx
pool 2.fedora.pool.ntp.org iburst
※現在はディストリビュータ毎の pool サーバを指定することで、ラウンドロビンで ntp サーバを参照するので設定不要です。
xxxxxxxxxx
chronyc sources
xxxxxxxxxx
client_max_body_size 2G;
xxxxxxxxxx
gzip on;
gzip_http_version 1.0;
gzip_vary on;
gzip_comp_level 6;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript;
gzip_disable "MSIE [1-6]\.";
gzip_disable "Mozilla/4";
gzip_proxied any;
gzip_buffers 16 8k;
xxxxxxxxxx
curl -I -H 'Accept-Encoding: gzip,deflate' http://www.qurataro.com/wikipedia/css/jqcloudlist.css
Content-Encoding: gzip が確認できたらOK
xxxxxxxxxx
post_max_size 2GB
upload_max_filesize 2GB
xxxxxxxxxx
date.timezone = Asia/Tokyo
xxxxxxxxxx
su - root ※ root ユーザーにならないと MariaDB の root ユーザーにアクセスできません
mysql -u root
mysql > SET PASSWORD = PASSWORD('youwantpassword')
NetworkManager-wait-online はネットワークが正常に起動しているかを確認するデーモンですが、VPS環境のようにネットワークチェックに時間がかかる環境だとデフォルトの30秒では早すぎてエラーが出ます。そこで起動時間を240秒に変えることで回避することができます。
xxxxxxxxxx
cp -p /usr/lib/systemd/system/NetworkManager-wait-online.service /etc/systemd/system/.
vi /etc/systemd/system/NetworkManager-wait-online.service
x[Unit]
Description=Network Manager Wait Online
Documentation=man:nm-online(1)
Requires=NetworkManager.service
After=NetworkManager.service
Before=network-online.target
[Service]
Type=oneshot
ExecStart=/usr/bin/nm-online -s -q --timeout=240 <-- デフォルト30
RemainAfterExit=yes
[Install]
WantedBy=network-online.target
無料の SSL 証明書を取得する方法です。
xxxxxxxxxx
※CentOS8系のみ実施 dnf install epel-release
dnf install certbot
※このコマンドを動かすために必要な python ライブラリなども同時にダウンロードされる
xxxxxxxxxx
certbot certonly \ # 証明書の作成
--webroot \ # 既存のウェブサーバを使うモードを選択
-w /usr/share/nginx/html \ # ドキュメント・ルートのパス
-d www.qurataro.com # 認証するドメイン名
そのあと、規約の同意(Agree)
xxxxxxxxxx
ls /etc/letsencrypt/
accounts archive csr keys live renewal renewal-hooks
xxxxxxxxxx
ls /etc/letsencrypt/live/qurataro.com/
cert.pem chain.pem fullchain.pem privkey.pem
xxxxxxxxxx
server {
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
server_name qurataro.com;
root /usr/share/nginx/html;
ssl_certificate "/etc/letsencrypt/live/qurataro.com/fullchain.pem";
ssl_certificate_key "/etc/letsencrypt/live/qurataro.com/privkey.pem";
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 10m;
ssl_ciphers PROFILE=SYSTEM;
ssl_prefer_server_ciphers on;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
証明書の期限を定期的に自動更新する
※cron は脆弱性の問題があり Fedora36 からデフォルトではインストールされない。そのため、cron の代替えである systemd の timer 機能を使用する。
xxxxxxxxxx
systemctl enable --now certbot-renew.timer
※インストールすると自動で設定されていることが多い
xxxxxxxxxx
# systemctl list-timers
NEXT LEFT LAST PASSED UNIT ACTIVATES
Thu 2022-06-02 05:54:20 JST 14h left Wed 2022-06-01 15:33:41 JST 13min ago certbot-renew.timer certbot-renew.service
`上記コマンドで certbot-renew.timer が表示されたら設定されている証明になります。
証明書が更新された後、nginx を再起動しないと証明書が反映されないので、nginx を再起動する設定を certbot-renew.timer に設定します。
xxxxxxxxxx
# vi /etc/sysconfig/certbot
# An example to restart httpd would be:
# POST_HOOK="--post-hook 'systemctl restart httpd'"
POST_HOOK=``"--post-hook 'systemctl restart nginx'"
CERT と KEY を合算したファイルを作成し、/etc/cockpit/ws-certs.d/ の中に設置する。
xxxxxxxxxx
cat /etc/letsencrypt/live/www.qurataro.com/fullchain.pem > /etc/cockpit/ws-certs.d/10-letsecnrypt.cert
cat /etc/letsencrypt/live/www.qurasystem.com/privkey.pem >> /etc/cockpit/ws-certs.d/10-letsecnrypt.cert
頭の番号の順番でファイルが読まれるデフォルトで設置してあるファイル ※0-self-signed.certを参考に
xxxxxxxxxx
systemctl restart cockpit
xxxxxxxxxx
02 04 16 * * /usr/bin/cat /etc/letsencrypt/live/www.qurasystem.com/fullchain.pem > /etc/cockpit/ws-certs.d/10-letsecnrypt.cert
03 04 16 * * /usr/bin/cat /etc/letsencrypt/live/www.qurasystem.com/privkey.pem >> /etc/cockpit/ws-certs.d/10-letsecnrypt.cert
04 04 16 * * /usr/bin/systemctl restart cockpit
xxxxxxxxxx
tar xvfz mecab-x.xx.xx.tar.gz
./configure --with-charset=utf8
make
make install
xxxxxxxxxx
tar zxfv mecab-ipadic-2.7.0-XXXX.tar.gz
mecab-ipadic-2.7.0-XXXX
./configure --with-charset=utf8
make
make install
wikipedia.dic を作成しているのでそれを利用するように修正する。 /usr/local/lib/mecab に作成した辞書やユーザ辞書を配置する。
xxxxxxxxxx
dicdir = /usr/local/lib/mecab/dic/ipadic
userdic = /usr/local/lib/mecab/dic/ipadic/wikipedia.dic
php-mecab-0.5.0 は PHP7 系に未対応の為、PHP7系対応済みの php-mecab-0.6.0 を使用する。
xxxxxxxxxx
wget https://github.com/rsky/php-mecab/archive/master.zip
tar xzvf master.zip
cd php-mecab-master/mecab
phpize
./configure --with-php-config=/bin/php-config --with-mecab=/usr/local/bin/mecab-config
make
make install
xxxxxxxxxx
vi /etc/php.d/mecab.ini
extension=mecab.so
/usr/local/libexec/mecab/mecab-dict-index -d /usr/local/lib/mecab/dic/ipadic
-u wikipedia.dic -f utf-8 -t utf-8 wikipedia.csv