PHP Server Monitor 是一套用來監控服務存活的工具、操作簡單,最近開始支援以Telegram發送通知,十分好用!
以下紀錄CenoOS從搭建LNMP到安裝PHP Server Monitor過程

安裝remi套件

#sudo yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm

啟用php7.3

#sudo vim /etc/yum.repos.d/remi-php73.repo
[remi-php73]
name=Remi's PHP 7.3 RPM repository for Enterprise Linux 7 - $basearch
mirrorlist=http://cdn.remirepo.net/enterprise/7/php73/mirror
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi

安裝nginx php-fpm mariadb 及一些工具

#sudo yum -y install nginx php73 php-fpm php-cli php-mysqlnd php-pdo mariadb-server htop mlocate wget yum-utils yum-cron telnet net-tools setools-console policycoreutils-python unzip

因為是架在GCP免費方案上,所以設定個swap。

#sudo dd if=/dev/zero of=/swap bs=1024 count=1024k
#sudo mkswap swap
#sudo swapon swap
#sudo chmod 0600 swap
#sudo vim /etc/sysctl.conf 
vm.swappiness=80
#sudo sysctl vm.swappiness=80
#sudo vim /etc/fstab
/swap   swap    swap    defaults        0 0 

開始設定服務

#sudo systemctl enable nginx php-fpm mariadb
#sudo systemctl start nginx php-fpm mariadb

設定mariadb
#mysql_secure_installation
除了自訂密碼輸入2次,一路Enter

建DB、用戶
#mysql -uroot -p
> create database servermonitor character set utf8 collate utf8_general_ci;
> grant all on servermonitor.* to monitor@localhost identified by 'password';
> flush privileges;
> exit

設定php.ini
#vim /etc/php.ini
date.timezone = Asia/Taipei
output_buffering = Off
expose_php = off
short_open_tag = On

設定php-fpm
#vim /etc/php-fpm.d/www.conf
user = nginx
group = nginx
取消以下註解
;env[HOSTNAME] = $HOSTNAME
;env[PATH] = /usr/local/bin:/usr/bin:/bin
;env[TMP] = /tmp
;env[TMPDIR] = /tmp
;env[TEMP] = /tmp

設定nginx
#vim /etc/nginx/nginx.conf

server是80 443底下都改
location / {
        index index.php index.html index.htm;
        try_files $uri $uri/ /index.php?$args;
}

add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
server_tokens off;

location ~ \.php$ {
        try_files $uri =404;
        #fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_namwget e;
        include fastcgi_params;
}

建立憑證

#sudo openssl req -new -x509 -days 3650 -nodes -out /etc/pki/nginx/server.crt -keyout /etc/pki/nginx/private/server.key

安裝php server monitor

#cd /usr/share/nginx/html
#sudo git clone https://github.com/phpservermon/phpservermon.git
#mv /phpservermon/* ./
#sudo yum install php-xml
#sudo php composer.phar install
#systemctl restart nginx php-fpm

打開 https:/server_ip/install.php 跳出如下,按「Let`s go」

下圖一直打不成功,所以直接手改config.php

#vim config.php
<?php
define('PSM_DB_PREFIX', 'xxx_');
define('PSM_DB_USER', 'abc');
define('PSM_DB_PASS', '123456');
define('PSM_DB_NAME', 'xyz');
define('PSM_DB_HOST', 'localhost');
define('PSM_DB_PORT', '3306'); //3306 is the default port for MySQL. If no specfic port is used, leave it empty.
define('PSM_BASE_URL', 'https://ip_address');

輸入登入的帳號密碼

完成

設定排程每分鐘監測

#crontab -e
*/1 * * * * /usr/bin/php /usr/share/nginx/html/cron/status.cron.php

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *