プロジェクト

全般

プロフィール

Wiki » 履歴 » バージョン 1

廣瀬 僚一, 2024/01/30 19:05

1 1 廣瀬 僚一
# サーバー情報
2
- ホスティング会社:xserver vps
3
- IP:162.43.32.188
4
- OS:Rocky Linux 9.2
5
- ログイン:root / clear!3831#
6
7
初期設定の段階で2GBのスワップ領域あり(xserver vpsの仕様?)
8
9
# 構築手順
10
11
## アップデート
12
```bash
13
yum update -y
14
```
15
16
## ユーザー作成
17
```bash
18
useradd webadmin
19
passwd webadmin
20
cld3831#
21
```
22
23
## 全体設定
24
SELinuxの無効化
25
```bash
26
vi /etc/selinux/config
27
```
28
```conf:config
29
#SELINUX=enforcing
30
```
31
32
## NGINX設定
33
### NGINXインストール
34
```bash
35
dnf install nginx -y
36
systemctl start nginx && systemctl enable nginx
37
```
38
### confファイル
39
公式を参考に記載
40
```conf:80.conf
41
server {
42
    listen 80;
43
    listen [::]:80;
44
    server_name sys.globalgenetics.jp;
45
    root /var/www/hmtl/sys.globalgenetics.jp/public;
46
 
47
    add_header X-Frame-Options "SAMEORIGIN";
48
    add_header X-Content-Type-Options "nosniff";
49
 
50
    index index.php;
51
 
52
    charset utf-8;
53
 
54
    location / {
55
        try_files $uri $uri/ /index.php?$query_string;
56
    }
57
 
58
    location = /favicon.ico { access_log off; log_not_found off; }
59
    location = /robots.txt  { access_log off; log_not_found off; }
60
 
61
    error_page 404 /index.php;
62
 
63
    location ~ \.php$ {
64
        fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
65
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
66
        include fastcgi_params;
67
    }
68
 
69
    location ~ /\.(?!well-known).* {
70
        deny all;
71
    }
72
}
73
```
74
75
## PHP設定
76
インストールできるphpを確認  
77
php8.1などをインストールする
78
```bash
79
dnf module list php #利用できるphpを検索
80
dnf module install php -y
81
dnf install php-bcmath php-pdo php-mysql php-gd -y
82
```
83
### confファイル
84
```bash:www.conf
85
user=nginx
86
group=nginx
87
88
pm = static
89
pm.max_children = 3
90
pm.max_requests = 1000
91
```
92
93
## php.ini設定
94
```bash:php.ini
95
max_execution_time = 300
96
memory_limit = 256M
97
upload_max_filesize = 20M
98
post_max_size = 128M
99
```
100
101
## データベース設定
102
### mysqlインストール
103
```bash
104
dnf install mysql -y
105
dnf install mysql-server -y
106
```
107
データベース名:globalgenetics
108
| User     | Pass       |
109
| -------- | ---------- |
110
| root     | Clear.3831 |
111
| db_admin | Cld3831#   |
112
113
```bash
114
mysql -u root -p{DB_ROOT_PASS} -h ${DB_HOST}
115
```
116
```sql
117
CREATE DATABASE [DB_NAME] DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
118
CREATE USER '[DB_USER]'@'[DB_HOST]' identified by '[DB_PASS]';
119
GRANT ALL ON [DB_NAME].*TO '[DB_USER]'@'[DB_HOST]';
120
FLUSH PRIVILEGES;
121
```
122
123
## composerインストール
124
```bash
125
cd ~
126
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
127
php -r "if (hash_file('sha384', 'composer-setup.php') === 'e21205b207c3ff031906575712edab6f13eb0b361f2085f1f1237b7126d785e826a450292b6cfd1d64d92e6563bbde02') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
128
php composer-setup.php
129
php -r "unlink('composer-setup.php');"
130
mv composer.phar /usr/local/bin/composer
131
composer -V
132
```
133
134
## Node.jsインストール
135
バージョン指定してインストール(16.x)
136
```bash
137
yum install https://rpm.nodesource.com/pub_16.x/nodistro/repo/nodesource-release-nodistro-1.noarch.rpm -y
138
yum install nodejs -y --setopt=nodesource-nodejs.module_hotfixes=1
139
140
node -v
141
npm -v
142
```
143
144
## サイトデータ配置
145
ディレクトリを作成
146
```bash
147
mkdir -p /var/www/html/sys.globalgenetics.jp/
148
149
cd /var/www/html/sys.globalgenetics.jp/
150
chmod -R 777 ./storage
151
```
152
envファイルの書き換え
153
- APP_URL
154
- DB_HOST
155
- DB_USERNAME
156
- DB_PASSWORD
157
158
```bash
159
chown -R nginx:nginx /var/www/html/sys.globalgenetics.jp/storage/app/public/uploads/
160
```
161
162
HTTPでアクセスして、アクセスできることを確認
163
164
## SSL設定
165
### epelリポジトリインストール
166
```bash
167
yum install epel-release.noarch -y
168
```
169
### certbotインストールとSSL化
170
```bash
171
dnf install certbot -y
172
certbot certonly --webroot -w /var/www/html/sys.globalgenetics.jp/public -d sys.globalgenetics.jp --email wp@clear-design.jp --debug
173
```
174
### nginx confファイルの作成と書き換え
175
```bash
176
vi /etc/nginx/conf.d/80.conf
177
```
178
```conf:80.conf
179
server {
180
    listen 80;
181
    listen [::]:80;
182
    server_name sys.globalgenetics.jp;
183
184
    return 301 https://$host$request_uri;    
185
}
186
```
187
188
```bash
189
vi /etc/nginx/conf.d/sys_global.conf
190
```
191
```conf:sys_global.conf
192
server {
193
    listen 443 ssl http2;
194
    listen [::]:443 ssl http2;
195
    server_name sys.globalgenetics.jp;
196
    root /var/www/html/sys.globalgenetics.jp/public;
197
 
198
    add_header X-Frame-Options "SAMEORIGIN";
199
    add_header X-Content-Type-Options "nosniff";
200
 
201
    ssl_certificate /etc/letsencrypt/live/sys.globalgenetics.jp/fullchain.pem;
202
    ssl_certificate_key /etc/letsencrypt/live/sys.globalgenetics.jp/privkey.pem;
203
204
    index index.php;
205
 
206
    charset utf-8;
207
 
208
    location / {
209
        try_files $uri $uri/ /index.php?$query_string;
210
    }
211
 
212
    location = /favicon.ico { access_log off; log_not_found off; }
213
    location = /robots.txt  { access_log off; log_not_found off; }
214
 
215
    error_page 404 /index.php;
216
 
217
    location ~ \.php$ {
218
        fastcgi_pass unix:/var/run/php-fpm/www.sock;
219
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
220
        include fastcgi_params;
221
    }
222
 
223
#    location ~ /\.(?!well-known).* {
224
#        deny all;
225
#    }
226
}
227
```
228
229
## メール設定
230
XSERVERにリレーし、メールを配信する
231
232
### メールアドレスの作成
233
XSERVER(cld01)で、グローバルジェネティクスドメインでメールアドレスを作成する。  
234
noreply@globalgenetics.jp  
235
パスワードも設定する
236
237
### postfixインストール
238
```bash
239
dnf install postfix -y
240
systemctl start postfix.service && systemctl enable postfix.service
241
```
242
その他、必要なものをインストール
243
```bash
244
dnf install cyrus-sasl-plain cyrus-sasl-lib cyrus-sasl-md5
245
```
246
247
### postfix設定(補足)
248
```bash
249
vi /etc/postfix/main.cf
250
```
251
以下を書き換え
252
```bash:main.cf
253
myhostname = globalgenetics.jp
254
mydomain = globalgenetics.jp
255
```
256
以下を末尾に追記
257
```bash:main.cf
258
milter_default_action = accept
259
non_smtpd_milters = $smtpd_milters
260
smtpd_milters = inet:127.0.0.1:8891
261
262
relayhost = [sv1116.xserver.jp]:587
263
smtp_sasl_auth_enable = yes
264
smtp_sasl_security_options = noanonymous
265
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
266
smtp_use_tls = yes
267
smtp_tls_note_starttls_offer = yes
268
```
269
```bash
270
vi /etc/postfix/sasl_passwd #メール認証情報の記載
271
```
272
```bash:sasl_passwd
273
[sv1116.xserver.jp]:587 作成したメールアドレス:パスワード
274
```
275
```bash
276
chmod 600 /etc/postfix/sasl_passwd
277
postmap /etc/postfix/sasl_passwd #認証情報のハッシュ化・登録
278
systemctl restart postfix.service
279
```
280
下記コマンドでテストメールの送信  
281
迷惑メールに入らずに受信できていれば完了
282
```bash
283
sendmail -t << EOL
284
From: 送信元メールアドレス
285
To: 送信先メールアドレス
286
Subject: メールタイトル
287
本文
288
EOL
289
```
290
291
## rootログイン禁止
292
```bash
293
PermitRootLogin no
294
```
295
296
---
297
## zabbix-agentインストール
298
```bash
299
dnf install zabbix-agent.x86_64 -y
300
```
301
302
## PHPキャッシュ
303
```bash
304
dnf install php-opcache php-pecl-apcu -y
305
```
306
負荷テスト
307
```bash
308
ab -n 100 -c 100 https://sys.globalgenetics.jp/
309
```
310
結果  
311
before
312
```
313
Total transferred:      162500 bytes
314
HTML transferred:       38600 bytes
315
Requests per second:    27.75 [#/sec] (mean)
316
Time per request:       3603.657 [ms] (mean)
317
Time per request:       36.037 [ms] (mean, across all concurrent requests)
318
Transfer rate:          44.04 [Kbytes/sec] received
319
```
320
after
321
```
322
Total transferred:      162500 bytes
323
HTML transferred:       38600 bytes
324
Requests per second:    128.77 [#/sec] (mean)
325
Time per request:       776.571 [ms] (mean)
326
Time per request:       7.766 [ms] (mean, across all concurrent requests)
327
Transfer rate:          204.35 [Kbytes/sec] received
328
```