2021/12/29
CentOS8
## 使用環境
- サーバー:さくらのVPN(CentOS8)
- ドメイン:お名前.com
## 初期設定
### アップデート
- yum
```
yum update
```
- dnf
```
dnf update
```
### ユーザー設定
- 作業用ユーザー追加
```
adduser testuser
```
- パスワード設定
```
passwd testuser
```
- sudo権限付加
```
usermod -aG wheel testuser
```
- rootユーザーのSSH接続不可
`/etc/ssh/sshd_config`
```conf
- #PermitRootLogin yes
+ PermitRootLogin no
```
```
systemctl restart sshd.service
```
- sshキー設定
```
su [sshキー設定したいユーザー]
mkdir ~/.ssh
chmod 700 ~/.ssh
cd ~/.ssh
ssh-keygen
```
```
mv ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
sudo systemctl restart sshd
```
*※ id_rsaを使用してSSH接続する*
** パスワードなしでsudo実行 **
1. `sudo visudo`
2.
```conf
- %wheel ALL=(ALL) ALL
+ %wheel ALL=(ALL) NOPASSWD: ALL
```
### インストール
- インストール済み一覧
```
yum list installed
```
#### PHP (バージョン指定)
*※ CentOS8は7.2がデフォルト*
1. 現在有効なバージョンを確認
```
dnf module list php
```
1. ほかのバージョンが有効な場合、リセット
```
dnf module reset php
```
1. 有効にしたいバージョンを有効にする
```
dnf module enable php:7.4
```
1. インストール
```
dnf module -y install php:7.4
```
#### MariaDB
1. 初期化
```
mysql_secure_installation
```
1. `/etc/my.cnf.d/mariadb-server`を修正
```conf
+ character-set-server = utf8
```
1. 起動
```
systemctl start mariadb
```
1. 接続
```
mysql -u root -p
```
1. ユーザー追加
```
CREATE USER 'ユーザー名'@'ホスト名' IDENTIFIED BY 'パスワード';
```
1. ユーザー確認
```
SELECT Host, User, Password FROM user;
```
1. 権限付与
```
GRANT ALL ON データベース名.* TO 'ユーザー名'@'ホスト名';
```
1. 権限確認
```
SHOW GRANTS FOR 'ユーザー名'@'ホスト名' ;
```
*参考*
- rootユーザーパスワード変更(初期化でできない場合)
```
use mysql;
ALTER USER 'root'@'localhost' IDENTIFIED BY "パスワード";
```
- https://mariadb.perlzemi.com/blog/20200616142021.html
### サービス設定
- 自動起動サービス
- 確認
```
systemctl list-unit-files
```
- 登録
```
sudo systemctl enable firewalld
```
### firewall
- 確認
```
firewall-cmd --list-all
```
- http, https 登録
```
firewall-cmd --add-service=http --zone=public --permanent
firewall-cmd --add-service=https --zone=public --permanent
```
### Let’s EncryptでSSL化
1. EPELリポジトリを有効にする
```
dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm
```
1. Certbotのインストール
```
dnf install -y python36 certbot python3-certbot-apache
```
1. 新しいSSL証明書をリクエストする
```
certbot --apache
```
```
# certbot --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): webmaster@example.com ←あなたのメールアドレス
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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. Do you agree?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: y ←規約に同意
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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: n ←メールとかは要らない
Account registered.
Which names would you like to activate HTTPS for?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: [ホスト名].sakura.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): ←何も入力しない
Requesting a certificate for [ホスト名].sakura.ne.jp
Performing the following challenges:
http-01 challenge for [ホスト名].sakura.ne.jp
Waiting for verification…
Cleaning up challenges
Created an SSL vhost at /etc/httpd/conf.d/default-le-ssl.conf
Deploying Certificate to VirtualHost /etc/httpd/conf.d/default-le-ssl.conf
Redirecting vhost in /etc/httpd/conf.d/default.conf to ssl vhost in /etc/httpd/conf.d/default-le-ssl.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://[ホスト名].sakura.ne.jp
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
IMPORTANT NOTES:
- Congratulations! Your certificate and chain have been saved at:
/etc/letsencrypt/live/[ホスト名].sakura.ne.jp/fullchain.pem
Your key file has been saved at:
/etc/letsencrypt/live/[ホスト名].sakura.ne.jp/privkey.pem
Your certificate will expire on 2021-04-16. To obtain a new or
tweaked version of this certificate in the future, simply run
certbot again with the "certonly" option. 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
```
1. `http://`でアクセスして`https://`にリダイレクトすることを確認
### Laravel構築
1. wgetインストール(composerインストールのため)
```
dnf install -y wget
```
1. composerインストール
1. インストーラーをダウンロード
```
wget https://getcomposer.org/installer -O composer-installer.php
```
1. インストール
```
php composer-installer.php --filename=composer --install-dir=/usr/local/bin
```
1. アップデート
```
composer self-update
```
1. 確認
```
composer -v
```
1. インストーラー削除
```
rm -f composer-installer.php
```
1. nodejs、npmインストール
1. モジュール確認
```
dnf module list nodejs
```
1. インストール
```
dnf module install -y nodejs
```
1. 確認
```
node -v
```
```
npm -v
```
1. composerまたはgitでlaravelをインストール
*参考*
- https://mikepon.jp/centos8_laravel/
- https://sourceexample.com/article/jp/86264ebb1ee9708f03690619b2bd9884/