tag:blogger.com,1999:blog-55613721581450094172024-03-14T03:19:55.989+09:00小黒のTECHメモ(仮)【工事中】主にCentOS上で動かすWeb開発関連の記事を記載。xioheihttp://www.blogger.com/profile/02714083766459050534noreply@blogger.comBlogger37125tag:blogger.com,1999:blog-5561372158145009417.post-22432486571241026862023-03-15T11:28:00.001+09:002023-03-15T11:28:28.201+09:00【Wordpress】ワードプレスのブロックテーマTwentyTwentyThree(TT3)でのカスタムフィールドの使い方<h2>カスタムフィールドを表示させる手順</h2>
・プラグインAdvanced Custom Fieldsをインストール<br />
フィールド名:comment でカスタムフィールドを設定<br />
・プラグインMeta Field Blockをインストール
<h5>xxx.html編集</h5>
<pre class="code">
<!-- wp:mfb/meta-field-block {"fieldType":"acf","fieldName":"comment"} /-->
</pre>xioheihttp://www.blogger.com/profile/07600365896800702223noreply@blogger.comtag:blogger.com,1999:blog-5561372158145009417.post-61170846160450647092023-02-14T14:44:00.001+09:002023-02-14T14:44:30.998+09:00【Wordpress】ワードプレスのブロックテーマでアイキャッチ(サムネイル)一覧を表示させる<h2>トップページなどでの画像サムネイル一覧表示</h2>
久々にワードプレスをいじったところ、”ブロックテーマ”なるものに置き換わりエディターも以前使っていたものはクラシックへ。theme.jsonって?<br />
PHPをちょくせつ編集していたものが、テンプレートファイルxxx.htmlなどと置き換わり、<br />
試行錯誤している最中、色々と沼る要素在り。
<h5>ホーム画面にサムネイル一覧を表示させるタグ</h5>
home.htmlなどを編集。<br />
この場合はカスタム投稿タイプ”portfolio”を表示させる例。(一般的な投稿は”post”)
<pre class="code">
・
<ul class="portfolio">
<!-- wp:query {"queryId":1,"query":{"offset":0,"postType":"portfolio","categoryIds":[],"tagIds":[],"order":"desc","orderBy":"date","author":"","search":"","sticky":""}} -->
<!-- wp:post-template {"align":"wide"} -->
<li><!-- wp:post-featured-image {"isLink":true,"sizeSlug":"thumbnail"} /--></li>
<!-- /wp:post-template -->
<!-- /wp:query -->
</ul>
・
</pre>xioheihttp://www.blogger.com/profile/07600365896800702223noreply@blogger.comtag:blogger.com,1999:blog-5561372158145009417.post-21251789506995978182022-04-08T18:59:00.001+09:002022-04-09T03:35:35.655+09:00【Laravel】データーベースの特定のテーブルだけ修正、作り直したら外部キー制約でシーダーエラー<h2>特定のテーブルだけマイグレート</h2>
テーブルの作り直し作業が発生したため、<br />
マイグレーションファイルを修正後、マイグレートのやり直し。
<h5>マイグレーションの確認</h5>
<pre class="console">
$ php artisan migrate:status
+------+-------------------------------------------------------+-------+
| Ran? | Migration | Batch |
+------+-------------------------------------------------------+-------+
| Yes | 2019_12_14_000001_create_personal_access_tokens_table | 1 |
| Yes | 2022_04_03_051357_create_areas_table | 1 |
| Yes | 2022_04_03_051532_create_expeditions_table | 1 |
| Yes | 2022_04_03_071904_create_expedition_trigers | 1 |
+------+-------------------------------------------------------+-------+
</pre>
<h5>マイグレーションファイルの実行</h5>
<pre class="console">
$ php artisan migrate:refresh --step=1 --path=/database/migrations/2022_04_03_071904_create_expedition_trigers.php
Rolling back: 2022_04_03_071904_create_expedition_trigers
Rolled back: 2022_04_03_071904_create_expedition_trigers (76.64ms)
Migrating: 2022_04_03_071904_create_expedition_trigers
Migrated: 2022_04_03_071904_create_expedition_trigers (211.42ms)
</pre>
<h2>特定のテーブルだけシーダー</h2>
しかし、この後seedした結果
<h5>シーダーの実行</h5>
<pre class="console">
$ php artisan db:seed --class=ExpeditionTrigerSeeder
Illuminate\Database\QueryException
SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (`kancolle`.`expedition_trigers`, CONSTRAINT `expedition_trigers_parent_exp_id_foreign` FOREIGN KEY (`parent_exp_id`) REFERENCES `expeditions` (`exp_id`)) (SQL: insert into `expedition_trigers` (`exp_id`, `parent_exp_id`) values (8, A2), (A1, A3), (A2, A3), (24, A4), (A4, A5), (B3, A6), (A5, A6), (B4, A7))
at vendor/laravel/framework/src/Illuminate/Database/Connection.php:716
・
・
</pre>
と出てしまう。
MySQLで作成したテーブルのSQLを見てみると。
<pre class="console">
> SHOW CREATE TABLE expedition_trigers;
+--------------------+-----
| Table | Create Table |
+--------------------+------------------
| expedition_trigers | CREATE TABLE `expedition_trigers` (
`expedition_triger_id` int unsigned NOT NULL AUTO_INCREMENT,
`parent_exp_id` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL,
`exp_id` varchar(10) COLLATE utf8mb4_unicode_ci NOT NULL,
`updated_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
`created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`expedition_triger_id`),
KEY `expedition_trigers_parent_exp_id_foreign` (`parent_exp_id`),
KEY `expedition_trigers_exp_id_foreign` (`exp_id`),
CONSTRAINT `expedition_trigers_exp_id_foreign` FOREIGN KEY (`exp_id`) REFERENCES `expeditions` (`exp_id`),
CONSTRAINT `expedition_trigers_parent_exp_id_foreign` FOREIGN KEY (`parent_exp_id`) REFERENCES `expeditions` (`exp_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci |
</pre>
修正時に消した外部キーが追加されてしまっている。<br />
既存のマイグレーションファイルを削除して作成し直す事で解決。<br />
深くは考えずそういうものなのだという事で、、<br />
テーブルはMYSQLで手動で削除。
<h5>マイグレーションファイルの作成</h5>
<pre class="console">
$ php artisan make:migration expedition_trigers
Created Migration: 2022_04_08_211941_expedition_trigers
</pre>
<h5>マイグレーションファイルの実行</h5>
<pre class="console">
$ php artisan migrate:refresh --step=1 --path=/database/migrations/2022_04_08_211941_expedition_trigers.php
Migration not found: 2022_04_03_071904_create_expedition_trigers
Migrating: 2022_04_08_211941_expedition_trigers
Migrated: 2022_04_08_211941_expedition_trigers (31.00ms)
</pre>
<h5>シーダーの実行</h5>
<pre class="console">
$ php artisan db:seed --class=ExpeditionTrigerSeeder
Database seeding completed successfully.
</pre>xioheihttp://www.blogger.com/profile/07600365896800702223noreply@blogger.comtag:blogger.com,1999:blog-5561372158145009417.post-59282274035651701042022-04-02T15:48:00.006+09:002022-04-02T22:39:17.537+09:00RockyLinuxでサーバー構築 - 1.環境設定CentOS8が2021/12/31にサポート終了になりました。<br />
CentOS7はまだ猶予がありそうですが、<br />
代わりにRockyLinuxで環境を構築しました。<br />
RockyLinuxインストール後の設定です。<br />
インストールから始める方はこちらを参照↓<br />
<a href="/2017/09/vmwarecentos.html">VMware+CentOS7で開発環境構築 - 1.インストール</a>
<h2>SELinux停止</h2>
<h5>SELinuxが停止されているか確認</h5>
<pre class="console">
# getenforce
Disabled
</pre>
<h5>停止されていなかったら停止しておく</h5>
<pre class="console">
# getenforce
Enforcing
# setenforce 0
# getenforce
Permissive
# vi /etc/sysconfig/selinux
</pre>
<pre class="code">
# 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.
<span class="m1">SELINUX=disabled</span>
# SELINUXTYPE= can take one of these three values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are proo
tected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
</pre>
<table>
<tr><td>Enforcing</td><td>SELinux有効</td></tr>
<tr><td>Permissive</td><td>SELinux無効。ポリシーに違反するアクセスがあった場合アクセスを許可する</td></tr>
<tr><td>Disable</td><td>SELinux無効</td></tr>
</table>
<h2>rootになれるユーザの管理</h2>
<h5>wheelにrootになれるユーザhogehogeを追加</h5>
<pre class="console">
# usermod -G wheel hogehoge
</pre>
<pre class="code">
#%PAM-1.0
auth required pam_env.so
auth sufficient pam_rootok.so
# Uncomment the following line to implicitly trust users in the "wheel" group.
#auth sufficient pam_wheel.so trust use_uid
# Uncomment the following line to require a user to be in the "wheel" group.
auth required pam_wheel.so use_uid <span class="m1">←コメント削除</span>
auth substack system-auth
auth include postlogin
account sufficient pam_succeed_if.so uid = 0 use_uid quiet
account include system-auth
password include system-auth
session include system-auth
session include postlogin
session optional pam_xauth.so
</pre>
<h2>root宛のメールを一般ユーザで受け取る</h2>
<h5>root宛をhogehogeに転送</h5>
<pre class="console">
# sed -i '/^root:/d' /etc/aliases
# echo "root: hogehoge" >> /etc/aliases
# newaliases
</pre>
<div class="note">
<pre class="console">
# newaliases
-bash: newaliases: command not found
</pre>
と出た場合。Postfixがまだインストールされていないのでインストール後に。
<pre class="console">
# newaliases
newaliases: fatal: parameter inet_interfaces: no local interface found for ::1
</pre>
と出た場合はPostfixが起動してないので起動させてから。
</div>
<h2>dnfリポジトリを日本サーバーに設定</h2>
<h5>AppStreamリポジトリファイルの修正</h5>
<pre class="console">
# vi /etc/yum.repos.d/Rocky-AppStream.repo
</pre>
<pre class="code">
[appstream]
name=Rocky Linux $releasever - AppStream
<span class="m1">#</span>mirrorlist=https://mirrors.rockylinux.org/mirrorlist?arch=$basearch&repo=AppStream-$relea
sever
#baseurl=http://dl.rockylinux.org/$contentdir/$releasever/AppStream/$basearch/os/
<span class="m1">baseurl=https://ftp.riken.jp/Linux/rocky/$releasever/AppStream/$basearch/os/</span>
gpgcheck=1
enabled=1
countme=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rockyofficial
</pre>
<h5>BaseOSリポジトリファイルの修正</h5>
<pre class="console">
# vi /etc/yum.repos.d/Rocky-BaseOS.repo
</pre>
<pre class="code">
[baseos]
name=Rocky Linux $releasever - BaseOS
<span class="m1">#</span>mirrorlist=https://mirrors.rockylinux.org/mirrorlist?arch=$basearch&repo=BaseOS-$releasev
er
#baseurl=http://dl.rockylinux.org/$contentdir/$releasever/BaseOS/$basearch/os/
<span class="m1">baseurl=https://ftp.riken.jp/Linux/rocky/$releasever/BaseOS/$basearch/os/</span>
gpgcheck=1
enabled=1
countme=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rockyofficial
</pre>
<h5>BaseOSリポジトリファイルの修正</h5>
<pre class="console">
# vi /etc/yum.repos.d/Rocky-Extras.repo
</pre>
<pre class="code">
[extras]
name=Rocky Linux $releasever - Extras
<span class="m1">#</span>mirrorlist=https://mirrors.rockylinux.org/mirrorlist?arch=$basearch&repo=extras-$releasever
#baseurl=http://dl.rockylinux.org/$contentdir/$releasever/extras/$basearch/os/
<span class="m1">baseurl=https://ftp.riken.jp/Linux/rocky/$releasever/extras/$basearch/os/</span>
gpgcheck=1
enabled=1
countme=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rockyofficial:q
</pre>
<h5>有効にしているリポジトリの確認</h5>
<pre class="console">
# grep 'enabled=1' /etc/yum.repos.d/*
/etc/yum.repos.d/Rocky-AppStream.repo:enabled=1
/etc/yum.repos.d/Rocky-BaseOS.repo:enabled=1
/etc/yum.repos.d/Rocky-Extras.repo:enabled=1
</pre>
<h2>epelリポジトリの追加</h2>
<h5>epel-releaseインストール</h5>
<pre class="console">
# dnf -y install epel-release
</pre>
<h5>リポジトリ修正</h5>
<pre class="console">
# vi /etc/yum.repos.d/epel.repo
</pre>
<pre class="code">
[epel]
name=Extra Packages for Enterprise Linux $releasever - $basearch
# It is much more secure to use the metalink, but if you wish to use a local mirror
# place its address here.
#baseurl=https://download.example/pub/epel/$releasever/Everything/$basearch
metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-$releasever&arch=$basearch&i
nfra=$infra&content=$contentdir
enabled=1
<span class="m1">priority=10</span>
gpgcheck=1
countme=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-8
</pre>
<h2>elrepoリポジトリの追加</h2>
<h5>elrepo-releaseインストール</h5>
<pre class="console">
# dnf -y install elrepo-release
</pre>
<h5>リポジトリ修正</h5>
<pre class="console">
# vi /etc/yum.repos.d/elrepo.repo
</pre>
<pre class="code">
[elrepo]
name=ELRepo.org Community Enterprise Linux Repository - el8
baseurl=http://elrepo.org/linux/elrepo/el8/$basearch/
http://mirrors.coreix.net/elrepo/elrepo/el8/$basearch/
http://mirror.rackspace.com/elrepo/elrepo/el8/$basearch/
http://linux-mirrors.fnal.gov/linux/elrepo/elrepo/el8/$basearch/
mirrorlist=http://mirrors.elrepo.org/mirrors-elrepo.el8
enabled=1
<span class="m1">priority=10</span>
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-elrepo.org
</pre>
<h2>remiリポジトリの追加</h2>
<h5>RockyLinuxのバージョン確認</h5>
<pre class="console">
# cat /etc/redhat-release
Rocky Linux release 8.5 (Green Obsidian)
</pre>
<h5>remi-releaseインストール</h5>
<pre class="console">
# dnf -y install https://rpms.remirepo.net/enterprise/remi-release-8.5.rpm
</pre>
※自分の環境にあったrpmを使用する事。
<h5>リポジトリ修正</h5>
<pre class="console">
# vi /etc/yum.repos.d/remi-safe.repo
</pre>
<pre class="code">
[remi-safe]
name=Safe Remi's RPM repository for Enterprise Linux 8 - $basearch
#baseurl=http://rpms.remirepo.net/enterprise/8/safe/$basearch/
#mirrorlist=https://rpms.remirepo.net/enterprise/8/safe/$basearch/httpsmirror
mirrorlist=http://cdn.remirepo.net/enterprise/8/safe/$basearch/mirror
enabled=1
<span class="m1">priority=10</span>
gpgcheck=1
repo_gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi.el8
</pre>
<pre class="console">
# vi /etc/yum.repos.d/remi-modular.repo
</pre>
<pre class="code">
[remi-modular]
name=Remi's Modular repository for Enterprise Linux 8 - $basearch
#baseurl=http://rpms.remirepo.net/enterprise/8/modular/$basearch/
#mirrorlist=https://rpms.remirepo.net/enterprise/8/modular/$basearch/httpsmirror
mirrorlist=http://cdn.remirepo.net/enterprise/8/modular/$basearch/mirror
enabled=1
<span class="m1">priority=10</span>
gpgcheck=1
repo_gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi.el8
</pre>
<h5>有効にしているリポジトリの確認</h5>
<pre class="console">
# grep 'enabled=1' /etc/yum.repos.d/*
/etc/yum.repos.d/elrepo.repo:enabled=1
/etc/yum.repos.d/epel-modular.repo:enabled=1
/etc/yum.repos.d/epel.repo:enabled=1
/etc/yum.repos.d/remi-modular.repo:enabled=1
/etc/yum.repos.d/remi-safe.repo:enabled=1
/etc/yum.repos.d/Rocky-AppStream.repo:enabled=1
/etc/yum.repos.d/Rocky-BaseOS.repo:enabled=1
/etc/yum.repos.d/Rocky-Extras.repo:enabled=1
</pre>
<h5>最新のパッケージに更新</h5>
<pre class="console">
# dnf -y upgrade
</pre>
<h2>その他の初期設定</h2>
<h5>ホスト名の設定</h5>
<pre class="console">
# hostnamectl set-hostname kowloonet.net
</pre>
<h5>自動アップデート</h5>
<pre class="console">
# dnf -y install dnf-automatic
systemctl start dnf-automatic.timer
systemctl enable dnf-automatic.timer
</pre>
<h5>開発ツールのインストール</h5>
<pre class="console">
# dnf -y groupinstall base "Development tools"
</pre>
<h5>コンソール日本語化</h5>
<pre class="console">
# dnf -y install langpacks-ja glibc-langpack-ja
# localectl set-locale LANG=ja_JP.UTF-8
</pre>
<h5>vimの設定</h5>
<pre class="console">
# echo "alias vi='vim'" >> /etc/profile
# source /etc/profile
# vi /etc/vimrc
</pre>
下記を追加
<pre class="code">
set tabstop=2
set expandtab
set shiftwidth=2
set list
set whichwrap=b,s,[,],<,>
</pre>
<h5>PERLのシンボリックリンク作成</h5>
<pre class="console">
# ln -s /usr/bin/perl /usr/local/bin/perl
</pre>
<h2>不要なサービスの停止</h2>
<h5>サービス一覧</h5>
<pre class="console">
# systemctl list-units --type service
UNIT LOAD ACTIVE SUB DESCRIPTION
auditd.service loaded active running Security Auditing Service
chronyd.service loaded active running NTP client/server
crond.service loaded active running Command Scheduler
dbus.service loaded active running D-Bus System Message Bus
dovecot.service loaded active running Dovecot IMAP/POP3 email server
dracut-shutdown.service loaded active exited Restore /run/initramfs on shutdown
firewalld.service loaded active running firewalld - dynamic firewall daemon
getty@tty1.service loaded active running Getty on tty1
httpd.service loaded active running The Apache HTTP Server
import-state.service loaded active exited Import network configuration from initramfs
irqbalance.service loaded active running irqbalance daemon
kmod-static-nodes.service loaded active exited Create list of required static device nodes for the curre>
ldconfig.service loaded active exited Rebuild Dynamic Linker Cache
lvm2-monitor.service loaded active exited Monitoring of LVM2 mirrors, snapshots etc. using dmeventd>
mailman.service loaded active running GNU Mailing List Manager
NetworkManager-wait-online.service loaded active exited Network Manager Wait Online
NetworkManager.service loaded active running Network Manager
nis-domainname.service loaded active exited Read and set NIS domainname from /etc/sysconfig/network
polkit.service loaded active running Authorization Manager
postfix.service loaded active running Postfix Mail Transport Agent
rsyslog.service loaded active running System Logging Service
saslauthd.service loaded active running SASL authentication daemon.
selinux-autorelabel-mark.service loaded active exited Mark the need to relabel after reboot
serial-getty@ttyS0.service loaded active running Serial Getty on ttyS0
sshd.service loaded active running OpenSSH server daemon
sssd.service loaded active running System Security Services Daemon
systemd-fsck-root.service loaded active exited File System Check on Root Device
systemd-hwdb-update.service loaded active exited Rebuild Hardware Database
systemd-journal-catalog-update.service loaded active exited Rebuild Journal Catalog
systemd-journal-flush.service loaded active exited Flush Journal to Persistent Storage
systemd-journald.service loaded active running Journal Service
systemd-logind.service loaded active running Login Service
systemd-random-seed.service loaded active exited Load/Save Random Seed
systemd-remount-fs.service loaded active exited Remount Root and Kernel File Systems
systemd-sysctl.service loaded active exited Apply Kernel Variables
systemd-sysusers.service loaded active exited Create System Users
systemd-tmpfiles-setup-dev.service loaded active exited Create Static Device Nodes in /dev
systemd-tmpfiles-setup.service loaded active exited Create Volatile Files and Directories
systemd-udev-trigger.service loaded active exited udev Coldplug all Devices
systemd-udevd.service loaded active running udev Kernel Device Manager
systemd-update-done.service loaded active exited Update is Completed
systemd-update-utmp.service loaded active exited Update UTMP about System Boot/Shutdown
systemd-user-sessions.service loaded active exited Permit User Sessions
tuned.service loaded active running Dynamic System Tuning Daemon
user-runtime-dir@0.service loaded active exited User runtime directory /run/user/0
user-runtime-dir@1000.service loaded active exited User runtime directory /run/user/1000
user@0.service loaded active running User Manager for UID 0
user@1000.service loaded active running User Manager for UID 1000
vsftpd.service loaded active running Vsftpd ftp daemon
LOAD = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB = The low-level unit activation state, values depend on unit type.
49 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.
</pre>
postfix,dovecot,httpd,sshd,vsftpd,mailmanは導入済み<br />
不要なサービスはどれでしょうか。後回し。xioheihttp://www.blogger.com/profile/07600365896800702223noreply@blogger.comtag:blogger.com,1999:blog-5561372158145009417.post-26205811652012304792022-04-02T07:45:00.001+09:002022-04-02T07:45:07.508+09:00【RockyLinux】mailmanの通し番号(シーケンス番号)をリセット・変更<h2>mailmanの通し番号を指定した値に変更</h2>
CentOS8からRockyLinuxに変更し、環境を再構築。<br />
今までの通し番号を引き継ぐ必要がでたため<br />
シーケンス番号を49に変更する例。<br />
リセットしたい場合は<br />
m.post_id=1
<h5>コマンドからの変更</h5>
<pre class="console">
# /usr/lib/mailman/bin/withlist メーリングリスト名
Loading list メーリングリスト名 (unlocked)
The variable `m' is the dev MailList instance
>>> m.Lock()
>>> m.post_id
2.0
>>> m.post_id=49
>>> m.Save()
>>>
Unlocking (but not saving) list: メーリングリスト名
Finalizing
</pre>
xioheihttp://www.blogger.com/profile/07600365896800702223noreply@blogger.comtag:blogger.com,1999:blog-5561372158145009417.post-87252967218652109582022-02-18T05:44:00.000+09:002022-02-18T05:44:03.166+09:00【Wordpress】ワードプレスでカスタム投稿記事をメールで送信(テキストメール編)
<h2>メール送信</h2>
ステータスが公開になったときにメールを送信する。<br />
HTMLで記載された記事のタグと改行を削除。<br />
改行が3個以上続くときは2個(最大1行の空白行)とする。
<h5>function.php</h5>
<pre class="console">
function sendmail_post_article($new_status, $old_status, $post) {
$active_posttype = 'news'; // 記事のカテゴリ
$mail_to = 'xxx@kowloonet.net';
$mail_from_name = "小黒のtechメモ(仮)";
$mail_from = 'yyy@kowloonet.net';
$from = mb_encode_mimeheader($mail_from_name)." <$mail_from>";
$mail_subject = '【NEWS】';
$headers[] = 'Content-Type: text/html; charset=UTF-8';
$headers[] = "From: ".$from;
$headers[] = "Sender: ".$from;
$headers[] = "Reply-To: ".$mail_from;
$headers[] = "X-Sender: " . $mail_from;
$headers[] = "X-Priority: 3";
if ($new_status == 'publish' && $old_status != 'publish' && $post->post_type == $active_posttype) {
/** HTML to txt **/
$content = preg_replace('/<br[[:space:]]*\/?[[:space:]]*>/i', "\n", $post->post_content);
$content = strip_tags($content);
$content = html_entity_decode($content);
$content = preg_replace("/\r\n|\r|\n/us", "\n", $content);
$content = preg_replace("/\n[^\S\n]+/us", "\n", $content);
$content = trim(preg_replace("/(\r\n){3,}|\r{3,}|\n{3,}/us", "\n\n", $content));
/**// HTML to txt **/
$message .= $content."\n\n詳しくはこちら↓\n";
$message .= get_permalink($post->ID)."\n\n\n";
$attachments = []; //添付ファイルがあれば
wp_mail($mail_to, $mail_subject, $message, $headers, $attachments);
}
}
add_action('transition_post_status','sendmail_post_article' , 10, 3)
</pre>
<div class="note">
<h5>エラーログを出力してデバック</h5>
<pre class="code">
error_log('$new_status: '.$new_status);
error_log('$post->post_type: '.$post->post_type);
error_log(print_r($post, true ));
</pre>
wp-content/debug.log<br />
に出力される。<br />
エラーログの出力設定は割愛。
</div>
xioheihttp://www.blogger.com/profile/07600365896800702223noreply@blogger.comtag:blogger.com,1999:blog-5561372158145009417.post-35377992663296848672021-12-02T08:20:00.004+09:002021-12-02T08:21:57.318+09:00【PHP】フォームから送信した日本語が文字化け、php.iniの設定が反映されなかった件<h2>mbstringを正しく設定しましょう</h2>
wordpressのContactForm7+Multi-Stepでフォームの確認画面を実装してみたところ文字化け、<br />
もちろん送信されたメールの本文も文字化けし、じゃっかん沼った話。
<h5>php.iniの設定</h5>
<pre class="console">
# vi /etc/php.ini
</pre>
<pre class="code">
mbstring.language = Japanese
mbstring.internal_encoding = UTF-8
mbstring.http_input = UTF-8
mbstring.http_output = UTF-8
<span class="m1">mbstring.encoding_translation = Off</span>
</pre>
<h5>apache、 php-fpmの再起動</h5>
<pre class="code">
# systemctl restart httpd
<span class="m1"># systemctl restart php-fpm</span>
</pre>
phpinfo()で確認。<br />
php-fpmの再起動をしないと反映されないのですね。<br />
古いシステムでなけれUTF-8に統一でmbstring.encoding_translation = Off<br />
って事ですね。
xioheihttp://www.blogger.com/profile/07600365896800702223noreply@blogger.comtag:blogger.com,1999:blog-5561372158145009417.post-8081186388651573502021-11-22T06:19:00.001+09:002021-11-22T06:37:03.417+09:00【Wordpress】ワードプレスの開発環境・テスト環境構築 | サーバー移行手順ワードプレスの開発環境を構築する手順。<br />
サーバー移行する際も同じです。<br />
ローカルに作成したい場合、Windows上であればVMWare等のバーチャルマシーンCentOS上に作ると良いでしょう。
<div class="note">
<ul style="list-style: square;color: #39f;">
<li><a href="/2017/09/vmwarecentos.html">VMware+CentOSで開発環境構築 - 1.インストール</a></li>
<li><a href="/2020/05/centos8-1.html">CentOS8でサーバー構築 - 1.環境設定</a></li>
<li><a href="/2020/05/centos8-2postfixdovecotmta.html">CentOS8でサーバー構築 - 2.Postfix+Dovecot(MTA)</a></li>
<li><a href="/2020/05/centos8-3lampapache24mysql80php74.html">CentOS8でサーバー構築 - 3.LAMP環境構築</a></li>
</ul>
</div>
サーバー移行に必要なものは、<br />
<ul class="em1"><li>Wordpressのファイル(フォルダ)</li><li>データベースのデータ(ダンプファイル)</li></ul>
の2点です。<br />
wp-adminの管理者パスワードがわからない場合は、新たに設定可能です。<br />
開発用なのでBASIC認証などで公開されない形にして、<br />簡単なパスワードに設定し直すのも良いでしょう。
<table>
<tr><th>移行前</th><th>移行後</th></tr>
<tr><td>http://kowloonet.net/</td><td>http://192.168.1.100/wordpress/</td></tr>
</table>
<h4>Wordpressのファイルを本番環境からダウンロード</h4>
サーバーから直接FTP等でダウンロードするのも良いですが、<br />
コマンドが使える環境では、tar.gz に圧縮すると、サーバー間のファイル移動に好都合です。
<h5>フォルダ圧縮</h5>
<pre class="console">
# tar cvzf wordpress.tar.gz wordpress
wordpress/
wordpress/wp-config.php
wordpress/index.php
wordpress/license.txt
wordpress/readme.html
・
・
</pre>
圧縮されたファイル wordpress.tar.gz が生成されますので、<br />
こちらをFTP等でダウンロードします。
<div class="note">
<h5>gzip形式で圧縮</h5>
<pre class="console"> tar cvzf 圧縮後のファイル名.tar.gz ファイル名</pre>
<h5>gzip形式で解凍・展開</h5>
<pre class="console">tar zxvf ファイル名.tar.gz</pre>
<h5>zip形式で圧縮</h5>
<pre class="console">zip 圧縮後のファイル名.zip -r ファイル名</pre>
<h5>zip形式で解凍・展開</h5>
<pre class="console">unzip ファイル名.zip
unzip ファイル名.zip -d 展開先ディレクトリ</pre>
</div>
<h4>データベースのエクスポート</h4>
wordpressで使用しているデータベース名を wp-config.php で確認。<br />
コマンドが使える環境でない場合はmysqladminを利用してください。
<h5>ダンプファイル作成</h5>
<pre class="console">
# mysqldump -uユーザ名 -p wordpress_db > wordpress_db_dump.sql
</pre>
wordpress_db_dump.sql が作成されますので、こちらもFTP等でダウンロード。
<h4>ファイルの展開と設定</h4>
ドキュメントルート /var/www/html/ 直下に展開します。<br />
FTPなどでアップロードして配置してください。
<h5>ファイル展開</h5>
<pre class="console">
# cd /var/www/html/
# tar zxvf wordpress.tar.gz
wordpress/
wordpress/wp-config.php
wordpress/index.php
wordpress/license.txt
・
・
</pre>
<h5>ファイルの所有者変更</h5>
<pre class="console">
# chown -R apache:user wordpress/
</pre>
所有者をapache<br />
グループをuser<br />
にしてuserでもファイルの書き込み変更を行えるようにします。<br />
開発環境なので、パーミッションを<br />
ディレクトリは775<br />
ファイルは664<br />
にしておきます。<br />
<h5>ファイルのパーミッション変更</h5>
<pre class="console">
# find wordpress/ -type d -exec chmod 775 {} \;
# find wordpress/ -type f -exec chmod 664 {} \;
</pre>
<div class="note">
<h5>本番環境では下記のパーミッション変更も追加で実施</h5>
<pre class="console">
# chmod 606 ./wordpress/.htaccess
# chmod 404 ./wordpress/wp-config.php
</pre>
※サーバー移転などでの本番環境のパーミッションはサイトルールに従ってください。
</div>
<h5>パーミッション確認</h5>
<pre class="console">
# cd wordpress/
# ls -la | awk 'NR>1{cmd="stat "$NF" -c %a";cmd|getline c;close(cmd);print c,$0}'
775 drwxrwxr-x 6 apache user 4096 Nov 20 11:53 .
755 drwxr-xr-x 12 user user 4096 Nov 20 11:00 ..
775 drwxrwxr-x 2 apache user 4096 Nov 18 18:24 img
664 -rw-rw-r-- 1 apache user 420 Nov 18 13:10 index.php
664 -rw-rw-r-- 1 apache user 19550 Nov 18 13:09 license.txt
664 -rw-rw-r-- 1 apache user 68 Nov 18 13:10 php.ini
664 -rw-rw-r-- 1 apache user 7447 Nov 18 13:09 readme.html
664 -rw-rw-r-- 1 apache user 6919 Nov 18 13:09 wp-activate.php
775 drwxrwxr-x 9 apache user 4096 Nov 18 18:24 wp-admin
664 -rw-rw-r-- 1 apache user 369 Nov 18 13:09 wp-blog-header.php
664 -rw-rw-r-- 1 apache user 2340 Nov 18 13:09 wp-comments-post.php
664 -rw-rw-r-- 1 apache user 4450 Nov 18 13:09 wp-config.php
664 -rw-rw-r-- 1 apache user 3807 Nov 18 13:09 wp-config-sample.php
775 drwxrwxr-x 8 apache user 4096 Nov 18 18:24 wp-content
664 -rw-rw-r-- 1 apache user 3847 Nov 18 13:09 wp-cron.php
775 drwxrwxr-x 20 apache user 12288 Nov 18 18:24 wp-includes
664 -rw-rw-r-- 1 apache user 2502 Nov 18 13:09 wp-links-opml.php
664 -rw-rw-r-- 1 apache user 3306 Nov 18 13:09 wp-load.php
664 -rw-rw-r-- 1 apache user 39551 Nov 18 13:09 wp-login.php
664 -rw-rw-r-- 1 apache user 8403 Nov 18 13:09 wp-mail.php
664 -rw-rw-r-- 1 apache user 18962 Nov 18 13:09 wp-settings.php
664 -rw-rw-r-- 1 apache user 31085 Nov 18 13:09 wp-signup.php
664 -rw-rw-r-- 1 apache user 4764 Nov 18 13:09 wp-trackback.php
664 -rw-rw-r-- 1 apache user 3068 Nov 18 13:09 xmlrpc.php
</pre>
<h4>データベースの設定</h4>
データベース名、MySQLユーザ名は本番環境と同じである必要はありません。<br />
ご都合に合わせて設定して下さい。今回は、
<table>
<tr><td>デーーベース名</td><td>wordpress_db</td></tr>
<tr><td>MySQLユーザ名</td><td>user</td></tr>
<tr><td>MySQLパスワード</td><td>1234</td></tr>
<tr><td>データベースサーバー</td><td>localhost</td></tr>
</table>
で設定。データベース名以外は本番のものから変更しておきました。
<h5>wp-config.phpの修正</h5>
<pre class="console">
# cd wordpress/
# vi wp-config.php
</pre>
<pre class="code">
/** WordPress のためのデータベース名 */
define('DB_NAME', 'wordpress_db');
/** MySQL データベースのユーザー名 */
define('DB_USER', 'user');
/** MySQL データベースのパスワード */
define('DB_PASSWORD', '1234');
/** MySQL のホスト名 */
#define('DB_HOST', 'mysql.xxxxxxx.com');
define('DB_HOST', 'localhost');
・
・
/**
* WordPress データベーステーブルの接頭辞
*
* それぞれにユニーク (一意) な接頭辞を与えることで一つのデータベースに複数の WordPress を
* インストールすることができます。半角英数字と下線のみを使用してください。
*/
$table_prefix = 'wp369041';
</pre>
vi を使わずにテキストエディタで修正したものを配置しても同じです。
<h5>データベースの作製</h5>
<pre class="console">
# mysql -uuser -p
mysql>CREATE DATABASE wordpress_db;
</pre>
<h5>データベースのインポート</h5>
<pre class="console">
# mysql -uuser -p1234 wordpress_db< wordpress_db_dump.sql
</pre>
コマンドが使えない場合はmysqladminを利用して下さい。<br />今回は、本番URL<br />
http://kowloonet.net/<br />
を<br />
http://192.168.1.100//wordpress/<br />
でアクセスできるように変更します。<br />
サイトURLが記載されている XXXoptions テーブルのカラム option_name の値 home と siteurl のカラム option_value の値を変更します。<br />
XXXは wp-config.phpに記載されている $table_prefix の文字列になります。<br />
テーブル名の変更が無い場合は「wp_」で、テーブル名は「wp_options」になります。<br />
私の環境では「wp369041」でしたので、テーブル名は「wp369041options」になります。
<h5>サイトURL変更</h5>
<pre class="console">
mysql> USE wordpress_db
mysql> SELECT * FROM wp369041options WHERE option_name IN ('home','siteurl');
+-----------+-------------+-------------------------------+----------+
| option_id | option_name | option_value | autoload |
+-----------+-------------+-------------------------------+----------+
| 2 | home | http://kowloonet.net/ | yes |
| 1 | siteurl | http://kowloonet.net/ | yes |
+-----------+-------------+-------------------------------+----------+
2 rows in set (0.00 sec)
mysql> UPDATE wp369041options SET option_value = 'http://192.168.128.100/wordpress/'
where option_name IN ('home','siteurl');
</pre>
本番環境のwp-adminの管理者ユーザのパスワードは長くて複雑な場合が多々あるので、<br />
簡易なものに変更しておきます。<br />
パスワードが不明な場合もこちらの方法で再設定可能です。<br />
管理者ユーザは XXXusers テーブルにあるので、
<h5>管理者ユーザの確認・パスワード変更</h5>
<pre class="console">
mysql> SELECT * FROM wp369041users;
</pre>
で確認。<br />
しかし、これだと管理者が誰かわからないので、「usermeta」テーブルも参照して、
<pre class="console">
mysql> SELECT u.user_login FROM wp369041users u, wp369041usermeta um WHERE u.ID = um.user_id AND um.meta_key LIKE '%capabilities' AND um.meta_value LIKE '%administrator%';
+------------+
| user_login |
+------------+
| admin |
| user |
+------------+
2 rows in set (0.00 sec)
</pre>
ユーザ名「admin」のパスワードを「pass」に変更します。
<h5>パスワード変更</h5>
<pre class="console">
mysql>UPDATE wp369041users SET user_pass = MD5('pass') WHERE user_login = 'admin';
</pre>
必要があれば管理者のメールドレスも変更。
<h5>パスワード変更</h5>
<pre class="console">
mysql> update wp369041users set user_email = 'メールアドレス' WHERE user_login = 'admin';
</pre>
http://192.168.1.100//wordpress/<br />
http://192.168.1.100//wordpress/wp-admin/<br />
にアクセスして表示、動作できればOK。
xioheihttp://www.blogger.com/profile/07600365896800702223noreply@blogger.comtag:blogger.com,1999:blog-5561372158145009417.post-48990541711596709122021-11-13T03:43:00.006+09:002021-11-16T08:44:50.496+09:00Googleマテリアルアイコン - Material icons<h2>Googleマテリアルアイコンの使用例</h2>
<a href="https://fonts.google.com/icons?selected=Material+Icons+Outlined:assignment_returned" target="_blank">Google Material icons</a>
<h5>HTML</h5>
<pre class="console">
<head>
・
<span class="m1"><link rel="stylesheet" href="https://fonts.googleapis.com/icon?family=Material+Icons" /></span>
・
</head>
<body>
・
<div class="search-box">
<input type="text" placeholder="遠征検索" v-model="keyword" class="encolle-global-search" />
</div>
・
</body>
</pre>
※v-model はvue使用時の記述です。
<h5>CSS</h5>
<pre class="console">
.encolle-global-search{
display:inline-block;
width: 300px;
font-size: 1.2rem;
height: 30px;
line-height: 1;
box-sizing: border-box;
padding: 5px 4px 5px 28px;
color: #687c98;
border-radius: 5px;
font-weight: 700;
border: 1px solid #dcdfe6;
transition: border-color .4s cubic-bezier(0.65, 0.05, 0.36, 1);
}
.search-box{
position: relative;
display: inline-block;
}
.search-box::before{
<span class="m1">content: '\e8b6';
font-family: 'Material Icons';</span>
font-size: 24px;
color: #ccc;
font-family: 'Material Icons';
position: absolute;
top: 4px;
left: 4px;
}
</pre>
xioheihttp://www.blogger.com/profile/07600365896800702223noreply@blogger.comtag:blogger.com,1999:blog-5561372158145009417.post-58794801942579915012021-03-14T15:41:00.002+09:002021-03-14T16:00:21.273+09:00LaravelでWEB開発 - PHPのtimezoneが反映されていなかった件Laravel内でのPHPが吐き出す時間がJSTになっていなかったので、php.iniを確認してみたところ正しく設定されていて、Laravelの設定でUTCに変更されていた。
<h2>PHPのtimezone設定</h2>
<h5>php.ini の編集・確認</h5>
<pre class="console">
# vi /etc/php.ini
</pre>
<pre class="code">
[Date]
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
<span class="m1">date.timezone = "Asia/Tokyo"</span>
</pre>
<h5>timezone確認</h5>
<pre class="console">
# php -i | grep timezone
Default timezone => Asia/Tokyo
date.timezone => Asia/Tokyo => Asia/Tokyo
</pre>
<h2>Laravelのtimezone設定</h2>
<h5>app.php 変更</h5>
<pre class="console">
$ vi config/app.php
</pre>
<pre class="code">
/*
|--------------------------------------------------------------------------
| Application Timezone
|--------------------------------------------------------------------------
|
| Here you may specify the default timezone for your application, which
| will be used by the PHP date and date-time functions. We have gone
| ahead and set this to a sensible default for you out of the box.
|
*/
<span class="m1"> 'timezone' => 'Asia/Tokyo',</span>
</pre>
<h5>確認</h5>
<pre class="console">
$ php artisan tinker
Psy Shell v0.10.4 (PHP 7.4.8 ― cli) by Justin Hileman
>>> echo Carbon\Carbon::now();
2021-03-14 15:38:54
</pre>
OK-xioheihttp://www.blogger.com/profile/07600365896800702223noreply@blogger.comtag:blogger.com,1999:blog-5561372158145009417.post-5509207354425941722020-09-11T17:43:00.012+09:002020-09-12T19:14:19.622+09:00CentOS8でサーバー構築 - 12.不正アクセスブロック(fail2ban)<h2>fail2banのインストール</h2>
<h5>インストール</h5>
<pre class="console">
# dnf -y install fail2ban
</pre>
<h2>fail2banの設定</h2>
<h5>設定</h5>
<pre class="console">
# cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
# vi /etc/fail2ban/jail.local
</pre>
<pre class="code">
# "bantime" is the number of seconds that a host is banned.
<span class="m1">bantime = 1d</span>
# A host is banned if it has generated "maxretry" during the last "findtime"
# seconds.
<span class="m1">findtime = 1h</span>
# "maxretry" is the number of failures before a host get banned.
<span class="m1">maxretry = 3</span>
・
・
# Destination email address used solely for the interpolations in
# jail.{conf,local,d/*} configuration files.
<span class="m1">destemail = root</span>
# Sender email address used solely for some actions
<span class="m1">sender = root</span>
# E-mail action. Since 0.8.1 Fail2Ban uses sendmail MTA for the
# mailing. Change mta configuration parameter to mail if you want to
# revert to conventional 'mail'.
<span class="m1">mta = postfix</span>
・
・
#
# Action shortcuts. To be used to define action parameter
# Default banning action (e.g. iptables, iptables-new,
# iptables-multiport, shorewall, etc) It is used to define
# action_* variables. Can be overridden globally or per
# section within jail.local file
#banaction = iptables-multiport
<span class="m1">banaction = firewallcmd-ipset</span>
#banaction_allports = iptables-allports
<span class="m1">banaction_allports = firewallcmd-allports</span>
・
・
#
# SSH servers
#
[sshd]
<span class="m1">enabled = true</span>
・
・
#
# HTTP servers
#
[apache-auth]
<span class="m1">enable = true</span>
・
・
[postfix]
<span class="m1">enabled = true</span>
・
・
[postfix-sasl]
<span class="m1">enabled = true</span>
・
・
# dovecot defaults to logging to the mail syslog facility
# but can be set by syslog_facility in the dovecot configuration.
[dovecot]
<span class="m1">enabled = true</span>
</pre>
<h2>fail2banの起動</h2>
<h5>起動</h5>
<pre class="console">
# systemctl start fail2ban
# systemctl enable fail2ban
</pre>
<h5>設定を変更した時などクライアントリロード</h5>
<pre class="console">
# fail2ban-client reload
</pre>
<h2>fail2banの動作確認</h2>
<h5>sshd</h5>
<pre class="console">
# fail2ban-client status sshd
Status for the jail: sshd
|- Filter
| |- Currently failed: 0
| |- Total failed: 0
| `- Journal matches: _SYSTEMD_UNIT=sshd.service + _COMM=sshd
`- Actions
|- Currently banned: 0
|- Total banned: 0
`- Banned IP list:
</pre>
<h5>postfix-sasl</h5>
<pre class="console">
# fail2ban-client status postfix-sasl
Status for the jail: postfix-sasl
|- Filter
| |- Currently failed: 16
| |- Total failed: 505
| `- Journal matches: _SYSTEMD_UNIT=postfix.service
`- Actions
|- Currently banned: 2
|- Total banned: 2
`- Banned IP list: <BANされたIPアドレス>
</pre>
<h2>その他</h2>
<h5>個別にBAN設定</h5>
<pre class="console">
# fail2ban-client -v set postfix-sasl banip xxx.xxx.xxx.0/24
</pre>
<!-- template
<h2>作成し直し</h2>
<h5>い</h5>
<pre class="console">
# php artisan migrate:reset
$ php artisan migrate
</pre>
<pre class="code">
</pre>
<div class="note">
<h5>い</h5>
<pre class="code">
</pre>
</div>
<span class="m1">う</span>
-->xioheihttp://www.blogger.com/profile/07600365896800702223noreply@blogger.comtag:blogger.com,1999:blog-5561372158145009417.post-89243350649130919092020-08-06T05:54:00.001+09:002020-08-06T05:54:20.817+09:00CentOS8でサーバー構築 - 11.PHPでMemcachedDBへの接続は極力少なくして、キャッシュセッションはMemcachedを使いましょう。<br />
って事でインストール。
<h2>Memcachedのインストール</h2>
<h5>Memcachedインストール</h5>
<pre class="console">
# dnf -y install memcached php-pecl-memcached
milter-manager_repos 347 B/s | 819 B 00:02
milter-manager_repos-source 446 B/s | 819 B 00:01
Dependencies resolved.
=====================================================
Package Architecture Version Repository Size
======================================================
Installing:
memcached x86_64 1.5.9-3.el8 AppStream 132 k
php-pecl-memcached x86_64 3.1.5-1.el8.remi.7.4 remi-modular 96 k
Installing dependencies:
fastlz x86_64 0.1.0-0.12.20070619svnrev12.el8 epel 15 k
libmemcached-libs x86_64 1.0.18-15.el8 AppStream 137 k
php-pecl-igbinary x86_64 3.1.2-1.el8.remi.7.4 remi-modular 158 k
php-pecl-msgpack x86_64 2.1.0-1.el8.remi.7.4 remi-modular 65 k
Transaction Summary
=======================================================
Install 6 Packages
</pre>
epel、remiリポジトリを使用するので、使えるようにしておく事。
<h2>Memcachedの設定</h2>
<h5>Memcached設定</h5>
<pre class="console">
# vi /etc/sysconfig/memcached
</pre>
<pre class="code">
PORT="11211"
USER="memcached"
MAXCONN="512"
CACHESIZE="64"
<span class="m1">OPTIONS="-l 127.0.0.1"</span>
</pre>
<h5>phpのMemcached設定</h5>
<pre class="console">
# vi /etc/php.d/50-memcached.ini
</pre>
<pre class="code">
; Use memcache as a session handler
session.save_handler=memcached
; Defines a comma separated list of server urls to use for session storage
session.save_path="localhost:11211"
</pre>
<pre class="console">
# vi /etc/php.ini
</pre>
<pre class="code">
[Session]
; Handler used to store/retrieve data.
; http://php.net/session.save-handler
<span class="m1">;</span>session.save_handler = files
</pre>
<h5>memcached起動</h5>
<pre class="console">
# systemctl start memcached
# systemctl enable memcached
Created symlink /etc/systemd/system/multi-user.target.wants/memcached.service → /usr/lib/systemd/system/memcached.service.
</pre>
<h5>Apache再起動</h5>
<pre class="console">
# systemctl restart httpd
</pre>
<h2>Firewalledの設定</h2>
<h5>Firewalled設定</h5>
<pre class="console">
# firewall-cmd --add-port=11211/tcp --zone=public --permanent
# firewall-cmd --reload
</pre>
<div class="note">
下記の様なエラーが出て起動できず。
<pre class="console">
OPTIONS="-l 127.0.0.1"
</pre>
と修正して解決。
<pre class="code">
systemctl status memcached
● memcached.service - memcached daemon
Loaded: loaded (/usr/lib/systemd/system/memcached.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Fri 2020-07-17 09:30:49 JST; 2min 21s ago
Process: 446015 ExecStart=/usr/bin/memcached -p ${PORT} -u ${USER} -m ${CACHESIZE} -c ${MAXCONN} $OPTIONS (code=e>
Main PID: 446015 (code=exited, status=71)
Jul 17 09:30:49 kowloonet.net systemd[1]: Started memcached daemon.
Jul 17 09:30:49 kowloonet.net memcached[446015]: bind(): Cannot assign requested address
Jul 17 09:30:49 kowloonet.net memcached[446015]: failed to listen on TCP port 11211: Cannot assign requested address
Jul 17 09:30:49 kowloonet.net systemd[1]: memcached.service: Main process exited, code=exited, status=71/OSERR
Jul 17 09:30:49 kowloonet.net systemd[1]: memcached.service: Failed with result 'exit-code'.
</pre>
</div>xioheihttp://www.blogger.com/profile/07600365896800702223noreply@blogger.comtag:blogger.com,1999:blog-5561372158145009417.post-50967265532322021352020-07-25T16:50:00.004+09:002020-08-07T06:15:55.144+09:00LaravelでWEB開発 - 2.VueとjQueryの共存<script>タグ内で jqueryを importし、 mounted() メソッドに処理を書けばOK。<br />
<h2>Vueのンストール</h2>
<h5>Vueインストール</h5>
<pre class="console">
$ npm install vue
npm notice created a lockfile as package-lock.json. You should commit this file.
+ vue@2.6.11
added 1 package from 1 contributor and audited 1 package in 0.598s
found 0 vulnerabilities
</pre>
<h2>jQueryのインポートと利用</h2>
<h5>.vueファイル修正</h5>
<pre class="console">
$ vi resources/js/components/Sample.vue
</pre>
<table>の <thead>を固定させるスクリプトを jQueryで実装。
<pre class="code">
<template>
<div>
<p v-if="errored">{{ error }}</p>
<p v-if="loading">Loading...</p>
・
・
</div>
</template>
<script>
<span class="m1">import $ from "jquery";</span>
export default{
data() {
return {
loading: true,
errored: false,
error: false,
},
<span class="m1"> mounted() {</span>
$(function () {
var _window = $(window);
$('.area1').css('color','red');
var bottom;
_window.on('scroll',function(){
bottom = $('.vgt-global-search').height() + 50 + $('header').height();
if(_window.scrollTop() > bottom){
$('thead').css('position','fixed').css('top','0');
}
else{
$('thead').css('position','static');
}
});
_window.trigger('scroll');
});
}
};
</script>
</pre>
<!-- template
<h2>作成し直し</h2>
<h5>い</h5>
<pre class="console">
</pre>
<pre class="code">
</pre>
<div class="note">
<h5>い</h5>
<pre class="code">
</pre>
</div>
<span class="m1">う</span>
-->
xioheihttp://www.blogger.com/profile/07600365896800702223noreply@blogger.comtag:blogger.com,1999:blog-5561372158145009417.post-3696340337874683302020-07-16T11:00:00.000+09:002020-07-16T16:10:54.570+09:00CentOS8でサーバー構築 - 10.ApacheのDoS攻撃対策(mod_evasive)<h2>mod_evasiveのインストール</h2>
2020/07/15現在、オフィシャルの CentOS8用のリポジトリに rpmは存在しないので、<br />
同じカーネルの Fedora29のアーカイブページの rpmからネットワーク経由でインストールする。
<h5>Linuxカーネルを確認</h5>
<pre class="console">
# rpm -q kernel
kernel-4.18.0-147.3.1.el8_1.x86_64
kernel-4.18.0-147.8.1.el8_1.x86_64
kernel-4.18.0-193.6.3.el8_2.x86_64
</pre>
4.18なので、Fedora29(kernel4.18)のrpmでインストールする。<br />
<h5>インストール</h5>
<pre class="console">
# rpm -ivh https://archives.fedoraproject.org/pub/archive/fedora/linux/updates/29/Everything/x86_64/Packages/m/mod_evasive-1.10.1-31.fc29.x86_64.rpm
</pre>
<h5>インストール確認</h5>
<pre class="console">
# httpd -M | grep evasive
evasive20_module (shared)
</pre>
<h2>mod_evasiveの設定</h2>
<h5>mod_evasive.conf設定</h5>
<pre class="console">
# vi /etc/httpd/conf.d/mod_evasive.conf
</pre>
<pre class="code">
# mod_evasive configuration
LoadModule evasive20_module modules/mod_evasive24.so
<IfModule mod_evasive24.c>
# The hash table size defines the number of top-level nodes for each
# child's hash table. Increasing this number will provide faster
# performance by decreasing the number of iterations required to get to the
# record, but consume more memory for table space. You should increase
# this if you have a busy web server. The value you specify will
# automatically be tiered up to the next prime number in the primes list
# (see mod_evasive.c for a list of primes used).
<span class="m1">DOSHashTableSize 3097</span>
# This is the threshhold for the number of requests for the same page (or
# URI) per page interval. Once the threshhold for that interval has been
# exceeded, the IP address of the client will be added to the blocking
# list.
<span class="m1">DOSPageCount 10</span>
# This is the threshhold for the total number of requests for any object by
# the same client on the same listener per site interval. Once the
# threshhold for that interval has been exceeded, the IP address of the
# client will be added to the blocking list.
<span class="m1">DOSSiteCount 5</span>
# The interval for the page count threshhold; defaults to 1 second
# intervals.
<span class="m1">DOSPageInterval 2</span>
# The interval for the site count threshhold; defaults to 1 second
# intervals.
<span class="m1">DOSSiteInterval 1</span>
# The blocking period is the amount of time (in seconds) that a client will
# be blocked for if they are added to the blocking list. During this time,
# all subsequent requests from the client will result in a 403 (Forbidden)
# and the timer being reset (e.g. another 10 seconds). Since the timer is
# reset for every subsequent request, it is not necessary to have a long
# blocking period; in the event of a DoS attack, this timer will keep
# getting reset.
<span class="m1">DOSBlockingPeriod 60</span>
# If this value is set, an email will be sent to the address specified
# whenever an IP address becomes blacklisted. A locking mechanism using
# /tmp prevents continuous emails from being sent.
#
# NOTE: Requires /bin/mail (provided by mailx)
<span class="m1">DOSEmailNotify "-s '[mod_evasive] Alert' メールアドレス"</span>
# If this value is set, the system command specified will be executed
# whenever an IP address becomes blacklisted. This is designed to enable
# system calls to ip filter or other tools. A locking mechanism using /tmp
# prevents continuous system calls. Use %s to denote the IP address of the
# blacklisted IP.
#DOSSystemCommand "su - someuser -c '/sbin/... %s ...'"
# Choose an alternative temp directory By default "/tmp" will be used for
# locking mechanism, which opens some security issues if your system is
# open to shell users.
#
#
# http://security.lss.hr/index.php?page=details&ID=LSS-2005-01-01
#
# In the event you have nonprivileged shell users, you'll want to create a
# directory writable only to the user Apache is running as (usually root),
# then set this in your httpd.conf.
<span class="m1">DOSLogDir "/var/lock/mod_evasive"</span>
# You can use whitelists to disable the module for certain ranges of
# IPs. Wildcards can be used on up to the last 3 octets if necessary.
# Multiple DOSWhitelist commands may be used in the configuration.
#DOSWhitelist 127.0.0.1
#DOSWhitelist 192.168.0.*
</IfModule>
</pre>
同じページに DOSPageInterval 秒に DOSPageCount 回のアクセスがあったらブラックリストへ。<br />
同じサイトに DOSSiteInterval 秒に DOSSiteCount 回のアクセスがあったらブラックリストへ。<br />
ブラックリストに登録された IPからは DOSBlockingPeriod 秒間 403を返す。
<h5>ロックファイル格納ディレクトリ作成</h5>
<pre class="console">
# mkdir /var/lock/mod_evasive
# chmod 777 /var/lock/mod_evasive
</pre>
<h5>Apache再起動</h5>
<pre class="console">
# httpd -t
Syntax OK
# systemctl restart httpd
</pre>
<h2>テストプログラムの実行</h2>
そのままでは BadRequest 400 が返ってくるので、test.plを修正。<br />
<span class="notem">私はPHPよりPerl歴の方が長いです・</span>
<h5>test.pl修正</h5>
<pre class="console">
# vi /usr/share/doc/mod_evasive/test.pl
</pre>
<pre class="code">
print $SOCKET "GET /?$_ HTTP/1.0\r\n\r\n";
</pre>
<h5>テスト実行</h5>
<pre class="console">
# perl /usr/share/doc/mod_evasive/test.pl
?
?
</pre>
Apacheの設定や環境によってはうまくいかないかもしれません。<br />
そんな時はブラウザでF5連打で試しましょう。<br />
成功すると、設定したアドレス宛に<br clear="all" />
<div style="display:inline-block;background-color:#fff;color:#333;margin:10px 50px;padding: 5px 10px;border:2px solid #999;line-height: 1.2em;font-size:10pt">
To: -s '[mod_evasive] Alert' メールアドレス<br />
Subject: HTTP BLACKLIST xxx.xxx.xxx.xxx<br />
<br />
mod_evasive HTTP Blacklisted xxx.xxx.xxx.xxx
</div><br clear="all" />
とメールが届きます。
<!-- template
<h2>作成し直し</h2>
<h5>い</h5>
<pre class="console">
</pre>
<pre class="code">
</pre>
<div class="note">
<h5>い</h5>
<pre class="code">
</pre>
</div>
<span class="m1">う</span>
-->xioheihttp://www.blogger.com/profile/07600365896800702223noreply@blogger.comtag:blogger.com,1999:blog-5561372158145009417.post-54930736796692506562020-07-09T23:05:00.000+09:002020-07-10T01:01:39.540+09:00CentOS8でサーバー構築 - 9.mailmanのインストールと設定(Postfix)<table>
<tr><td>メールホスト</td><td>kowloonet.net</td></tr>
<tr><td>URLホスト</td><td>admin.kowloonet.net</td></tr>
<tr><td>URL</td><td>https://admin.kowloonet.net/mailman/admin/</td></tr>
</table>
で設定します。
<h2>mailmanのインストール</h2>
<h5>mailmanインストール</h5>
<pre class="console">
# dnf -y install mailman
</pre>
<h2>mailmanの設定</h2>
<h5>mm_cfg.pyの編集</h5>
<pre class="console">
# vi /etc/mailman/mm_cfg.py
</pre>
<pre class="code">
DEFAULT_URL_HOST = 'kowloonet.net'
DEFAULT_EMAIL_HOST = 'kowloonet.net'
</pre>
<h5>Defaults.pyの編集</h5>
<pre class="console">
# vi /usr/lib/mailman/Mailman/Defaults.py
</pre>
<pre class="code">
# Mailman needs to know about (at least) two fully-qualified domain names
# (fqdn); 1) the hostname used in your urls, and 2) the hostname used in email
# addresses for your domain. For example, if people visit your Mailman system
# with "http://www.dom.ain/mailman" then your url fqdn is "www.dom.ain", and
# if people send mail to your system via "yourlist@dom.ain" then your email
# fqdn is "dom.ain". DEFAULT_URL_HOST controls the former, and
# DEFAULT_EMAIL_HOST controls the latter. Mailman also needs to know how to
# map from one to the other (this is especially important if you're running
# with virtual domains). You use "add_virtualhost(urlfqdn, emailfqdn)" to add
# new mappings.
#
# If you don't need to change DEFAULT_EMAIL_HOST and DEFAULT_URL_HOST in your
# mm_cfg.py, then you're done; the default mapping is added automatically. If
# however you change either variable in your mm_cfg.py, then be sure to also
# include the following:
#
# add_virtualhost(DEFAULT_URL_HOST, DEFAULT_EMAIL_HOST)
#
# because otherwise the default mappings won't be correct.
<span class="m1">DEFAULT_EMAIL_HOST = 'kowloonet.net'
DEFAULT_URL_HOST = 'admin.kowloonet.net'
DEFAULT_URL_PATTERN = 'https://%s/mailman/'</span>
# MTA -- but then also see POSTFIX_STYLE_VIRTUAL_DOMAINS.
<span class="m1">MTA = 'Postfix'</span>
・
・
# The default language for this server. Whenever we can't figure out the list
# context or user context, we'll fall back to using this language. See
# LC_DESCRIPTIONS below for legal values.
<span class="m1">DEFAULT_SERVER_LANGUAGE = 'ja'</span>
・
・
# Set this variable to Yes to allow list owners to delete their own mailing
# lists. You may not want to give them this power, in which case, setting
# this variable to No instead requires list removal to be done by the site
# administrator, via the command line script bin/rmlist.
<span class="m1">OWNERS_CAN_DELETE_THEIR_OWN_LISTS = Yes</span>
・
・
# These format strings will be expanded w.r.t. the dictionary for the
# mailing list instance.
<span class="m1">DEFAULT_SUBJECT_PREFIX = "[%(real_name)s: %%d] "</span>
# What should happen to non-member posts which are do not match explicit
# non-member actions?
# 0 = Accept
# 1 = Hold
# 2 = Reject
# 3 = Discard
<span class="m1">DEFAULT_GENERIC_NONMEMBER_ACTION = 0</span>
・
・
# Mailman can be configured to "munge" Reply-To: headers for any passing
# messages. One the one hand, there are a lot of good reasons not to munge
# Reply-To: but on the other, people really seem to want this feature. See
# the help for reply_goes_to_list in the web UI for links discussing the
# issue.
# 0 - Reply-To: not munged
# 1 - Reply-To: set back to the list
# 2 - Reply-To: set to an explicit value (reply_to_address)
<span class="m1">DEFAULT_REPLY_GOES_TO_LIST = 0</span>
・
・
# SUBSCRIBE POLICY
# 0 - open list (only when ALLOW_OPEN_SUBSCRIBE is set to 1) **
# 1 - confirmation required for subscribes
# 2 - admin approval required for subscribes
# 3 - both confirmation and admin approval required
#
# ** please do not choose option 0 if you are not allowing open
# subscribes (next variable)
<span class="m1">DEFAULT_SUBSCRIBE_POLICY = 2</span>
・
・
Are archives on or off by default?
<span class="m1">DEFAULT_ARCHIVE = Off</span>
・
・
# Will list be available in digested form?
<span class="m1">DEFAULT_DIGESTABLE = No</span>
</pre>
<h5>エイリアス作成</h5>
<pre class="console">
# /usr/lib/mailman/bin/genaliases
</pre>
<h5>管理者パスワード作成</h5>
<pre class="console">
# /usr/lib/mailman/bin/mmsitepass
</pre>
<h5>管理用メーリングリスト作成</h5>
<pre class="console">
# /usr/lib/mailman/bin/newlist mailman
Enter the email of the person running the list: example@example.com
Initial mailman password:
Hit enter to notify mailman owner...
</pre>
<h5>パーミッション修正</h5>
<pre class="console">
# /usr/lib/mailman/bin/check_perms -f
/etc/mailman/aliases bad group (has: root, expected mailman) (fixing)
/etc/mailman/adm.pw bad group (has: root, expected mailman) (fixing)
/usr/lib/mailman/Mailman/Defaults.pyc bad group (has: root, expected mailman) (fixing)
/usr/lib/mailman/Mailman/mm_cfg.pyc bad group (has: root, expected mailman) (fixing)
/var/log/mailman/error bad group (has: root, expected mailman) (fixing)
Problems found: 5
Re-run as mailman (or root) with -f flag to fix
# chown apache /etc/mailman/aliases
# chmod 664 /etc/mailman/aliases*
# chmod 2775 /etc/mailman
</pre>
<h5>パーミッション修正確認</h5>
<pre class="console">
# /usr/lib/mailman/bin/check_perms
No problems found
</pre>
<h5>mailman起動と自動起動設定</h5>
<pre class="console">
# systemctl enable --now mailman
</pre>
<div class="note">
<pre class="console">
# /usr/lib/mailman/bin/newlist mailman
Enter the email of the person running the list: example@example.com
Initial mailman password:
postalias: fatal: open /etc/mailman/aliases.db: Permission denied
Traceback (most recent call last):
File "/usr/lib/mailman/bin/newlist", line 274, in <module>
main()
File "/usr/lib/mailman/bin/newlist", line 240, in main
sys.modules[modname].create(mlist)
File "/usr/lib/mailman/Mailman/MTA/Postfix.py", line 342, in create
_update_maps()
File "/usr/lib/mailman/Mailman/MTA/Postfix.py", line 78, in _update_maps
raise RuntimeError, msg % (acmd, status, errstr)
RuntimeError: command failed: /usr/sbin/postalias /etc/mailman/aliases (status: 1, Operation not permitted)
</pre>
などとエラーが出た場合は。
<pre class="console">
# /usr/lib/mailman/bin/check_perms -f
</pre>
を実行してパーミッションを修正する。
</div>
<div class="note">
<h5>管理者パスワードの変更</h5>
<pre class="console">
/usr/lib/mailman/bin/mmsitepass
</pre>
<h5>メーリングリストの削除</h5>
<pre class="console">
# /usr/lib/mailman/bin/rmlist メーリングリスト名
</pre>
</div>
<h2>Postfixの設定</h2>
<h5>mailman起動とサービス追加</h5>
<pre class="console">
# vi /etc/postfix/main.cf
</pre>
<pre class="code">
#alias_maps = dbm:/etc/aliases
<span class="m1">#</span>alias_maps = hash:/etc/aliases
#alias_maps = hash:/etc/aliases, nis:mail.aliases
#alias_maps = netinfo:/aliases
<span class="m1">alias_maps = hash:/etc/aliases, hash:/etc/mailman/aliases</span>
・
・
#alias_database = dbm:/etc/aliases
#alias_database = dbm:/etc/mail/aliases
<span class="m1">#</span>alias_database = hash:/etc/aliases
#alias_database = hash:/etc/aliases, hash:/opt/majordomo/aliases
<span class="m1">alias_database = hash:/etc/aliases, hash:/etc/mailman/aliases</span>
</pre>
<h5>postfix再起動</h5>
<pre class="console">
# systemctl restart postfix
</pre>
<h2>Apacheの設定</h2>
mailman.confや他の .confを状況に応じて修正後Apache再起動
<h5>mailman.conf</h5>
<pre class="console">
# cd /etc/httpd/conf.d/
# cp mailman.conf mailman.conf.org
# vi mailman.conf
</pre>
<h5>Apache再起動</h5>
<pre class="console">
# httpd -t
Syntax OK
# systemctl restart httpd
</pre>
<h2>ブラウザでアクセス</h2>
https://ホスト名/mailman/admin/<br />
にアクセス。
<div class="image">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXgAF0dKMNOd597t4F1Hr-QHQ27RhBkD5LRkPXlGfYQL_VCe08wj6cIpgAnc9u8XZnUrAOweEB-kRC5WRZhbuIz2LrHm6VD1HYv3YXO1bL3T6PRYH9O5-elOzg_hG3wyoD8CVuCOqPX7fX/s1600/mailman.png" imageanchor="1" ><img border="0" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgXgAF0dKMNOd597t4F1Hr-QHQ27RhBkD5LRkPXlGfYQL_VCe08wj6cIpgAnc9u8XZnUrAOweEB-kRC5WRZhbuIz2LrHm6VD1HYv3YXO1bL3T6PRYH9O5-elOzg_hG3wyoD8CVuCOqPX7fX/s1600/mailman.png" data-original-width="744" data-original-height="343" /></a>
</div>xioheihttp://www.blogger.com/profile/07600365896800702223noreply@blogger.comtag:blogger.com,1999:blog-5561372158145009417.post-64463647983753555872020-06-25T10:10:00.001+09:002020-06-25T12:48:52.061+09:00【CentOS8】クローラ拒否設定(robots.txt .htaccess)DocumentRoot /var/www/dev の場合
<h2>robots.txtでクローラ拒否</h2>
<pre class="console">
# vi /var/www/dev/robots.txt
</pre>
<pre class="code">
User-Agent:*
Disallow:/
</pre>
<h2>.htaccessでクローラ拒否</h2>
httpd.conf に記述してもOK。
<pre class="console">
# vi /var/www/dev/.htaccess
</pre>
<pre class="code">
SetEnvIf User-Agent "Googlebot" ng_ua
SetEnvIf User-Agent "bingbot" ng_ua
order Allow,Deny
Allow from all
Deny from env=ng_ua
</pre>xioheihttp://www.blogger.com/profile/07600365896800702223noreply@blogger.comtag:blogger.com,1999:blog-5561372158145009417.post-25436731947476699202020-06-24T10:20:00.000+09:002020-06-24T10:30:56.338+09:00【CentOS8】Ruby2.7.1のインストールdnfでもRubyはインストールできますが、2.5.5とバージョンが古いので、<br />
rbenvを使って最新のRuby2.7.1をインストールします。
<div class="note">
<pre class="console">
# dnf list avialable ruby
milter-manager_repos 406 B/s | 819 B 00:02
milter-manager_repos-source 400 B/s | 819 B 00:02
Available Packages
ruby.i686 2.5.5-105.module_el8.1.0+214+9be47fd7 AppStream
ruby.x86_64 2.5.5-105.module_el8.1.0+214+9be47fd7 AppStream
</pre>
</div>
<h4>rbenvのインストール</h4>
CentOS8インストール時におおよそのもの、git、openssl-develなどはデフォルトで入っています。<br />
こちらの環境で必要なものは readline-devel、nodejsでした。
<h5>必要なパッケージインストール</h5>
<pre class="console">
# yum -y install readline-devel nodejs
</pre>
<div class="note">
epelリポジトリが追加されていない場合は追加。
<h5>epelリポジトリの追加</h5>
<pre class="console"># dnf -y install epel-release
</pre>
</div>
<h5>rbenvをダウンロード</h5>
<pre class="console">
# git clone https://github.com/rbenv/rbenv.git ~/.rbenv
</pre>
<h5>Pathなどを追加</h5>
<pre class="console">
# echo 'export PATH="~/.rbenv/bin:$PATH"' >> ~/.bash_profile
# echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
# source ~/.bash_profile
</pre>
<div class="note">
rbenv intすると、下記のメッセージが。
<pre class="console">
# Load rbenv automatically by appending
# the following to ~/.bash_profile:
eval "$(rbenv init -)"
</pre>
手動でやるな、自動でやれと。
</div>
<h5>rbenvバージョン確認</h5>
<pre class="console">
# rbenv -v
rbenv 1.1.2-30-gc879cb0
</pre>
<h4>Rubyのインストール</h4>
<h5>Ruby最新バージョン確認</h5>
<pre class="console">
# rbenv install --list
2.5.8
2.6.6
2.7.1
jruby-9.2.11.1
maglev-1.0.0
mruby-2.1.1
rbx-5.0
truffleruby-20.1.0
Only latest stable releases for each Ruby implementation are shown.
Use 'rbenv install --list-all' to show all local versions.
</pre>
<h5>Rubyインストール</h5>
<pre class="console">
# rbenv install 2.7.1
</pre>
<h5>使用するRubyのバージョン指定</h5>
<pre class="console">
# rbenv global 2.7.1
# rbenv rehash
</pre>
<div class="note">
rbenvでバージョンを指定してやらないと下記のメッセージ。
<pre class="console">
# ruby -v
rbenv: ruby: command not found
The `ruby' command exists in these Ruby versions:
2.7.1
</pre>
</div>
<h5>Rubyバージョン確認</h5>
<pre class="console">
# ruby -v
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-linux]
</pre>
xioheihttp://www.blogger.com/profile/07600365896800702223noreply@blogger.comtag:blogger.com,1999:blog-5561372158145009417.post-41588482036825885172020-06-23T11:11:00.000+09:002020-06-23T11:11:55.780+09:00【CentOS8】glib2.6インストール時に [meson.build:1814:2: ERROR: Dependency "mount" not found, tried pkgconfig]<pre class="console">
# cd glib-2.60.7
# meson _build
・
・
Dependency mount found: NO (tried pkgconfig)
meson.build:1814:2: ERROR: Dependency "mount" not found, tried pkgconfig
</pre>
libmount-devel をインストールする事で解決。
<pre class="console">
# dnf -y install libmount-devel
</pre>xioheihttp://www.blogger.com/profile/07600365896800702223noreply@blogger.comtag:blogger.com,1999:blog-5561372158145009417.post-70541272421696896762020-06-22T13:13:00.000+09:002020-06-30T17:13:25.018+09:00CentOS8でサーバー構築 - 8.ファイアーウォール(Firewalld)以前は iptablesで管理していましたが、CentOS7以降デフォルトで<br />
Firewalldが使われることになったので、こちらを使う。<br />
zoneは publicのみ設定します。
<h4>Firewalldの起動</h4>
<h5>現在起動していているか確認</h5>
<pre class="console">
# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)
</pre>
既にインストールされていているが起動していない。
<h5>firewall-cmdでも確認できる</h5>
<pre class="console">
# firewall-cmd --state
not running
</pre>
<h5>パッケージが最新か確認</h5>
<pre class="console">
# dnf list firewalld
CentOS-8 - AppStream 448 kB/s | 4.3 kB 00:00
CentOS-8 - Base 87 kB/s | 3.9 kB 00:00
CentOS-8 - Extras 169 kB/s | 1.5 kB 00:00
CentOS-8 - PowerTools 21 kB/s | 4.3 kB 00:00
Extra Packages for Enterprise Linux Modular 8 - x86_64 15 kB/s | 8.1 kB 00:00
Extra Packages for Enterprise Linux 8 - x86_64 10 kB/s | 7.9 kB 00:00
Remi's Modular repository for Enterprise Linux 8 - x86_64 3.5 kB/s | 3.5 kB 00:00
Safe Remi's RPM repository for Enterprise Linux 8 - x86_6 3.1 kB/s | 3.0 kB 00:00
Installed Packages
firewalld.noarch 0.7.0-5.el8_1.1 @BaseOS
Available Packages
firewalld.noarch 0.8.0-4.el8 BaseOS
</pre>
0.8が使えるようなのでupdate。dnfではupdateも使えるがupgradeが正しいオプション。
<h5>アップグレード</h5>
<pre class="console">
# dnf -y upgrade firewalld
</pre>
<h5>起動</h5>
<pre class="console">
# systemctl start firewalld
</pre>
起動したとたん、SSHの接続が切られました。事によってはデータセンターに行くパターンです。
<h5>設定サービスの確認</h5>
<pre class="console">
# firewall-cmd --zone=public --list-services
cockpit dhcpv6-client ssh
</pre>
IPv6は使う予定が無いので dhcpv6-clientの通信を停止しておきます。
<h5>dhcpv6-client停止</h5>
<pre class="console">
# firewall-cmd --permanent --remove-service=dhcpv6-client
success
# firewall-cmd --reload
</pre>
見慣れないcockpitはCentOS8の操作をWEB上からできるとか。<br />
セキュリティ面を考慮しないとすぐには利用したくないので、こちらも一旦停止しておきます。
<h5>cockpit停止</h5>
<pre class="console">
# firewall-cmd --permanent --remove-service=cockpit
success
# firewall-cmd --reload
success
</pre>
<h5>http https追加</h5>
<pre class="console">
# firewall-cmd --permanent --add-service=http
success
# firewall-cmd --permanent --add-service=https
success
# firewall-cmd --reload
success
</pre>
<h5>確認</h5>
<pre class="console">
# firewall-cmd --zone=public --list-services
http https ssh
</pre>
<div class="note">
cockpitはデフォルトでインストールされていました。
<pre class="console">
# dnf list installed |grep cockpit
cockpit.x86_64 196.3-1.el8 @BaseOS
cockpit-bridge.x86_64 196.3-1.el8 @BaseOS
cockpit-packagekit.noarch 197.3-1.el8 @AppStream
cockpit-system.noarch 196.3-1.el8 @BaseOS
cockpit-ws.x86_64 196.3-1.el8 @BaseOS
</pre>
</div>
<h4 id="mail">メール関連のサービス追加</h4>
必要に応じて、smtp, smtps, pop3, pop3s, imap, imapsを追加。
<pre class="console">
# firewall-cmd --permanent --add-service=smtp
success
# firewall-cmd --permanent --add-service=smtps
success
# firewall-cmd --permanent --add-service=pop3
success
# firewall-cmd --permanent --add-service=pop3s
success
# firewall-cmd --reload
success
</pre>
<h4>SSHのポートを変更対応</h4>
SSHのPortを12345に変更。
<h5>ssh.xmlコピー</h5>
<pre class="console">
# cp /usr/lib/firewalld/services/ssh.xml /etc/firewalld/services/ssh.xml
</pre>
<h5>ssh.xm編集</h5>
<pre class="console">
# vi /etc/firewalld/services/ssh.xml
<pre class="code2">
<?xml version="1.0" encoding="utf-8"?>
<service>
<short>SSH</short>
<description>Secure Shell (SSH) is a protocol for logging into and executing commands on remote machines. It provides secure encrypted communications. If you plan on accessing your machine remotely via SSH over a firewalled interface, enable this option. You need the openssh-server package installed for this option to be useful.</description>
<port protocol="tcp" port="<span class-"m1">12345</span>"/>
</service>
</pre></pre>
<h5>設定反映</h5>
<pre class="console">
# firewall-cmd --reload
success
</pre>
<h4 id="ftp">FTPのポートを変更対応</h4>
FTPのPortを12345に変更。<br />
PASV_PORT: 60100-60100
<h5>ftp.xmlコピー</h5>
<pre class="console">
# cp /usr/lib/firewalld/services/ftp.xml /etc/firewalld/services/ftp.xml
</pre>
<h5>ftp.xml編集</h5>
<pre class="console">
# vi /etc/firewalld/services/ftp.xml
<pre class="code2">
?xml version="1.0" encoding="utf-8"?>
<service>
<short>FTP</short>
<description>FTP is a protocol used for remote file transfer. If you plan to make your FTP server publicly available, enable this option. You need the vsftpd package installed for this option to be useful.</description>
<port protocol="tcp" port="<span class-"m1">12345</span>"/>
<helper name="ftp"/>
</service>
</pre></pre>
<h5>追加されていない場合はftp追加</h5>
<pre class="console">
# firewall-cmd --permanent --add-service=ftp
success
</pre>
<h5>PASVポート追加</h5>
<pre class="console">
# firewall-cmd --zone=public --permanent --add-port=60000-60100/tcp
success
</pre>
<h5>設定反映</h5>
<pre class="console">
# firewall-cmd --reload
success
</pre>
<h5>確認</h5>
<pre class="console">
# firewall-cmd --list-ports
60000-60100/tcp
</pre>
<h4>コマンドまとめ</h4>
<h5>起動の確認</h5>
<pre class="console">
firewall-cmd --state
</pre>
<h5>設定の確認</h5>
<pre class="console">
firewall-cmd --list-all
firewall-cmd --get-active-zone
firewall-cmd --zone=public --list-services
firewall-cmd --list-ports
</pre>
<h5>サービスの追加</h5>
<pre class="console">
firewall-cmd --permanent --add-service=ftp
</pre>
<h5>サービスの削除</h5>
<pre class="console">
firewall-cmd --permanent --remove-service=ftp
</pre>
<h5>設定反映</h5>
<pre class="console">
firewall-cmd --reload
</pre>
<h5>特定のIPを拒否</h5>
<pre class="console">
firewall-cmd --zone=drop --permanent --add-source=46.38.148.0/22
</pre>
<div class="note">
<h5>lsofコマンドで現在使っているポートを確認</h5>
<pre class="console">
# lsof -i -nP
・
・
httpd 4176 apache 3u IPv4 24324 0t0 TCP *:80 (LISTEN)
dovecot 8231 root 23u IPv4 463784 0t0 TCP *:110 (LISTEN)
dovecot 8231 root 24u IPv6 463785 0t0 TCP *:110 (LISTEN)
dovecot 8231 root 25u IPv4 463786 0t0 TCP *:995 (LISTEN)
dovecot 8231 root 26u IPv6 463787 0t0 TCP *:995 (LISTEN)
dovecot 8231 root 41u IPv4 463832 0t0 TCP *:143 (LISTEN)
dovecot 8231 root 42u IPv6 463833 0t0 TCP *:143 (LISTEN)
dovecot 8231 root 43u IPv4 463834 0t0 TCP *:993 (LISTEN)
dovecot 8231 root 44u IPv6 463835 0t0 TCP *:993 (LISTEN)
master 8346 root 16u IPv4 467529 0t0 TCP *:25 (LISTEN)
master 8346 root 20u IPv4 467532 0t0 TCP *:465 (LISTEN)
・
・
</pre>
</div>xioheihttp://www.blogger.com/profile/07600365896800702223noreply@blogger.comtag:blogger.com,1999:blog-5561372158145009417.post-37407194750154934382020-06-22T12:46:00.001+09:002022-04-01T09:25:05.911+09:00CentOS8でサーバー構築 - 7.Postfix3.3+Dovecot2.3の暗号化設定(SSL/TLS)以前、<a href="/2020/05/centos8-2postfixdovecotmta.html">CentOS8でサーバー構築 - 2.Postfix+Dovecot(MTA)</a>で、Gmail経由でメールを送受信できるところまで設定しました。<br />
今回は、暗号化してSMTPS Port465、POP3S Port995でメールの送受信をできるようにします。<br />
Portはルーター、firewalld、パケットフィルタリング、などは開けておくこと。<br />
使用するホスト名:mail.kowloonet.net
<h4>Let's Encryptで証明書取得</h4>
無料でアラートが出ないSSLを使えるようになったなんて、便利になったもんです。。<br />
ここでは <span class="em2">Let's Encrypt</span> でTLS暗号化します。
<h5>certbotをdnfでインストールできるか確認</h5>
<pre class="console">
# dnf info certbot
Last metadata expiration check: 0:03:12 ago on Sun 14 Jun 2020 10:52:38 AM JST.
Available Packages
Name : certbot
Version : 1.4.0
Release : 1.el8
Architecture : noarch
Size : 46 k
Source : certbot-1.4.0-1.el8.src.rpm
Repository : epel
Summary : A free, automated certificate authority client
URL : https://pypi.python.org/pypi/certbot
License : ASL 2.0
Description : certbot is a free, automated certificate authority that aims
: to lower the barriers to entry for encrypting all HTTP traffic on the
: internet.
</pre>
<div class="note">
epelリポジトリをインストールしていない場合はインストールする。
<h5>epelリポジトリ追加・インストール</h5>
<pre class="console"># dnf -y install epel-release</pre>
</div>
<h5>certbotインストール</h5>
<pre class="console">
# dnf install cerbot
</pre>
certbot用に使用するホスト名 mail.kowloonet.netで外部から接続できるようにする。<br />
certbot実行時に使用するホスト名がhttpやhttpsで正しく接続できるかを確認しに行きます。<br />
使用するホスト名はDNSレコードに追加しておくこと。<br />
Webサーバーを公開していない場合のやり方は割愛します。
<h5>Apacheバーチャルホスト設定</h5>
<pre class="console"># vi /etc/httpd/conf.d/virtualhost-kowloonet.net.conf</pre>
<pre class="code">
<VirtualHost *:80>
ServerName kowloonet.net
ServerAlias mail.kowloonet.net
DocumentRoot /var/www/html
</VirtualHost>
</pre>
<h5>Apache再起動</h5>
<pre class="console">
# systemctl restart httpd
</pre>
<h5>certbotで証明書作成</h5>
<pre class="console">
# certbot certonly --webroot -w /var/www/html/ -m メールアドレス -d mail.kowloonet.net --agree-tos
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator webroot, Installer None
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: <span class="m1">N</span> <span class="notem">←初回だけ聞かれる</span>
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator webroot, Installer None
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for mail.kowloonet.net
Using the webroot path /var/www/html for all unmatched domains.
Waiting for verification...
Cleaning up challenges
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/mail.kowloonet.net/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/mail.kowloonet.net/privkey.pem
Your cert will expire on 2020-09-12. To obtain a new or tweaked
version of this certificate in the future, simply run certbot
again. To non-interactively renew *all* of your certificates, run
"certbot renew"
- If you like Certbot, please consider supporting our work by:
Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate
Donating to EFF: https://eff.org/donate-le
</pre>
<h4>Postfixの設定</h4>
Postfixのバージョンは 3.3.1でした。
<h5>Postfixのバージョン確認</h5>
<pre class="console">
# postconf | grep mail_version
mail_version = 3.3.1
milter_macro_v = $mail_name $mail_version
</pre>
<h5>main.cf設定</h5>
<pre class="console">
# vi /etc/postfix/main.cf
</pre>
<pre class="code">
# the server certificate first, then the issuing CA(s) (bottom-up order).
#
<span class="m1">#</span>smtpd_tls_cert_file = /etc/pki/tls/certs/postfix.pem
<span class="m1">smtpd_tls_cert_file = /etc/letsencrypt/live/mail.kowloonet.net/fullchain.pem</span>
・
・
<span class="m1">#</span>smtpd_tls_key_file = /etc/pki/tls/private/postfix.key
<span class="m1">smtpd_tls_key_file = /etc/letsencrypt/live/mail.kowloonet.net/privkey.pem</span>
# Announce STARTTLS support to remote SMTP clients, but do not require that
# clients use TLS encryption (opportunistic TLS inbound).
#
smtpd_tls_security_level = may
・
・
# Use TLS if this is supported by the remote SMTP server, otherwise use
# plaintext (opportunistic TLS outbound).
#
smtp_tls_security_level = may
<span class="m1">tls_high_cipherlist = HIGH:!aNULL:!eNULL:!SSLv2:!SSLv3:!kRSA:!kDHd:!EXPORT:!ADH:!DSS:!PSK:!SRP:!RC4:!MD5:!DES:!3DES:!EXP:!SEED:!IDEA:!3DES:!LOW@STRENGTH
smtp_tls_ciphers = high
smtpd_tls_ciphers = high
smtpd_tls_mandatory_ciphers = high
smtpd_tls_mandatory_protocols=!SSLv2,!SSLv3
smtp_tls_mandatory_protocols=!SSLv2,!SSLv3
smtpd_tls_protocols=!SSLv2,!SSLv3
smtp_tls_protocols=!SSLv2,!SSLv3</span>
</pre>
<h5>master.cfの設定</h5>
<pre class="console">
# vi /etc/postfix/master.cf
</pre>
<pre class="code">
# ======================================
smtp inet n - n - - smtpd
#smtp inet n - n - 1 postscreen
#smtpd pass - - n - - smtpd
#dnsblog unix - - n - 0 dnsblog
#tlsproxy unix - - n - 0 tlsproxy
<span class="m1">#</span>submission inet n - n - - smtpd
# -o syslog_name=postfix/submission
# -o smtpd_tls_security_level=encrypt
<span class="m1">#</span> -o smtpd_sasl_auth_enable=yes
# -o smtpd_tls_auth_only=yes
# -o smtpd_reject_unlisted_recipient=no
# -o smtpd_client_restrictions=$mua_client_restrictions
# -o smtpd_helo_restrictions=$mua_helo_restrictions
# -o smtpd_sender_restrictions=$mua_sender_restrictions
# -o smtpd_recipient_restrictions=
# -o smtpd_relay_restrictions=permit_sasl_authenticated,reject
# -o milter_macro_daemon_name=ORIGINATING
<span class="m1">smtps inet n - n - - smtpd</span>
# -o syslog_name=postfix/smtps
<span class="m1"> -o smtpd_tls_wrappermode=yes
-o smtpd_sasl_auth_enable=yes</span>
# -o smtpd_reject_unlisted_recipient=no
# -o smtpd_client_restrictions=$mua_client_restrictions
# -o smtpd_helo_restrictions=$mua_helo_restrictions
# -o smtpd_sender_restrictions=$mua_sender_restrictions
# -o smtpd_recipient_restrictions=
# -o smtpd_relay_restrictions=permit_sasl_authenticated,reject
# -o milter_macro_daemon_name=ORIGINATING
#628 inet n - n - - qmqpd
pickup unix n - n 60 1 pickup
cleanup unix n - n - 0 cleanup
qmgr unix n - n 300 1 qmgr
#qmgr unix n - n 300 1 oqmgr
<span class="m1">tlsmgr unix - - n 1000? 1 tlsmgr</span>
</pre>
<h5>Postfix再起動</h5>
<pre class="console">
# systemctl restart postfix
</pre>
<h4>Dovecotの設定</h4>
アップグレードしてdovecotのバージョンが2.2から2.3に変わり、設定ファイルが結構変わり以前だったら出なかったWarningが結構出るようになり、
色々mergeするのも面倒だったので、dovecotを一旦removeして再インストールしました。<br />
Dovecotのバージョン2.3.8で対応します。<br />
デフォルトで ssl = required になっていましたq。<br />
アップデートに伴いWarning出た件は下記参照。
<h5>dovecote再インストール</h5>
<pre class="console">
# dnf remove dovecot
# dnf -y install dovecot
</pre>
remove後も設定ファイルは 10-ssl.conf.rpmsave などで残ります。
<h5>dovecotのバージョン確認</h5>
<pre class="console"># dovecot --version
2.3.8 (9df20d2db)
</pre>
<h5>10-mail.conf設定</h5>
<pre class="console">
# vi /etc/dovecot/conf.d/10-mail.conf
</pre>
<pre class="code">
# <doc/wiki/MailLocation.txt>
#
<span class="m1">mail_location = maildir:~/Maildir</span>
</pre>
<h5>10-auth.conf設定</h5>
<pre class="console">
# vi /etc/dovecot/conf.d/10-auth.conf
</pre>
<pre class="code">
# See also ssl=required setting.
<span class="m1">disable_plaintext_auth = no</span>
</pre>
<h5>10-ssl.confの設定</h5>
<pre class="console">
# vi /etc/dovecot/conf.d/10-ssl.conf
</pre>
<pre class="code">
# SSL/TLS support: yes, no, required. <doc/wiki/SSL.txt>
# disable plain pop3 and imap, allowed are only pop3+TLS, pop3s, imap+TLS and imaps
# plain imap and pop3 are still allowed for local connections
ssl = required
# PEM encoded X.509 SSL/TLS certificate and private key. They're opened before
# dropping root privileges, so keep the key file unreadable by anyone but
# root. Included doc/mkcert.sh can be used to easily generate self-signed
# certificate, just make sure to update the domains in dovecot-openssl.cnf
<span class="m1">#</span>ssl_cert = </etc/pki/dovecot/certs/dovecot.pem
<span class="m1">#</span>ssl_key = </etc/pki/dovecot/private/dovecot.pem
<span class="m1">ssl_cert = </etc/letsencrypt/live/mail.kowloonet.net/fullchain.pem
ssl_key = </etc/letsencrypt/live/mail.kowloonet.net/privkey.pem</span>
・
・
# SSL DH parameters
# Generate new params with `openssl dhparam -out /etc/dovecot/dh.pem 4096`
# Or migrate from old ssl-parameters.dat file with the command dovecot
# gives on startup when ssl_dh is unset.
<span class="m1">ssl_dh = </etc/dovecot/dh.pem</span>
# Minimum SSL protocol version to use. Potentially recognized values are SSLv3,
# TLSv1, TLSv1.1, and TLSv1.2, depending on the OpenSSL version used.
<span class="m1">ssl_min_protocol = TLSv1.2</span>
# SSL ciphers to use, the default is:
#ssl_cipher_list = ALL:!kRSA:!SRP:!kDHd:!DSS:!aNULL:!eNULL:!EXPORT:!DES:!3DES:!MD5:!PSK:!RC4:!ADH:!LOW@STRENGTH
# To disable non-EC DH, use:
#ssl_cipher_list = ALL:!DH:!kRSA:!SRP:!kDHd:!DSS:!aNULL:!eNULL:!EXPORT:!DES:!3DES:!MD5:!PSK:!RC4:!ADH:!LOW@STRENGTH
<span class="m1">#</span>ssl_cipher_list = PROFILE=SYSTEM
<span class="m1">ssl_cipher_list = HIGH:!aNULL:!eNULL:!SSLv2:!SSLv3:!kRSA:!kDHd:!EXPORT:!ADH:!DSS:!PSK:!SRP:!RC4:!MD5:!DES:!3DES:!EXP:!SEED:!IDEA:!3DES:!LOW@STRENGTH</span>
・
・
# Prefer the server's order of ciphers over client's.
<span class="m1">ssl_prefer_server_ciphers = yes</span>
</pre>
<div class="note">
ssl_prefer_server_ciphers:<br />
このディレクティブを yes に設定すると、接続先のクライアントが指定された暗号化の命令に従います。
</div>
<h5>dh.pemの作製</h5>
OpenSSL 1.1.1c FIPS です。
<pre class="console">
# openssl dhparam 4096 -out /etc/dovecot/dh.pem
</pre>
結構時間かかります。
<div class="note">
v2.2の古いパラメータを使いたい場合は
<pre class="console">
dd if=/var/lib/dovecot/ssl-parameters.dat bs=1 skip=88 | openssl dhparam -inform der > dh.pem
</pre>
と書いてあったので、特に必要ない場合は
<pre class="console">
openssl dhparam 4096 > dh.pem
</pre>
の方が良さげです。
</div>
<h5>dovecot起動設定</h5>
<pre class="console">
# systemctl start dovecot
# systemctl enable dovecot
Created symlink /etc/systemd/system/multi-user.target.wants/dovecot.service → /usr/lib/systemd/system/dovecot.service.
</pre>
<div class="note">
指定するcipherを個別に TLS_AES_256_GCM_SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES128-GCM-SHA256 など指定しても良いです。<br />
こちらを参考にしました<br />
<a href="https://access.redhat.com/documentation/ja-jp/red_hat_enterprise_linux/7/html/security_guide/sec-hardening_tls_configuration" target="_blank">4.13. TLS 設定の強化 Red Hat Enterprise Linux 7 | Red Hat Customer Portal</a>
<h5>推奨事項を満たす暗号化スイートを一覧表示</h5>
<pre class="console">
# openssl ciphers -v 'kEECDH+aECDSA+AES:kEECDH+AES+aRSA:kEDH+aRSA+AES' | column -t
</pre>
<pre class="code">
TLS_AES_256_GCM_SHA384 TLSv1.3 Kx=any Au=any Enc=AESGCM(256) Mac=AEAD
TLS_CHACHA20_POLY1305_SHA256 TLSv1.3 Kx=any Au=any Enc=CHACHA20/POLY1305(256) Mac=AEAD
TLS_AES_128_GCM_SHA256 TLSv1.3 Kx=any Au=any Enc=AESGCM(128) Mac=AEAD
TLS_AES_128_CCM_SHA256 TLSv1.3 Kx=any Au=any Enc=AESCCM(128) Mac=AEAD
ECDHE-ECDSA-AES256-GCM-SHA384 TLSv1.2 Kx=ECDH Au=ECDSA Enc=AESGCM(256) Mac=AEAD
ECDHE-ECDSA-AES256-CCM8 TLSv1.2 Kx=ECDH Au=ECDSA Enc=AESCCM8(256) Mac=AEAD
ECDHE-ECDSA-AES256-CCM TLSv1.2 Kx=ECDH Au=ECDSA Enc=AESCCM(256) Mac=AEAD
ECDHE-ECDSA-AES128-GCM-SHA256 TLSv1.2 Kx=ECDH Au=ECDSA Enc=AESGCM(128) Mac=AEAD
ECDHE-ECDSA-AES128-CCM8 TLSv1.2 Kx=ECDH Au=ECDSA Enc=AESCCM8(128) Mac=AEAD
ECDHE-ECDSA-AES128-CCM TLSv1.2 Kx=ECDH Au=ECDSA Enc=AESCCM(128) Mac=AEAD
ECDHE-ECDSA-AES256-SHA384 TLSv1.2 Kx=ECDH Au=ECDSA Enc=AES(256) Mac=SHA384
ECDHE-ECDSA-AES128-SHA256 TLSv1.2 Kx=ECDH Au=ECDSA Enc=AES(128) Mac=SHA256
ECDHE-ECDSA-AES256-SHA TLSv1 Kx=ECDH Au=ECDSA Enc=AES(256) Mac=SHA1
ECDHE-ECDSA-AES128-SHA TLSv1 Kx=ECDH Au=ECDSA Enc=AES(128) Mac=SHA1
ECDHE-RSA-AES256-GCM-SHA384 TLSv1.2 Kx=ECDH Au=RSA Enc=AESGCM(256) Mac=AEAD
ECDHE-RSA-AES128-GCM-SHA256 TLSv1.2 Kx=ECDH Au=RSA Enc=AESGCM(128) Mac=AEAD
ECDHE-RSA-AES256-SHA384 TLSv1.2 Kx=ECDH Au=RSA Enc=AES(256) Mac=SHA384
ECDHE-RSA-AES128-SHA256 TLSv1.2 Kx=ECDH Au=RSA Enc=AES(128) Mac=SHA256
ECDHE-RSA-AES256-SHA TLSv1 Kx=ECDH Au=RSA Enc=AES(256) Mac=SHA1
ECDHE-RSA-AES128-SHA TLSv1 Kx=ECDH Au=RSA Enc=AES(128) Mac=SHA1
DHE-RSA-AES256-GCM-SHA384 TLSv1.2 Kx=DH Au=RSA Enc=AESGCM(256) Mac=AEAD
DHE-RSA-AES256-CCM8 TLSv1.2 Kx=DH Au=RSA Enc=AESCCM8(256) Mac=AEAD
DHE-RSA-AES256-CCM TLSv1.2 Kx=DH Au=RSA Enc=AESCCM(256) Mac=AEAD
DHE-RSA-AES128-GCM-SHA256 TLSv1.2 Kx=DH Au=RSA Enc=AESGCM(128) Mac=AEAD
DHE-RSA-AES128-CCM8 TLSv1.2 Kx=DH Au=RSA Enc=AESCCM8(128) Mac=AEAD
DHE-RSA-AES128-CCM TLSv1.2 Kx=DH Au=RSA Enc=AESCCM(128) Mac=AEAD
DHE-RSA-AES256-SHA256 TLSv1.2 Kx=DH Au=RSA Enc=AES(256) Mac=SHA256
DHE-RSA-AES128-SHA256 TLSv1.2 Kx=DH Au=RSA Enc=AES(128) Mac=SHA256
DHE-RSA-AES256-SHA SSLv3 Kx=DH Au=RSA Enc=AES(256) Mac=SHA1
DHE-RSA-AES128-SHA SSLv3 Kx=DH Au=RSA Enc=AES(128) Mac=SHA1
</pre>
</div>
<div class="note">
v2.2の設定ファイル 10-ssl.conf を修正していたら下記エラーが起こりました。<br />
v2.3にアップデート後に設定ファイルを適切に対応するには <br />
/usr/share/doc/dovecot/example-config/conf.d/10-ssl.conf<br />
を参考にすると良いです。
<pre class="console">
Jun 22 08:31:30 kowloonet dovecot[6465]: config: Warning: Obsolete setting in /etc/dovecot/conf.d/10-ssl.conf:51: ssl_dh_parameters_length is no longer needed
Jun 22 08:31:30 kowloonet dovecot[6465]: config: Warning: Obsolete setting in /etc/dovecot/conf.d/10-ssl.conf:54: ssl_protocols has been replaced by ssl_min_protocol
Jun 22 08:37:56 kowloonet dovecot[6569]: config: Warning: please set ssl_dh=</etc/dovecot/dh.pem
</pre>
ssl_dh を指定しない時のエラー。
<pre class="console">
un 22 08:21:10 kowloonet dovecot[6388]: pop3-login: Error: Failed to initialize SSL server context: Can't load DH parameters: error:1408518A:SSL routines:ssl3_ctx_ctrl:dh key too small: user=<>, rip=xxx.xxx.xxx.xxx, lip=xxx.xxx.xxx.xxx, session=<VbetYaCoIfF+hMEL>
</pre>
</div>
<h4>Gmail宛にメールが送信されない件</h4>
<h5>maillog</h5>
<pre class="console">
Apr 1 07:51:34 kowloonet postfix/smtpd[2696]: disconnect from softbank126200169177.bbtec. net[126.200.169.177] ehlo=1 auth=1 mail=1 rcpt=1 data=1 rset=1 quit=1 commands=7
Apr 1 07:51:35 kowloonet postfix/smtp[2699]: 6E1F9C172C: to=<xxxxxxxxxxxxx@gmail.com>, r elay=gmail-smtp-in.l.google.com[64.233.189.27]:25, delay=1.5, delays=0.09/0.03/0.85/0.53, dsn=5.7.1, status=bounced (host gmail-smtp-in.l.google.com[64.233.189.27] said: 550-5.7.1 [160.16.139.144 12] Our system has detected that this message is 550-5.7.1 likely uns olicited mail. To reduce the amount of spam sent to Gmail, 550-5.7.1 this message has been blocked. Please visit 550-5.7.1 https://support.google.com/mail/?p=UnsolicitedMessageErr or 550 5.7.1 for more information. 6-20020a630e46000000b003824f9f2affsi710091pgo.451 - gs mtp (in reply to end of DATA command))
</pre>
DNSレコードに下記を追加することで解決。
<table>
<tr><td>エントリ名</td><td>タイプ</td><td>データ</td><td>TTL</td></tr>
<tr><td>@</td><td>TXT</td><td>v=spf1 a:mail.kowloonet.net include:_spf.google.com ~all</td><td> 3600s</td></tr>
</table>
参照:
<a href="https://support.google.com/a/answer/10684623?hl=ja&ref_topic=10685331" target="_blank">https://support.google.com/a/answer/10684623?hl=ja&ref_topic=10685331</a>
xioheihttp://www.blogger.com/profile/07600365896800702223noreply@blogger.comtag:blogger.com,1999:blog-5561372158145009417.post-35055871610455275292020-06-18T21:58:00.000+09:002020-06-20T09:16:03.053+09:00CentOS8でサーバー構築 - 6.FTPサーバーの設定(vsftpd SSL/TLSなど)以前に<a href="/2020/05/centos8-1.html#ftp">CentOS8でサーバー構築 - 1.環境設定</a>でFTPを使えるようにはしましたが、<br />
実際に運用するにはセキュリティーなどを強化してから使用することにします。<br />
今回 Portは 12345、PASV_PORTは60000-60100、クライアントの公開鍵認証は無しで設定します。<br />
ルータやパケットフィルタリング、firewallなどを開けておく事。<br />
vsftpd: version 3.0.3、OpenSSL 1.1.1c です。<br />
<span class="em1">この組み合わせだとTLSv1.3で認証する。</span><br />
(CentOS7では vsftpd: version 3.0.2、OpenSSL 1.0.2k-fips TLSv1.2で認証)<br />
使用したクライアントソフトはFFFTP Ver 4.7、FileZilla 3.48.1
<table>
<caption>設定一覧</caption>
<tr><td>listen_port</td><td>12345</td></tr>
<tr><td>anonymous_enable</td><td>NO<br />
<span class="notem">匿名での接続を許可</span></td></tr>
<tr><td>dirmessage_enable</td><td>NO<br />
<span class="notem">ディレクトリに.messageファイルがあれば表示</span></td></tr>
<tr><td>xferlog_file</td><td>/var/log/vsftpd.log</td></tr>
<tr><td>xferlog_std_format</td><td>NO<br />
<span class="notem">NOにした場合は詳細なログを記載</span></td></tr>
<tr><td>ascii_upload_enable</td><td>YES<br />
<span class="notem">アップロード時ASCIIモードでのデータ転送を許可</span></td></tr>
<tr><td>ascii_download_enable</td><td>YES<br />
<span class="notem">ダウンロード時ASCIIモードでのデータ転送を許可</span></td></tr>
<tr><td>chroot_local_user</td><td>YES<br />
<span class="notem">すべてのローカルユーザのログインをchrootで管理<br />ホームディレクトリの外側にアクセス不可</span></td></tr>
<tr><td>chroot_list_enable</td><td>YES<br />
<span class="notem">chroot_local_user=YESの場合、chroot_list_fileで指定した<br />ユーザのみホームディレクトリの外側にアクセス可</span></td></tr>
<tr><td>chroot_list_file</td><td>/etc/vsftpd/chroot_list<br />
<span class="notem">ここに記載のあるユーザのみホームディレクトリの外側にアクセス可</span></td></tr>
<tr><td>allow_writeable_chroot</td><td>YES<br />
<span class="notem">YESにしないと、chroot_listに記載のないユーザは接続できなくなる</span></td></tr>
<tr><td>userlist_enable</td><td>YES<br />
<span class="notem">userlist_fileを有効</span>
</td></tr>
<tr><td>userlist_deny</td><td>NO<br />
<span class="notem">userlist_enable=YESの場合<br />YES: userlist_fileに記載されたユーザのログインを拒否<br />
NO: userlist_fileに記載されたユーザのログインを許可</span>
</td></tr>
<tr><td>userlist_file</td><td>/etc/vsftpd/allowed_user_list<br />
<span class="notem">userlist_deny=NOにしてある場合は、<br />ここに記載のあるユーザのみログインを許可</span></td></tr>
<tr><td>ssl_enable</td><td>YES<br />
<span class="notem">SSL/TLSの設定を有効</span>
</td></tr>
<tr><td>ssl_tlsv1_2</td><td>YES<br />
<span class="notem">TLSv1.2を利用可。TLSv1.3も利用する模様</span></td></tr>
<tr><td>ssl_ciphers</td><td>HIGH<br />
<span class="notem">これを設定しないと、デフォルトのDES-CBC3-SHAになり、<br />使用するクライアントソフトによっては接続できないかも。<br />cipherを直接記載しても良い。</span></td></tr>
<tr><td>force_local_logins_ssl</td><td>YES<br />
<span class="notem">SSL/TLSを使用時のみユーザのログインを許可</span></td></tr>
<tr><td>force_local_data_ssl</td><td>YES<br />
<span class="notem">SSL/TLSを使用時のみデーター転送を許可</span></td></tr>
<tr><td>rsa_cert_file</td><td>/etc/pki/tls/certs/vsftpd.pem<br />
<span class="notem">証明書のパス<br />Let's Encrypt などで証明書を取得済みの場合はそちらのパスを</span></td></tr>
<tr><td>debug_ssl</td><td>YES<br />
<span class="notem">SSL関連のログを記載</span></td></tr>
<tr><td>pasv_min_port</td><td>60000</td></tr>
<tr><td>pasv_max_port</td><td>60100</td></tr>
</table>
<div class="note">
TLS1.0、TLS1.1には既に脆弱性が見つかっているので、TLS1.2以上の利用を推奨。
</div>
<h4>vsftpd.confの設定</h4>
マニュアルも一部追加で記載。
<h5>設定</h5>
<pre class="console">
# vi /etc/vsftpd/vsftpd.conf
</pre>
<pre class="code">
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
<span class="m1">anonymous_enable=NO</span>
・
・
# Activate directory messages - messages given to remote users when they
# go into a certain directory.
<span class="m1">dirmessage_enable=NO</span>
・
・
# You may override where the log file goes if you like. The default is shown
# below.
<span class="m1">xferlog_file=/var/log/vsftpd.log</span>
#
# If you want, you can have your log file in standard ftpd xferlog format.
# Note that the default log file location is /var/log/xferlog in this case.
<span class="m1">xferlog_std_format=NO</span>
・
・
# ASCII mangling is a horrible feature of the protocol.
<span class="m1">ascii_upload_enable=YES</span>
<span class="m1">ascii_download_enable=YES</span>
・
・
# You may specify an explicit list of local users to chroot() to their home
# directory. If chroot_local_user is YES, then this list becomes a list of
# users to NOT chroot().
# (Warning! chroot'ing can be very dangerous. If using chroot, make sure that
# the user does not have write access to the top level directory within the
# chroot)
<span class="m1">chroot_local_user=YES</span>
<span class="m1">chroot_list_enable=YES</span>
# (default follows)
<span class="m1">chroot_list_file=/etc/vsftpd/chroot_list</span>
<span class="m1">allow_writeable_chroot=YES</span>
・
・
# When "listen" directive is enabled, vsftpd runs in standalone mode and
# listens on IPv4 sockets. This directive cannot be used in conjunction
# with the listen_ipv6 directive.
<span class="m1">listen=YES</span>
#
# This directive enables listening on IPv6 sockets. By default, listening
# on the IPv6 "any" address (::) will accept connections from both IPv6
# and IPv4 clients. It is not necessary to listen on *both* IPv4 and IPv6
# sockets. If you want that (perhaps because you want to listen on specific
# addresses) then you must run two copies of vsftpd with two configuration
# files.
# Make sure, that one of the listen options is commented !!
<span class="m1">listen_ipv6=NO</span>
pam_service_name=vsftpd
userlist_enable=YES
・
・<span class="em1">ここから追加、デフォルトで有効無効になっているものも、明示的に記載在り</span>
#
# This option is examined if userlist_enable is activated. If you set this
# setting to NO, then users will be denied login unless they are explicitly
# listed in the file specified by userlist_file. When login is denied, the
# denial is issued before the user is asked for a password. Default: YES
<span class="m1">userlist_deny=NO</span>
#
# This option is the name of the file loaded when the userlist_enable
# option is active. Default: /etc/vsftpd.user_list
<span class="m1">userlist_file=/etc/vsftpd/allowed_user_list</span>
#
# If enabled, vsftpd will display directory listings with the time in your
# local time zone. The default is to display GMT. The times returned by
# the MDTM FTP command are also affected by this option. Default: NO
<span class="m1">use_localtime=YES</span>
#
# If activated, files and directories starting with . will be shown in
# directory listings even if the "a" flag was not used by the client.
# This override excludes the "." and ".." entries. Default: NO
<span class="m1">force_dot_files=NO</span>
#
# When enabled, allows use of the SITE CHMOD command. NOTE! This
# only applies to local users. Anonymous users never get to use SITE CHMOD.
# Default: YES
<span class="m1">chmod_enable=YES</span>
#
# If vsftpd is in standalone mode, this is the port it will listen on
# for incoming FTP connections. Default: 21
<span class="m1">listen_port=12345</span>
#
# If enabled, and vsftpd was compiled against OpenSSL, vsftpd will support
# secure connections via SSL. This applies to the control connection (including
# login) and also data connections. You'll need a client with SSL support too.
# NOTE!! Beware enabling this option. Only enable it if you need it. vsftpd can
# make no guarantees about the security of the OpenSSL libraries. By enabling
# this option, you are declaring that you trust the security of your installed
# OpenSSL library. Default: NO
<span class="m1">ssl_enable=YES
ssl_sslv2=NO
ssl_sslv3=NO
ssl_tlsv1=NO
ssl_tlsv1_1=NO
ssl_tlsv1_2=YES</span>
#
# This option can be used to select which SSL ciphers vsftpd will allow for
# encrypted SSL connections. See the ciphers man page for further details.
# Note that restricting ciphers can be a useful security precaution as it
# prevents malicious remote parties forcing a cipher which they have found
# problems with. Default: DES-CBC3-SHA
<span class="m1">ssl_ciphers=HIGH</span>
#
# If set to yes, all SSL data connections are required to exhibit SSL session
# reuse (which proves that they know the same master secret as the control
# channel). Although this is a secure default, it may break many FTP clients,
# so you may want to disable it. For a discussion of the consequences, see
# http://scarybeastsecurity.blogspot.com/2009/02/vsftpd-210-released.html
# (Added in v2.1.0). Default: YES
require_ssl_reuse=YES
<span class="m1">force_local_logins_ssl=YES
force_local_data_ssl=YES
rsa_cert_file=/etc/pki/tls/certs/vsftpd.pem</span>
#
# If enabled, then any log output which would have gone to /var/log/vsftpd.log
# goes to the system log instead. Logging is done under the FTPD facility.
# default: NO
syslog_enable=NO
#
# If true, OpenSSL connection diagnostics are dumped to the vsftpd log file.
# (Added in v2.0.6). Default: NO
<span class="m1">debug_ssl=YES</span>
#
# The minimum port to allocate for PASV style data connections. Can be used
# to specify a narrow port range to assist firewalling. Default: 0 (use any port)
<span class="m1">pasv_min_port=60000
pasv_max_port=60100</span>
</pre>
<div class="note">
allow_writeable_chroot=YES にしないと環境により下記エラーが起こる。
<pre class="console">500 OOPS: vsftpd: refusing to run with writable root inside chroot()
</pre>
</div>
<div class="note">
古いクライアントソフトだとデフォルト設定 require_ssl_reuse=YESの環境下では<br />
上記英文のマニュアルで多くのFTPクライアントは壊れると言っているように
<pre class="console">
522 SSL connection failed: session reuse required
</pre>
とファイルリストが表示されない事がある。
</div>
<div class="note">
Let's Encrypt で証明書を取得済みの場合は
<pre class="code">
rsa_cert_file=/etc/letsencrypt/live/xxxxxxxxx.com/fullchain.pem
rsa_private_key_file=/etc/letsencrypt/live/xxxxxxxxx.com/privkey.pem
</pre>
</div>
<h4>ユーザの設定</h4>
<h5>FTP接続を許可するユーザの追加</h5>
<pre class="code">
# echo "ユーザ名" >> /etc/vsftpd/allowed_user_list
</pre>
<h5>ホームディレクトリ以外の参照を許可するユーザの追加</h5>
<pre class="code">
# echo "ユーザ名" >> /etc/vsftpd/chroot_list
</pre>
<h4>SSL/TLS対応</h4>
有効期限は約10年に。<br />
色々聞かれますが、何も記載せず[ENTER]でいけますが、ある程度は入力しておきましょう。
<h5>証明書の作製</h5>
<pre class="console">
# cd /etc/pki/tls/certs
# openssl req -x509 -nodes -newkey rsa:2048 -keyout vsftpd.pem -out vsftpd.pem -days 3650
Generating a RSA private key
.+++++
...................+++++
writing new private key to 'vsftpd.pem'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:JP
State or Province Name (full name) []:Chiba
Locality Name (eg, city) [Default City]:Funabashi
Organization Name (eg, company) [Default Company Ltd]:KOWLOONET.NET
Organizational Unit Name (eg, section) []:rhizome
Common Name (eg, your name or your server's hostname) []:kowloonet.net
Email Address []:メールアドレス。記載した場合接続したときに表示されます。
</pre>
<h5>パーミッション変更</h5>
<pre class="console">
# chmod 400 vsftpd.pem
</pre>
<h5>証明書の確認</h5>
<pre class="console">
# openssl x509 -text -noout -in /etc/pki/tls/certs/vsftpd.pem
Certificate:
Data:
Version: 3 (0x2)
Serial Number:
1f:81:8f:0e:d6:c1:da:f8:c7:6e:31:39:6d:dc:d4:2a:51:e8:60:f4
Signature Algorithm: sha256WithRSAEncryption
・
・
</pre>
<h4>再起動して確認</h4>
<h5>vsftpd再起動</h5>
<pre class="console">
# systemctl restart vsftpd
</pre>
<h5>SSL/TLS接続の確認</h5>
<pre class="console">
# openssl s_client -connect localhost:12345 -starttls ftp
CONNECTED(00000003)
・
・
Peer signing digest: SHA256
Peer signature type: RSA-PSS
Server Temp Key: ECDH, P-256, 256 bits
---
SSL handshake has read 3349 bytes and written 751 bytes
Verification: OK
---
New, TLSv1.3, Cipher is TLS_AES_256_GCM_SHA384
Server public key is 2048 bit
Secure Renegotiation IS NOT supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
Early data was not sent
Verify return code: 0 (ok)
---
220 (vsFTPd 3.0.3)
---
Post-Handshake New Session Ticket arrived:
SSL-Session:
Protocol : TLSv1.3
Cipher : TLS_AES_256_GCM_SHA384
・
・
</pre>
TLSv1.3の様です。ssl_tlsv1_2=YES だとTLSv1.2以上で利用可という事でしょうか。<br />よくわからず、今後の課題としておきます。
<h5>FTPクライアントソフトで確認</h5>
割愛します。<br /><br />
以上でFTPの設定は終了です。
<h4>その他</h4>
<div class="note">
FFFTPで接続時、下記の様なエラーが吐かれる。接続・転送などは特に問題なし。<br />調べてはみたものの、原因は不明。<br />
FFFTPがTLS1.3に対応していないとかその辺??
<pre class="console">
Wed Jun 17 05:29:30 2020 [pid 9039] [ユーザ名] DEBUG: Client "xxx.xxx.xxx.xxx", "SSL ret: 18446744073709551615, SSL error: error:00000000:lib(0):func(0):reason(0), errno: 0"
</pre>
</div>
<div class="note">
証明書のパス rsa_cert_fileが正しくない時のエラー
<pre class="console">
500 OOPS: SSL: could not set cipher list
</pre>
</div>
<div class="note">
vsftpdがデフォルトで使用する暗号はDES-CBC3-SHAと記載されているが、サーバーには見当たらず。<br />
CentOS8 OpenSSL 1.1.1c
<pre class="console">
# openssl ciphers -v | grep 'DES-CBC3-SHA'
#
</pre>
試しにCentOS7では、<br />
CentOS7.6 OpenSSL 1.0.2k-fips
<pre class="console">
# openssl ciphers -v | grep 'DES-CBC3-SHA'
ECDHE-RSA-DES-CBC3-SHA SSLv3 Kx=ECDH Au=RSA Enc=3DES(168) Mac=SHA1
ECDHE-ECDSA-DES-CBC3-SHA SSLv3 Kx=ECDH Au=ECDSA Enc=3DES(168) Mac=SHA1
EDH-RSA-DES-CBC3-SHA SSLv3 Kx=DH Au=RSA Enc=3DES(168) Mac=SHA1
EDH-DSS-DES-CBC3-SHA SSLv3 Kx=DH Au=DSS Enc=3DES(168) Mac=SHA1
DH-RSA-DES-CBC3-SHA SSLv3 Kx=DH/RSA Au=DH Enc=3DES(168) Mac=SHA1
DH-DSS-DES-CBC3-SHA SSLv3 Kx=DH/DSS Au=DH Enc=3DES(168) Mac=SHA1
ECDH-RSA-DES-CBC3-SHA SSLv3 Kx=ECDH/RSA Au=ECDH Enc=3DES(168) Mac=SHA1
ECDH-ECDSA-DES-CBC3-SHA SSLv3 Kx=ECDH/ECDSA Au=ECDH Enc=3DES(168) Mac=SHA1
DES-CBC3-SHA SSLv3 Kx=RSA Au=RSA Enc=3DES(168) Mac=SHA1
KRB5-DES-CBC3-SHA SSLv3 Kx=KRB5 Au=KRB5 Enc=3DES(168) Mac=SHA1
</pre>
</div>
<div class="note">
CentOS7.6 OpenSSL 1.0.2k-fips環境下で構築したftpに接続してみると、<br />TLSv1.2となる
<pre class="console">
# openssl s_client -connect localhost:21 -starttls ftp
CONNECTED(00000003)
depth=0 C = JP, L = Default City, O = Default Company Ltd, CN = kowloonet.local
verify error:num=18:self signed certificate
verify return:1
depth=0 C = JP, L = Default City, O = Default Company Ltd, CN = kowloonet.local
verify return:1
---
Certificate chain
0 s:/C=JP/L=Default City/O=Default Company Ltd/CN=kowloonet.local
i:/C=JP/L=Default City/O=Default Company Ltd/CN=kowloonet.local
---
Server certificate
-----BEGIN CERTIFICATE-----
・
・
-----END CERTIFICATE-----
subject=/C=JP/L=Default City/O=Default Company Ltd/CN=kowloonet.local
issuer=/C=JP/L=Default City/O=Default Company Ltd/CN=kowloonet.local
---
No client certificate CA names sent
Client Certificate Types: RSA sign, DSA sign, ECDSA sign
Requested Signature Algorithms: RSA+SHA512:DSA+SHA512:ECDSA+SHA512:RSA+SHA384:DSA+SHA384:ECDSA+SHA384:RSA+SHA256:DSA+SHA256:ECDSA+SHA256:RSA+SHA224:DSA+SHA224:ECDSA+SHA224:RSA+SHA1:DSA+SHA1:ECDSA+SHA1
Shared Requested Signature Algorithms: RSA+SHA512:DSA+SHA512:ECDSA+SHA512:RSA+SHA384:DSA+SHA384:ECDSA+SHA384:RSA+SHA256:DSA+SHA256:ECDSA+SHA256:RSA+SHA224:DSA+SHA224:ECDSA+SHA224:RSA+SHA1:DSA+SHA1:ECDSA+SHA1
Peer signing digest: SHA512
Server Temp Key: ECDH, P-256, 256 bits
---
SSL handshake has read 1663 bytes and written 437 bytes
---
New, TLSv1/SSLv3, Cipher is ECDHE-RSA-AES256-GCM-SHA384
Server public key is 2048 bit
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
SSL-Session:
Protocol : TLSv1.2
Cipher : ECDHE-RSA-AES256-GCM-SHA384
Session-ID:
・
・
---
</pre>
</div>
<h5>ciphers表示</h5>
<pre class="console">
# openssl ciphers -v | sort
表示結果は割愛
</pre>
<h5>ciphers ECDHEのみ表示</h5>
<pre class="console">
# openssl ciphers -v | grep ECDHE | sort
ECDHE-ECDSA-AES128-CCM TLSv1.2 Kx=ECDH Au=ECDSA Enc=AESCCM(128) Mac=AEAD
ECDHE-ECDSA-AES128-GCM-SHA256 TLSv1.2 Kx=ECDH Au=ECDSA Enc=AESGCM(128) Mac=AEAD
ECDHE-ECDSA-AES128-SHA256 TLSv1.2 Kx=ECDH Au=ECDSA Enc=AES(128) Mac=SHA256
ECDHE-ECDSA-AES128-SHA TLSv1 Kx=ECDH Au=ECDSA Enc=AES(128) Mac=SHA1
ECDHE-ECDSA-AES256-CCM TLSv1.2 Kx=ECDH Au=ECDSA Enc=AESCCM(256) Mac=AEAD
ECDHE-ECDSA-AES256-GCM-SHA384 TLSv1.2 Kx=ECDH Au=ECDSA Enc=AESGCM(256) Mac=AEAD
ECDHE-ECDSA-AES256-SHA TLSv1 Kx=ECDH Au=ECDSA Enc=AES(256) Mac=SHA1
ECDHE-ECDSA-CHACHA20-POLY1305 TLSv1.2 Kx=ECDH Au=ECDSA Enc=CHACHA20/POLY1305(256) Mac=AEAD
ECDHE-PSK-AES128-CBC-SHA256 TLSv1 Kx=ECDHEPSK Au=PSK Enc=AES(128) Mac=SHA256
ECDHE-PSK-AES128-CBC-SHA TLSv1 Kx=ECDHEPSK Au=PSK Enc=AES(128) Mac=SHA1
ECDHE-PSK-AES256-CBC-SHA TLSv1 Kx=ECDHEPSK Au=PSK Enc=AES(256) Mac=SHA1
ECDHE-PSK-CHACHA20-POLY1305 TLSv1.2 Kx=ECDHEPSK Au=PSK Enc=CHACHA20/POLY1305(256) Mac=AEAD
ECDHE-RSA-AES128-GCM-SHA256 TLSv1.2 Kx=ECDH Au=RSA Enc=AESGCM(128) Mac=AEAD
ECDHE-RSA-AES128-SHA256 TLSv1.2 Kx=ECDH Au=RSA Enc=AES(128) Mac=SHA256
ECDHE-RSA-AES128-SHA TLSv1 Kx=ECDH Au=RSA Enc=AES(128) Mac=SHA1
ECDHE-RSA-AES256-GCM-SHA384 TLSv1.2 Kx=ECDH Au=RSA Enc=AESGCM(256) Mac=AEAD
ECDHE-RSA-AES256-SHA TLSv1 Kx=ECDH Au=RSA Enc=AES(256) Mac=SHA1
ECDHE-RSA-CHACHA20-POLY1305 TLSv1.2 Kx=ECDH Au=RSA Enc=CHACHA20/POLY1305(256) Mac=AEAD
</pre>
xioheihttp://www.blogger.com/profile/07600365896800702223noreply@blogger.comtag:blogger.com,1999:blog-5561372158145009417.post-54149699675255574652020-06-13T11:02:00.000+09:002020-07-17T00:26:17.621+09:00【Linux】vi操作メモ<h2>vimの設定</h2>
<h5>vim設定</h5>
<pre class="console">
# vi ~/.vimrc
</pre>
<pre class="code">
set tabstop=2
set shiftwidth=2
set smartindent
set expandtab
</pre>
<pre class="console">
# source ~/.vimrc
</pre>
<table>
<tr>
<td>tabstop</td><td>タブ幅をスペースn分で読み込み</td></tr>
<td>shiftwidth</td><td>タブ幅をスペースn分で作成</td></tr>
<td>smartindent</td><td>自動インデント</td></tr>
<td>expandtab</td><td>タブを半角スペースで挿入</td></tr>
</table>
<h2>vim拡張子の関連付け</h2>
<h5>vim設定</h5>
<pre class="code">
# echo 'autocmd BufNewFile,BufRead *.vue set filetype=php' >> ~/.vimrc
</pre>
<pre class="console">
# vi test.vue
: source ~/.vimrc
</pre>
<h2>カーソルの移動</h2>
<table>
<tr>
<th>上下左右</th><td>h j k l</td></tr>
<th>単語の先頭</th><td>w</td></tr>
<th>前の単語の先頭</th><td>b</td></tr>
<th>単語の末尾</th><td>e</td></tr>
<th>前の単語の末尾</th><td>ge</td></tr>
<th>段落の移動</th><td>{ }</td></tr>
<th>行の先頭</th><td>^</td></tr>
<th>行の末尾</th><td>$</td></tr>
<th>ファイルの先頭</th><td>gg</td></tr>
<th>ファイルの末尾</th><td>G</td></tr>
<th>画面スクロール下</th><td>Ctrl+F</td></tr>
<th>画面スクロール</th><td>Ctrl+B</td></tr>
</tr>
</table>xioheihttp://www.blogger.com/profile/07600365896800702223noreply@blogger.comtag:blogger.com,1999:blog-5561372158145009417.post-74861991624447046152020-06-12T05:33:00.000+09:002020-06-25T09:52:24.826+09:00CentOS8でサーバー構築 - 5.バーチャルホスト・BASIC認証の設定(Apache2.4)バーチャルホスト<br />
<span class="em2"> dev.kowloonet.local</span><br />
ドキュメントルートは<br />
<span class="em2"> /home/dev</span><br />
で設定する。<br />
DNSは内部向けにBINDで dev.kowloonet.local でアクセスできるようにしてあります。<br />
独自ドメインを取得していて外部のDNSサーバーを利用している場合は<br />コントロールパネルなどから設定が必要です。<br />
<a href="/2020/06/centos8-4dnsbind.html">CentOS8でサーバー構築 - 4.内部向けDNSサーバー(BIND)</a>
<h4>バーチャルホストの設定</h4>
<h5>未定義バーチャルホストの接続を拒否</h5>
<pre class="console">
# vi /etc/httpd/conf.d/virtualhost-00.conf
</pre>
<pre class="code">
<VirtualHost _default_:80>
ServerName any
<Location />
Require all denied
</Location>
</VirtualHost>
</pre>
<h5>バーチャルホスト設定</h5>
<pre class="console">
# vi /etc/httpd/conf.d/virtualhost-dev.conf
</pre>
<pre class="code">
<VirtualHost *:80>
ServerName dev.kowloonet.local
DocumentRoot /home/dev
<Directory /home/dev>
Options FollowSymLinks
DirectoryIndex index.html index.php
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
</pre>
<h5>Apache再起動</h5>
<pre class="console">
# systemctl restart httpd
</pre>
<h4>BASIC認証の設定</h4>
先程追加したバーチャルホストに対してBASIC認証をかける。
<h5>バーチャルホスト追加</h5>
<pre class="console">
# vi /etc/httpd/conf.d/virtualhost-dev.conf
</pre>
<pre class="code">
<VirtualHost *:80>
ServerName dev.kowloonet.local
DocumentRoot /home/dev
# Auth Basic
<Directory /home/dev>
Options FollowSymLinks
DirectoryIndex index.html index.php
AllowOverride All
AuthType Basic
AuthName "Basic Authentication"
AuthUserFile /etc/httpd/conf/.htpasswd_dev
require valid-user
</Directory>
</VirtualHost>
</pre>
<h5>htpasswdファイル作成(新規で作成)</h5>
<pre class="console">
# htpasswd -c /etc/httpd/conf/.htpasswd_dev ユーザ名
New password:
Re-type new password:
Adding password for user ユーザ名
</pre>
<h5>htpasswdファイル作成(ユーザを追加)</h5>
<pre class="console">
# htpasswd /etc/httpd/conf/.htpasswd_dev ユーザ名
</pre>
<h5>Apache再起動</h5>
<pre class="console">
# systemctl restart httpd
</pre>
<div class="note">
<h5>ログファイルを別にしたい場合</h5>
<pre class="code">
<VirtualHost *:80>
ServerName dev.kowloonet.local
DocumentRoot /home/dev
<span class="m1">ErrorLog logs/dev.kowloonet.local-error_log</span>
<span class="m1">CustomLog logs/dev.kowloonet.local-access_log combined env=!no_log</span>
<Directory /home/dev>
Options FollowSymLinks
DirectoryIndex index.html index.php
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
</pre>
</div>xioheihttp://www.blogger.com/profile/07600365896800702223noreply@blogger.comtag:blogger.com,1999:blog-5561372158145009417.post-69348738429057711892020-06-11T10:34:00.003+09:002020-06-11T10:38:08.096+09:00TeraTermのマクロ - 自動でROOTログイン<h4>パスワード形式での認証</h4>
<pre class="code">
username = 'ユーザー名'
hostname = '192.168.128.100'
pass = 'ユーザのパスワード'
rootpass = 'ルートのパスワード'
port = '22'
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
msg = hostname
strconcat msg ':port /ssh /2 /auth=password /user='
strconcat msg username
strconcat msg ' /passwd='
strconcat msg pass
connect msg
wait username
varCmd = 'su -'
sendln varCmd
wait 'Password:'
sendln ROOTPASS
</pre>xioheihttp://www.blogger.com/profile/07600365896800702223noreply@blogger.comtag:blogger.com,1999:blog-5561372158145009417.post-79907249633536985702020-06-11T04:42:00.000+09:002020-06-11T05:10:03.914+09:00【Wordpress】カスタムフィールドでソート・日付範囲指定<h4>日付でソートしてその年以降の記事のみ表示</h4>
ユーザが設定したカスタムフィールド「schedule_date」でソートして、<br />
現在の年より過去の記事は表示させないようにする。<br />
「schedule_date」は Ymd の8桁の文字列。<br />
ソートには<br />
'orderby' => 'meta_value'<br />
'order' => 'ASC/DESC', <br />
'meta_key' => 'ソート対象のフィールド名',<br />
で指定する。<br />
条件判定は meta_query を使う。
<pre class="code">
<?php
$posttype = 'schedule';
$args = array(
'posts_per_page' => -1,
'post_type' => $posttype,
'post_status' => 'publish',
<span class="m1">'orderby' => 'meta_value',</span>
<span class="m1">'order' => 'ASC',</span>
<span class="m1">'meta_key' => 'schedule_date',</span>
<span class="m1">'meta_query' => array('key' => 'schedule_date',</span>
<span class="m1">'value' => date('Y').'0101',</span>
<span class="m1">'compare' => '>=',</span>
<span class="m1">'type' => 'DATE'</span>
<span class="m1">),</span>
);
$the_query = new WP_Query($args);
</pre>
<h4>日付でソートしてその年の記事のみ表示</h4>
範囲指定の条件が2個以上の場合は relation を使う。
<pre class="code">
<?php
$posttype = 'schedule';
$args = array(
'posts_per_page' => -1,
'post_type' => $posttype,
'post_status' => 'publish',
'orderby' => 'meta_value',
'order' => 'ASC',
'meta_key' => 'schedule_date',
'meta_query' => array(
<span class="m1">'relation' => 'AND',</span>
array(
'key' => 'schedule_date',
'value' => date('Y').'0101',
'compare' => '>=',
'type' => 'DATE'
),
array(
'key' => 'schedule_date',
'value' => date('Y').'1231',
'compare' => '<=',
'type' => 'DATE'
)
)
);
$the_query = new WP_Query($args);
</pre>
xioheihttp://www.blogger.com/profile/07600365896800702223noreply@blogger.com