みちのいに!!

自分のメモと、他にもハマる人がいそうなことを書く

くれはちゃん育成日記3日目(お名前VPSに入れたArchLinuxを設定する話)

くれはちゃん育成日記2日目(お名前VPSに入れたArchLinuxを設定する話) - みちのいに

の続きです

iplist_check.shを毎日実行するためにcron……ではなくSystemd/timersを設定します。

参考 
Logwatchをsystemd timerで日次処理する | netanote.com
systemd/Timers (日本語) - ArchWiki
systemdでの定期実行(timerユニット) - Qiita
Systemd入門(4) - serviceタイプUnitの設定ファイル - めもめも

cd /etc/systemd/system

iplist.service を作る。

[Unit]
Description=update iplist and iptables

[Service]
Type=simple
ExecStart=/bin/sh /root/script/iplist_check.sh

[Install]
WantedBy = timers.target

iplist.timer を作る。

[Unit]
Description=update iplist and reflect iptables

[Timer]
OnBootSec = 5m
OnUnitActiveSec = 1d
[Install]
WantedBy=timers.target
#timerを実行
systemctl enable iplist.timer

ntp設定

普段使いのArch Linux: Arch Linuxで時刻同期 | NTP, systemd-timesyncd
Network Time Protocol daemon (日本語) - ArchWiki

pacman -S ntp

/etc/ntp.confを変更

server ntp.nict.jp iburst
server ntp1.jst.mfeed.ad.jp iburst
server ntp2.jst.mfeed.ad.jp iburst
server ntp3.jst.mfeed.ad.jp iburst

お好みで

systemctl daemon-reload
systemctl start ntpd.service
systemctl enable ntpd.service

Kernel Panic時の自動再起動

お名前.com VPS を借りて最初にやったこと(2) iptables設定、不要サービス停止 | karakaram-blog

sysctl (日本語) - ArchWikiを見ると、

Note: バージョン 207 から、systemd は /etc/sysctl.d/* と /usr/lib/sysctl.d/* の設定だけを適用するようになっています。/etc/sysctl.conf をカスタマイズしていた場合は、ファイルの名前を /etc/sysctl.d/99-sysctl.conf のように変更する必要があります。

とあるので、

mv /etc/sysctl.conf /etc/sysctl.d/99-sysctl.conf

ここに

kernel.panic = 10

を追記して実行すると

sysctl: cannot open "/etc/sysctl.conf": No such file or directory

…………は?

# sysctl --system
* Applying /usr/lib/sysctl.d/50-coredump.conf ...
kernel.core_pattern = |/usr/lib/systemd/systemd-coredump %p %u %g %s %t %e
* Applying /usr/lib/sysctl.d/50-default.conf ...
kernel.sysrq = 16
kernel.core_uses_pid = 1
(略)
* Applying /etc/sysctl.d/99-sysctl.conf ...
net.ipv4.icmp_echo_ignore_broadcasts = 1
net.ipv4.tcp_syncookies = 1
kernel.panic = 10
* Applying /etc/sysctl.conf ...
sysctl: cannot open "/etc/sysctl.conf": No such file or directory

とのことなので読んでくれてる気はするんですが……

とりあえず空ファイル置いておきます

nginx

pacman -S nginx

設定はこんな感じにしました。
CentOSで設定した時のファイルを持ってきたので、archに入れた時の初期ファイルとは少し違った構成になってます。
この段階でPHP投入にも備えていきます
/etc/nginx/conf.d/default.conf

server {
    listen       80;
    server_name  hogehoge.com;
    #access_log  /var/log/nginx/log/host.access.log  main;
    index index.html index.htm index.php index.xht;
    location / {
        root   /var/www/hogehoge.com;
        index  index.html index.htm index.php;
    }

    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /var/www/hogehoge.com;
    }

    location ~ \.php$ {
        root           /var/www/hogehoge.comw;
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include        /etc/nginx/fastcgi.conf;
    }

}

/etc/nginx/nginx.conf

user  nginx;
worker_processes  3;

error_log  /var/log/nginx/error.log warn;
#pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    keepalive_timeout  65;

    #gzip  on;

    include /etc/nginx/conf.d/*.conf;
    server_tokens off;
}

途中

getpwnam(“nginx”) failed

に見舞われたので、
NGINX-1.5.12. コンパイル インストール手順 | Face-WEB

groupadd nginx
useradd -g nginx nginx
usermod -s /bin/false nginx
起動
systemctl start nginx
systemctl enable nginx

nginxにphp

参考 CentOSにてnginxでPHPを動かす - Qiita
https://wiki.archlinux.org/index.php/Nginx_%28%E6%97%A5%E6%9C%AC%E8%AA%9E%29
ArchLinuxでnginx + php (php-fpm)とか - opamp_sando's blog

SQLite大好きマンなのでSQLiteも使えるようにします。

pacman -S php
pacman -S php-fpm
pacman -S php-sqlite

/etc/php/php.ini

open_basedir = /var/www/

アンコメント
extension=sqlite3.so

/etc/php/php-fpm.conf

#/etc/nginx/nginx.conf のuserと一致させる
user = nginx
group = nginx

listen = 127.0.0.1:9000
#↑もうひとつのlistenはコメントアウトする

#アンコメント
listen.allowed_clients = 127.0.0.1
systemctl start php-fpm
systemctl enable php-fpm
<?php phpinfo();

とでも書いたphpをアップロードして開いて確認する。


お疲れ様でした。これで当初の目標(nginxでphpを動くようにする)は完遂です。
これからもくれはちゃんをどんどん育てあげようと思います。