CentOS9 秘伝のタレ
CentOS7から大きくは変わっていません。
| yum -> dnf
ifconfig -> ip (dnf iproute)
|
コマンドは、この2つぐらいか大きな変更点です。
その他、selinuxが起動してたりしますが、selinuxは一旦OFFでの運用とします。
参考サイト
あとで書く、あればかく。
秘伝のタレ
ユーザ作成
PW認証の場合(非推奨)
鍵認証の場合
| su {user_name}
cd
ssh-keygen
# 以前と同じ pemで生成する場合は下記の通り -> なんか形式がかわってるはず。
ssh-keygen -t rsa -m PEM
# デフォルトだとこちら
ssh-keygen -t rsa
cd .ssh/
cat id_rsa.pub >> authorized_keys
chmod 600 authorized_keys
cat id_rsa
|
秘密鍵で入れるか確認する
ローカル作業
| # 秘密鍵を保存
vi .ssh/xxxxxx.key
chmod 600 .ssh/xxxxxx.key
ssh -i .ssh/xxxxxx.key {user_name}@xxx.xxx.xxx.xxx
|
sudo
sudoの調整、人によってはnopassを怒る人もいます
root にて
| ## Same thing without a password
# %wheel ALL=(ALL) NOPASSWD: ALL
## Same thing without a password
%wheel ALL=(ALL) NOPASSWD: ALL
%wheel ALL=(ALL) ALL
がコメントINされてる場合は、コメントアウト
|
wheelグループを追加
| groups {group_name}
usermod -aG wheel {group_name}
groups {group_name}
|
パッケージを最新にする
| # yum は dnf へ
dnf check-update
dnf update
|
selinuxの調整
| # getenforce offになってるはず
# SELINUX=disabled になってればOK
# なってなければ、 setenforce 0
# vi /etc/selinux/config SELINUX=disabled へ書き換え
cat /etc/selinux/config
|
sshの調整
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 | # rootログインをなくす
cd /etc/ssh/
cp sshd_config sshd_config.org
vi /etc/ssh/sshd_config
Rootログイン、パスワードログイン禁止
# diff sshd_config sshd_config.org
46c46
< PermitRootLogin no
---
> PermitRootLogin yes
73c73
< PasswordAuthentication no
---
> PasswordAuthentication yes
systemctl restart sshd
# 確認しようね
|
dnf回りの調整 パッケージの自動更新
| dnf check
Failed to set locale, defaulting to C.UTF-8
# 原因 : LC_ALLが設定されていないから LC_ALLが設定されていれば、ロケールにはその値が使われます。他のロケール関係の環境変数の値は無視されます
# でもよくみるとさ、Failed to set locale って localeがないよって事で
# locale コマンド打つと、確かに LC_ALLがから
# locale -a を打つと日本語が使えない
# なので日本語パッケージを入れてみる。 LC_ALL=c をセットするより正しそうかと思われる。
dnf list langpacks-*
# langpacks-ja.noarch が有るはず
dnf install langpacks-ja
# 表示が日本語になって少しなれない・・・
|
dnfの自動更新
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 | # デフォルトではパッケージの取得だけでインストールはしない( apply_updates = no )になっているので、これについては設定ファイルを弄って yes に直しておきます。
# dnf-automatic は cron ではなく、systemd の timer*2 による定期実行
dnf install dnf-automatic
# {,.org}の書き方初めて知った、これで.org付でコピーされるのか
cp -a /etc/dnf/automatic.conf{,.org}
cd /etc/dnf/
sed -i -e 's/^apply_updates = no/apply_updates = yes/' /etc/dnf/automatic.conf
# diff automatic.conf automatic.conf.org
18c18
< apply_updates = yes
---
> apply_updates = no
systemctl enable dnf-automatic.timer
systemctl start dnf-automatic.timer
Memo)
https://howtosanta.com/japan/centos-8%E3%81%A7%E8%87%AA%E5%8B%95%E3%83%91%E3%83%83%E3%82%B1%E3%83%BC%E3%82%B8%E6%9B%B4%E6%96%B0%E3%82%92%E6%A7%8B%E6%88%90%E3%81%99%E3%82%8B%E6%96%B9%E6%B3%95/
というのがあり
dnf-automatic-install.timer
dnf-makecache.timer
あたりでも同様の事ができそう(今後はこっちに移りそうな気配・・)
https://blog.yuto-shin.net/2020/about-dnf-centos8/
3. 自動更新の設定
がわかりやすい。
|
hostnameの設定 ■■■■■
| hostname toss.tenshindo.ne.jp
hostnamectl set-hostname toss.tenshindo.ne.jp
|
wgetのインストール ■■■■■
| which wget
# なければ
dnf install wget
|
httpdのセットアップ ■■■■■
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68 | # dnf info httpd
名前 : httpd
バージョン : 2.4.37
dnf install httpd mod_ssl
# 設定ファイル更新
cd /etc/httpd/conf/
cp -a httpd.conf{,.org}
vi httpd.conf
# diff httpd.conf httpd.conf.org
167c167
< DirectoryIndex index.php index.html
---
> DirectoryIndex index.html
194,196d193
< # custom add
< SetEnvIf Request_URI "\.(gif|jpg|png|css|js|swf|svg|woff|woff2)$" nolog
<
300c297
< AddHandler cgi-script .cgi
---
> #AddHandler cgi-script .cgi
# セキュリティ用ファイルを作成記載する
cd /etc/httpd/conf.d/
touch security.conf
vi security.conf
#最後に追記する
# バージョン情報の隠蔽
ServerTokens Prod
Header unset X-Powered-By
# httpoxy 対策
RequestHeader unset Proxy
# クリックジャッキング対策
Header append X-Frame-Options SAMEORIGIN
# XSS対策
Header set X-XSS-Protection "1; mode=block"
Header set X-Content-Type-Options nosniff
# XST対策
TraceEnable Off
# 個別ファイル更新
cd /etc/httpd/conf.d/
touch vhosts.conf
vi vhosts.conf
# サンプルに沿って設定(下記)
cp -a ssl.conf{,.org}
# sslも別ファイルバージョン ssl.confはもろもろコメントアウトする
vi vhosts-ssl.conf
or
vi ssl.conf
# サンプルに沿って設定(下記)
# 設定分繰り返す
mkdir -p /var/www/vhosts/www.example.com/html
mkdir -p /var/log/httpd/www.example.com
chown -R {user_name}:{user_group} /var/www/vhosts/www.example.com
# 起動してみる
# この時点は起動できても firewalldの設定でアクセス出来ない可能性が大
httpd -S
systemctl start httpd
systemctl enable httpd
|
ログローテーションの調整 下記サンプル参照■■
| vi /etc/logrotate.d/httpd
|
SSLセットアップ(Let's Encrypt)■■
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80 | # https://certbot.open-code.club/
# apacheの場合 (改善するべき事ありそう)
cd /usr/local/src/
wget https://dl.eff.org/certbot-auto
chmod 755 certbot-auto
mv certbot-auto /usr/local/bin/
# 依存パッケージのインストール
certbot-auto --install-only
# /usr/local/bin/certbot-auto --apache
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator apache, Installer apache
Enter email address (used for urgent renewal and security notices)
(Enter 'c' to cancel): kiyo@itm.co.jp
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing, once your first certificate is successfully issued, 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: Y
Which names would you like to activate HTTPS for?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: example.com
2: jafco.itm.ne.jp
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate numbers separated by commas and/or spaces, or leave input
blank to select all options shown (Enter 'c' to cancel): 2
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for jafco.itm.ne.jp
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/httpd/conf.d/ssl.conf
Redirecting vhost in /etc/httpd/conf.d/vhosts.conf to ssl vhost in /etc/httpd/conf.d/ssl.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://jafco.itm.ne.jp
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Subscribe to the EFF mailing list (email: kiyo@itm.co.jp).
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/jafco.itm.ne.jp/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/jafco.itm.ne.jp/privkey.pem
Your cert will expire on 2020-10-25. To obtain a new or tweaked
version of this certificate in the future, simply run certbot-auto
again with the "certonly" option. To non-interactively renew *all*
of your certificates, run "certbot-auto renew"
- Your account credentials have been saved in your Certbot
configuration directory at /etc/letsencrypt. You should make a
secure backup of this folder now. This configuration directory will
also contain certificates and private keys obtained by Certbot so
making regular backups of this folder is ideal.
- 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
# 再取得
certbot-auto renew
crontab -e
# let's encrypt 2020.07.27
00 04 01 * * /usr/local/bin/certbot-auto renew
|
以下まったく整形してない
■■ SSLセットアップ(Let's以外のファイルの場合)■■
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 | # /etc/ssl が新たにCentOS8からできてるのでそちらで行う事とする
mkdir /etc/ssl/ssl.key
mkdir /etc/ssl/ssl.crt
mkdir /etc/ssl/ssl.csr
cd /etc/ssl/ssl.key
#新規以外の場合はファイルの上書きされるので注意
openssl req -nodes -newkey rsa:2048 -keyout /etc/ssl/ssl.key/www.example.com.key -out /etc/ssl/ssl.csr/www.example.com.csr
# 2018.0705 別手法
# 秘密鍵作成
openssl genrsa -des3 -out example.com.sha256.2048.key 2048 -sha256
# PW解除
openssl rsa -in examplecom.sha256.2048.pass.key -out example.com.sha256.2048.key
#CSR作成
openssl req -new -sha256 -key /etc/ssl/ssl.key/example.com.sha256.2048.key -out example.com.csr
|
CSRの内容を確認するコマンド
| openssl req -in /etc/ssl/ssl.csr/www.example.com.csr -text
|
CSRの内容確認ツール
SSL証明書・秘密鍵・CSRファイルのペア確認方法 -> チェックサムを確認する
https://qiita.com/sumida0713/items/72fcb2b0ab926c906507
証明書
openssl x509 -noout -modulus -in | openssl md5
秘密鍵
openssl rsa -noout -modulus -in <秘密鍵ファイル> | openssl md5
CSR
openssl req -noout -modulus -in | openssl md5
サーバ証明書を作成する場合(通常行わない)
| openssl x509 -req -days 3650 -in /etc/httpd/ssl/ssl.csr/www.example.com.csr -signkey /etc/httpd/ssl/ssl.key/www.example.com.key -out /etc/httpd/ssl/ssl.crt/www.example.com.crt
|
■■ mod_security ■■■
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55 | 参考URL
https://www.shadan-kun.com/blog/measure/2939/
https://qiita.com/crazyhacks/items/27e54a67d3a44e9787b9
https://qiita.com/is2ei/items/56d0f0276c57867cb81a
dnf install mod_security mod_security_crs
# mod_security-mlogc はログ解析する場合に必要ぽい
# 下記が設定ファイル
# /etc/httpd/conf.d/mod_security.conf
# 主なルールファイルは下記
# # ModSecurity Core Rules Set and Local configuration
# IncludeOptional modsecurity.d/*.conf
# IncludeOptional modsecurity.d/activated_rules/*.conf
# IncludeOptional modsecurity.d/local_rules/*.conf
# 運用開始は下記の調整がいいかも
# /etc/httpd/conf.d/mod_security.conf
# にて、検知のみとする設定である
# SecRuleEngine DetectionOnly
# SQLインジェクション REQUEST-942-APPLICATION-ATTACK-SQLI.conf RESPONSE-951-DATA-LEAKAGES-SQL.conf
# クロスサイトスクリプティング REQUEST-941-APPLICATION-ATTACK-XSS.conf
# PHP用 REQUEST-933-APPLICATION-ATTACK-PHP.conf RESPONSE-953-DATA-LEAKAGES-PHP.conf
# を除いて、他のconfファイルを無効化します。
# シンボリックリンクを削除すると、yumアップデート時に再度有効になってしまうので、同名の空ファイルに置き換えます。
# IncludeOptional の部分を調整するのが筋の気もする
cd /etc/httpd/modsecurity.d
cp -rp activated_rules activated_rules.org
cd activated_rules
# 今回はファイルを指定する
cd /etc/httpd/conf.d/
cp -a mod_security.conf mod_security.conf.org
vi /etc/httpd/conf.d/mod_security.conf
# diff mod_security.conf mod_security.conf.org
4d3
< #SecRuleEngine DetectionOnly ←追記(攻撃を検知した場合、遮断せず、検知内容をログに出力する設定)SecRuleEngine Onを同時にコメントアウトする
54,58c53
< IncludeOptional modsecurity.d/activated_rules/REQUEST-942-APPLICATION-ATTACK-SQLI.conf.conf
< IncludeOptional modsecurity.d/activated_rules/RESPONSE-951-DATA-LEAKAGES-SQL.conf
< IncludeOptional modsecurity.d/activated_rules/REQUEST-941-APPLICATION-ATTACK-XSS.conf
< IncludeOptional modsecurity.d/activated_rules/REQUEST-933-APPLICATION-ATTACK-PHP.conf
< IncludeOptional modsecurity.d/activated_rules/RESPONSE-953-DATA-LEAKAGES-PHP.conf
---
> IncludeOptional modsecurity.d/activated_rules/*.conf
動作確認
https://toss.tenshindo.ne.jp/login/login.php?union+select
|
■■■■ PostgreSQL ■■■■■
| # 別リポジトリでなくデフォルトを利用する場合
dnf install postgresql postgresql-server
export PGSETUP_INITDB_OPTIONS="--encoding=UTF-8 --no-locale"
postgresql-setup initdb
systemctl enable postgresql
systemctl start postgresql
|
■■■■ MySQL ■■■■■
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 | # https://mattintosh.hatenablog.com/entry/20200311/1583904463 が詳しい
cd /usr/local/src/
# version 8.x なら下記でOK
wget https://dev.mysql.com/get/mysql80-community-release-el8-1.noarch.rpm
rpm -ivh mysql-community-release-el7-5.noarch.rpm
# それ以外は、 https://repo.mysql.com/yum/ から取得
# 2020.07.27 日現在はこれ
https://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql-community-release-el7-7.noarch.rpm
# 5.7を有効に 5.6を無効化する必要有
vi /etc/yum.repos.d/mysql-community.repo
# mysql と mariadb モジュールを無効にする。
dnf module disable mysql mariadb
dnf module list mysql mariadb
# 確認
ll /etc/dnf/modules.d
cat /etc/dnf/modules.d/*
dnf info mysql-community-server
dnf install mysql-community-server
systemctl start mysqld.service
systemctl enable mysqld.service
cat /var/log/mysqld.log | grep 'temporary password'
l!g=*cHf9a-W // インストール毎に違う
mysql -u root -p
Exit
|
■■■■ MariaDB ■■■■■
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 | https://mariadb.com/ja/resources/blog/mariadb-on-centos8/
# MariaDB Package Repository Setup and Usage
https://mariadb.com/kb/en/mariadb-package-repository-setup-and-usage/
#今回はここが一番役に立つ
https://www.s-style.co.jp/blog/2019/12/5579/
# 10.3 はデフォルトリポジトリになります。今回は10.4
cd /usr/local/src
curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash -s -- --mariadb-server-version="mariadb-10.4"
cat /etc/yum.repos.d/mariadb.repo
dnf --repo=mariadb-main search MariaDB
# バージョン : 10.4.12 になる
dnf --repo=mariadb-main info MariaDB
# 依存関係で先にインストール
dnf install rsync libaio lsof perl-DBI galera-4
# 本体をインストール
dnf install --repo=mariadb-main MariaDB-server
# 起動
systemctl enable mariadb
systemctl start mariadb
# 接続 rootで
mariadb
|
■■■■ MySQL MariaDB 共通設定 ■■■■■
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39 | # 下記のコマンドは真面目にセキュリティを確保するならすべきだ
# 英(大文字小文字)数字、記号が必要
ROOTのPWは、 1qaz#edc5tgB
mysql_secure_installation
Or
mariadb-secure-installation
Change the password for root ? ((Press y|Y for Yes, any other key for No) : y
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
変更したPWでログインしてみる
# 設定調整 [mysqld]以外の部分をファイル下部に貼り付ければOK
vi /etc/my.cnf
[mysqld]
character-set-server = utf8
default_password_lifetime = 0
[client]
default-character-set=utf8
systemctl restart mysqld.service
systemctl enable mysqld.service
# DBの作成と利用ユーザの作成
CREATE DATABASE {database_name} DEFAULT CHARACTER SET utf8;
CREATE USER '{database_user_name}'@'localhost' IDENTIFIED BY 'trEVam%gtU4x';
FLUSH PRIVILEGES;
#権限
GRANT ALL ON {database_name}.* TO '{database_user_name}'@'localhost' ;
FLUSH PRIVILEGES;
|
■■■■ PHP ■■■■■
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38 | # epleが必要なばあいはこちら
dnf install epel-release
# こちらで良いらしい
dnf -y install https://rpms.remirepo.net/enterprise/remi-release-8.rpm
# 下記が今までしてた。コマンド
cd /usr/local/src/
wget http://rpms.famillecollet.com/enterprise/remi-release-8.rpm
rpm -ivh remi-release-8.rpm
# 利用出来るバージョンを確認
dnf module list php
# バージョン指定でインストール name:Stream のツナギ
dnf module install php:remi-7.4
#足りない分を別途
dnf install php-devel php-gd php-pdo php-pgsql php-pecl-mysql
# https://forum.remirepo.net/viewtopic.php?id=3911
# php-devel を入れようとすると libedit-devel が無いと怒られる。上記URLが参考になりそうだけどPASS
#
#以下はおこのみで
php-pecl-zip php-pecl-jsonc php-opcache
# PHPの設定変更
cp -a php.ini php.ini.org
# diff php.ini php.ini.org
374c374
< expose_php = Off
---
> expose_php = On
902c902
< date.timezone = Asia/Tokyo
---
> ;date.timezone =
|
■■■■ fail2ban ■■■■■
1
2
3
4
5
6
7
8
9
10
11
12
13 | dnf install fail2ban-systemd fail2ban
systemctl enable fail2ban
systemctl start fail2ban
# 軽い設定
cd /etc/fail2ban/jail.d
touch local.conf
# 下記設定
vi local.conf
# ddos,dos設定追加
touch /etc/fail2ban/filter.d/apache-ddos.conf
vi /etc/fail2ban/filter.d/apache-ddos.conf
|
■■■■ postfix ■■■■■
1
2
3
4
5
6
7
8
9
10
11
12 | dnf install postfix
cd /etc/postfix
cp -a main.cf{,.org}
# 設定は下記参照
vi main.cf
# 設定は下記参照
vi master.cf
systemctl enable postfix
systemctl start postfix
|
■■ root mailの転送 ■■
| #root の .forword ファイル作成に書き込む方が良い
cd
touch .forword
vi .forword
#メアドを記載する
---
kiyo@itm.co.jp
--
|
■■■■ logwatchの設定 ■■■■■
| dnf install logwatch
cd /etc/logwatch/conf/
cp -a logwatch.conf{,.org}
cp -a /usr/share/logwatch/default.conf/logwatch.conf logwatch.conf
|
■■■■ firewalldの設定 ■■■■■
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 | systemctl enable firewalld
systemctl start firewalld
firewall-cmd --list-all
firewall-cmd --get-services
firewall-cmd --zone=public --permanent --add-service=http
firewall-cmd --zone=public --permanent --add-service=https
firewall-cmd --zone=public --permanent --add-service=mysql
firewall-cmd --zone=public --permanent --add-service=smtp
firewall-cmd --zone=public --permanent --add-service=smtps
firewall-cmd --zone=public --permanent --add-service=pop3
firewall-cmd --zone=public --permanent --add-service=pop3s
firewall-cmd --zone=public --permanent --add-service=imap
firewall-cmd --zone=public --permanent --add-service=imaps
#publicのサービス一覧確認
firewall-cmd --list-services --zone=public --permanent
# sshをportでなくIPのみにする場合は下記の通りする
firewall-cmd --permanent --zone=public --add-rich-rule="rule family="ipv4" source address="61.194.253.50" port protocol="tcp" port="22" accept"
firewall-cmd --reload
# 設定削除(sshを削除)
firewall-cmd --remove-service=ssh --zone=public --permanent
|
■■■■ phpMyAdminの設定 (ソースインストール) ■■■■■
| https://qiita.com/lixwork/items/7b4cabd169803138b03f
https://souiunogaii.hatenablog.com/entry/phpMyAdmin-Install
・phpMyAdmin 5.0.2 以降
|
■■■■ MT で必要になってきそうなもの ■■■■■
1
2
3
4
5
6
7
8
9
10
11
12
13
14 | dnf install epel-release
dnf install perl-DBI
dnf install perl-DBD-MySQL
dnf install ImageMagick
dnf install ImageMagick-perl
dnf install gd
dnf install perl-GD
dnf install perl-Time-HiRes
dnf install perl-Archive-Tar
dnf install perl-Archive-Zip
dnf install perl-XML-SAX
dnf install perl-libxml-perl
dnf install perl-Authen-SASL
dnf install perl-open
|
以下設定サンプル (コピペ用)
vhosts.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56 | #www.example.com
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
DocumentRoot /var/www/vhosts/www.example.com/html
ErrorLog /var/log/httpd/www.example.com/www.example.com-error_log
CustomLog /var/log/httpd/www.example.com/www.example.com-access_log combined env=!nolog
# cgi-binがいる場合
ScriptAlias /cgi-bin/ "/var/www/vhosts/www.example.com/cgi-bin/"
# htmlでssiを動かす(下記の Options の設定でhtml以下の設置となる)
AddHandler server-parsed .html
<Directory /var/www/vhosts/www.example.com/html>
AllowOverride All
DirectoryIndex index.html index.php
Options Includes FollowSymLinks ExecCGI
Require all granted
</Directory>
SetEnv CAKE_ENV prod
</VirtualHost>
#stg.example.com
<VirtualHost *:80>
ServerName stg.example.com
DocumentRoot /var/www/vhosts/stg.example.com/html
ErrorLog /var/log/httpd/stg.example.com/stg.example.com-error_log
CustomLog /var/log/httpd/stg.example.com/stg.example.com-access_log combined env=!nolog
<Directory /var/www/vhosts/stg.example.com/html>
AllowOverride All
DirectoryIndex index.html index.php
Options Includes FollowSymLinks ExecCGI
Require all granted
</Directory>
SetEnv CAKE_ENV stg
</VirtualHost>
#dev.example.com
<VirtualHost *:80>
ServerName dev.example.com
DocumentRoot /var/www/vhosts/dev.example.com/html
ErrorLog /var/log/httpd/dev.example.com/dev.example.com-error_log
CustomLog /var/log/httpd/dev.example.com/dev.example.com-access_log combined env=!nolog
<Directory /var/www/vhosts/dev.example.com/html>
AllowOverride All
DirectoryIndex index.html index.php
Options Includes FollowSymLinks ExecCGI
Require all granted
</Directory>
SetEnv CAKE_ENV dev
</VirtualHost>
|
ssl.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101 | #www.example.com
<VirtualHost *:443>
SSLEngine on
SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
SSLCertificateFile /etc/pki/tls/certs/localhost.crt
SSLCACertificateFile /etc/pki/tls/certs/ca-bundle.crt
#SSLCertificateKeyFile /etc/httpd/ssl/ssl.key/www.example.com.2016.key
#SSLCertificateFile /etc/httpd/ssl/ssl.crt/www.example.com.2016.crt
#SSLCACertificateFile /etc/httpd/ssl/ssl.crt/IntermediateCA.crt
SSLProtocol ALL
SSLCipherSuite ALL
ServerName www.example.com
ServerAlias example.com
DocumentRoot /var/www/vhosts/www.example.com/html
ErrorLog /var/log/httpd/www.example.com/www.example.com-error_log
CustomLog /var/log/httpd/www.example.com/www.example.com-access_log combined env=!nolog
# cgi-binがいる場合
ScriptAlias /cgi-bin/ "/var/www/vhosts/www.example.com/cgi-bin/"
# htmlでssiを動かす(かきの Options の設定でhtml以下の設置となる)
AddHandler server-parsed .html
<Directory "/var/www/vhosts/www.example.com/html">
AllowOverride All
DirectoryIndex index.php index.html
Options Includes FollowSymLinks ExecCGI
Require all granted
</Directory>
<Files ~ "\.(cgi|shtml|phtml|php?)$">
SSLOptions +StdEnvVars
</Files>
SetEnv CAKE_ENV prod
</VirtualHost>
#stg.example.com
<VirtualHost *:443>
SSLEngine on
SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
SSLCertificateFile /etc/pki/tls/certs/localhost.crt
SSLCACertificateFile /etc/pki/tls/certs/ca-bundle.crt
#SSLCertificateKeyFile /etc/httpd/ssl/ssl.key/www.example.com.2016.key
#SSLCertificateFile /etc/httpd/ssl/ssl.crt/www.example.com.2016.crt
#SSLCACertificateFile /etc/httpd/ssl/ssl.crt/IntermediateCA.crt
SSLProtocol ALL
SSLCipherSuite ALL
ServerName stg.example.com
DocumentRoot /var/www/vhosts/stg.example.com/html
ErrorLog /var/log/httpd/stg.example.com/stg.example.com-error_log
CustomLog /var/log/httpd/stg.example.com/stg.example.com-access_log combined env=!nolog
<Directory "/var/www/vhosts/stg.example.com/html">
AllowOverride All
DirectoryIndex index.php index.html
Options Includes FollowSymLinks ExecCGI
Require all granted
</Directory>
<Files ~ "\.(cgi|shtml|phtml|php?)$">
SSLOptions +StdEnvVars
</Files>
SetEnv CAKE_ENV stg
</VirtualHost>
#dev.example.com
<VirtualHost *:443>
SSLEngine on
SSLCertificateKeyFile /etc/pki/tls/private/localhost.key
SSLCertificateFile /etc/pki/tls/certs/localhost.crt
SSLCACertificateFile /etc/pki/tls/certs/ca-bundle.crt
#SSLCertificateKeyFile /etc/httpd/ssl/ssl.key/www.example.com.2016.key
#SSLCertificateFile /etc/httpd/ssl/ssl.crt/www.example.com.2016.crt
#SSLCACertificateFile /etc/httpd/ssl/ssl.crt/IntermediateCA.crt
SSLProtocol ALL
SSLCipherSuite ALL
ServerName dev.example.com
DocumentRoot /var/www/vhosts/dev.example.com/html
ErrorLog /var/log/httpd/dev.example.com/dev.example.com-error_log
CustomLog /var/log/httpd/dev.example.com/dev.example.com-access_log combined env=!nolog
<Directory "/var/www/vhosts/dev.example.com/html">
AllowOverride All
DirectoryIndex index.php index.html
Options Includes FollowSymLinks ExecCGI
Require all granted
</Directory>
<Files ~ "\.(cgi|shtml|phtml|php?)$">
SSLOptions +StdEnvVars
</Files>
SetEnv CAKE_ENV dev
</VirtualHost>
|
/etc/logrotate.d/httpd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29 | /var/log/httpd/*/*log {
daily
rotate 1
create
missingok
notifempty
sharedscripts
postrotate
/bin/systemctl reload httpd.service > /dev/null 2>/dev/null || true
EXT=`date +%Y%m%d -d '1 days ago'`
TODAY=`date +%Y%m%d`
for f in $1;
do
if [ -e $f-$TODAY ] ; then
gzip $f-$TODAY;
mv $f-$TODAY.gz $f.$EXT.gz;
fi
done
endscript
}
#/var/log/httpd/*log {
# missingok
# notifempty
# sharedscripts
# delaycompress
# postrotate
# /bin/systemctl reload httpd.service > /dev/null 2>/dev/null || true
# endscript
#}
|
/etc/fail2ban/jail.d/local.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26 | [DEFAULT]
banaction = firewallcmd-ipset
backend = systemd
ignoreip = 127.0.0.1 39.110.214.232 183.177.131.178
[sshd]
enabled = true
[apache-ddos]
enabled = true
port = http,https
# フィルタ名
filter = apache-ddos
# 監視するログ名
logpath = /var/log/httpd/www.example.com/www.example.com-access_log
# 許容する接続回数
# 5回以上不正に接続するとBANされる
maxretry = 10
# 不正アクセスカウント時間
# 3秒(3)
findtime = 3
# BANした後、再び接続できるようになるまでの時間(秒)
# 86400秒 = 1日
bantime = 86400
backend = polling
|
/etc/fail2ban/filter.d/apache-ddos.conf
| [Definition]
failregex = ^<HOST> -.*"(GET|POST).*
ignoreregex = \.(?i)(jpe?g|gif|png|bmp|pdf|js|css|woff|eot|ttf|ico|txt|xml|swf|xlsx?|docx?|pptx?|webp)
|
/etc/postfix/main.cf (要調整)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67 | # diff main.cf main.cf.org
94c94
< myhostname = toss.tenshindo.ne.jp
---
> #myhostname = host.domain.tld
102c102
< mydomain = toss.tenshindo.ne.jp
---
> #mydomain = domain.tld
117c117
< myorigin = $myhostname
---
> #myorigin = $myhostname
132c132
< inet_interfaces = all
---
> #inet_interfaces = all
135c135
< #inet_interfaces = localhost
---
> inet_interfaces = localhost
183c183
< #mydestination = $myhostname, localhost.$mydomain, localhost
---
> mydestination = $myhostname, localhost.$mydomain, localhost
187d186
< mydestination = $myhostname, localhost
284c283
< mynetworks = 168.100.189.0/28, 127.0.0.0/8
---
> #mynetworks = 168.100.189.0/28, 127.0.0.0/8
316c315
< relay_domains = $mydestination
---
> #relay_domains = $mydestination
710,712c709
< #smtpd_tls_cert_file = /etc/pki/tls/certs/postfix.pem
<
< smtpd_tls_cert_file = /etc/letsencrypt/live/toss.tenshindo.ne.jp/privkey.pem
---
> smtpd_tls_cert_file = /etc/pki/tls/certs/postfix.pem
718c715
< #smtpd_tls_key_file = /etc/pki/tls/private/postfix.key
---
> smtpd_tls_key_file = /etc/pki/tls/private/postfix.key
723d719
< smtp_tls_security_level = may
729c725
< #smtp_tls_CApath = /etc/pki/tls/certs
---
> smtp_tls_CApath = /etc/pki/tls/certs
735c731
< #smtp_tls_CAfile = /etc/pki/tls/certs/ca-bundle.crt
---
> smtp_tls_CAfile = /etc/pki/tls/certs/ca-bundle.crt
741,744d736
< smtp_tls_note_starttls_offer = yes
< smtpd_tls_loglevel = 1
< smtpd_tls_received_header = yes
<
747,752d738
<
< # Milter configuration
< milter_default_action = accept
< milter_protocol = 6
< smtpd_milters = inet:127.0.0.1:8891
< non_smtpd_milters = $smtpd_milters
|
/etc/postfix/master.cf (要調整)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 | ※技術メモ※
# encrypt だと必ず暗号化求められるので必要な時だけの may にする
#smtpd_tls_security_level = may
# Outlook用の設定ぽい、Some clients, namely Outlook [Express] prefer the "wrapper" mode. This is true for OE (Win32 < 5.0 and Win32 >=5.0 when run on a port<>25 and OE (5.01 Mac on all ports).
# win32 できてるから、win64の今だとコメントアウトのままでいい気がする。
# -o smtpd_tls_wrappermode=yes
# diff master.cf master.cf.org
17,19c17,19
< submission inet n - n - - smtpd
< -o syslog_name=postfix/submission
< -o smtpd_tls_security_level=may
---
> #submission inet n - n - - smtpd
> # -o syslog_name=postfix/submission
> # -o smtpd_tls_security_level=encrypt
29,31c29,31
< smtps inet n - n - - smtpd
< -o syslog_name=postfix/smtps
< -o smtpd_tls_wrappermode=yes
---
> #smtps inet n - n - - smtpd
> # -o syslog_name=postfix/smtps
> # -o smtpd_tls_wrappermode=yes
|
以下ログメモ
ssh-keygen Log 全部そのままenter
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 | [user_name@tk2-404-43127 ~]$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/user_name/.ssh/id_rsa):
Created directory '/home/user_name/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/user_name/.ssh/id_rsa.
Your public key has been saved in /home/user_name/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:vdCZkfNb3cMdeU7Isg1KYAUFeziXPzjpUHPlSlwkRsY user_name@tk2-404-43127.vs.sakura.ne.jp
The key's randomart image is:
+---[RSA 3072]----+
| ==oo=.+ |
| . + *E* ..|
| + @ * +oo|
| O # *.+=|
| S X * oo=|
| + o + .|
| o . |
| |
| |
+----[SHA256]-----+
|
openssl
1
2
3
4
5
6
7
8
9
10
11
12 | Country Name (2 letter code) [XX]:JP
State or Province Name (full name) []:Fukuoka
Locality Name (eg, city) [Default City]:Fukuoka-shi
Organization Name (eg, company) [Default Company Ltd]:Example Inc.
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:www.example.com
Email Address []:
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
|
MariaDB 10.4
| [root@tk2-404-43127 src]# curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash -s -- --mariadb-server-version="mariadb-10.4"
[info] Repository file successfully written to /etc/yum.repos.d/mariadb.repo
[info] Adding trusted package signing keys...
[info] Successfully added trusted package signing keys
|