硬件监控 与 统计: PV UV IP
硬件监控
监控对象
物理硬件监控:CPU温度 风扇的转速 主板的温度 电压 功率
监控方法
IPMI #zabbix监控
ipmitool #命令行获取这些信息
#安装 ipmitool
[root@web01 ~]# yum -y install ipmitool
# ipmitool 使用方法
百度搜索:ipmitool命令使用
https://blog.youkuaiyun.com/zygblock/article/details/53367664
统计PV UV IP
统计方法
1、根据日志进行分析
2、开源软件:
matomo 自己搭建的,以前叫 piwik
js代码 开发写的
Awstates 是一个免费的强大而有个性的工具,带来先进的网络,流量,FTP或邮件服务器统计图。
GoAccess 基于终端的日志分析器
3、第三方统计:
腾讯分析 https://ta.qq.com/
百度统计
谷歌分析
matomo 搭建
搭建一个测试用论坛
命令行操作
#创建统一用户
[root@web01 ~]# groupadd -g666 www
[root@web01 ~]# useradd -u666 -g666 www
#创建站点目录
[root@web01 ~]# mkdir /code
#安装并启动 nginx
[root@web01 ~]# yum -y install nginx
systemctl start nginx
systemctl enable nginx
#安装并启动 PHP
[root@web01 ~]# yum -y install php72w php72w-cli php72w-common php72w-devel php72w-embedded php72w-gd php72w-mcrypt php72w-mbstring php72w-pdo php72w-xml php72w-fpm php72w-mysqlnd php72w-opcache php72w-pecl-memcached php72w-pecl-redis php72w-pecl-mongodb
systemctl start php-fpm
systemctl enable php-fpm
#安装并启动 mariadb 数据库
[root@web02 ~]# yum -y install mariadb-server
systemctl start mariadb-server
systemctl enable mariadb-server
#设置数据库管理员密码
[root@web02 ~]# mysqladmin -uroot password '123456'
#上传站点文件到 /code
https://www.discuz.net/ # discuz 官方网站
[root@web01 code]# ll
drwxr-xr-x 5 www www 49 Mar 31 2020 discuz
-rw-r--r-- 1 www www 10922155 Mar 30 14:40 Discuz_X3.3_SC_UTF8.zip
#用 unzip 解压 Discuz_X3.3_SC_UTF8.zip 到 /code/discuz
[root@web01 code]# unzip -q Discuz_X3.3_SC_UTF8.zip -d discuz/
[root@web01 code]# ll discuz/
total 4
drwxr-xr-x 2 www www 102 Jul 27 2017 readme
drwxr-xr-x 12 www www 4096 Jul 27 2017 upload
drwxr-xr-x 4 www www 72 Jul 27 2017 utility
#站点目录授权
[root@web01 code]# chown www.www -R www.www discuz/
#配置nginx
[root@web01 ~]# vim /etc/nginx/conf.d/discuz.conf
server {
listen 80;
server_name discuz.qls.com;
root /code/discuz/upload;
location / {
index index.php index.html;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
# nginx 使用统一用户
[root@web01 code]# vim /etc/nginx/nginx.conf
user www;
# php 使用统一用户
[root@web01 code]# vim /etc/php-fpm.d/www.conf
user = www
group = www
#创建 discuz 数据库
[root@web01 /code]# mysql -uroot -p123456
MariaDB [(none)]> create database discuz;
MariaDB [(none)]> exit #退出数据库
#重启 nginx php-fpm mariadb
[root@web01 code]# systemctl restart nginx php-fpm mariadb
discuz 页面配置
#配置windows系统的解析【增加2行】
C:\Windows\System32\drivers\etc\hosts
10.0.0.7 discuz.qls.com
10.0.0.8 matomo.qls.com
#访问 discuz 页面
http://discuz.qls.com/
如果下图有 红色X 出现,就返回检查上面的步骤,可能是站点目录没有授权www
这里的admin密码是登陆网站用的密码
登陆
设置取消验证码登陆【测试网站,省的登陆麻烦】
搭建 matomo
命令行操作
#配置nginx
[root@web01 /etc/nginx/conf.d]# vim matomo.conf
server {
listen 80;
server_name matomo.qls.com;
root /code/matomo;
location / {
index index.php index.html;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
#重启nginx
systemctl restart nginx
#上传解压 matomo
[root@web01 /code]# unzip -q matomo-latest.zip
[root@web01 /code]# ll
drwxr-xr-x 5 www www 49 2020-03-30 14:40 discuz
-rw-r--r-- 1 root root 341 2020-03-24 12:25 How to install Matomo.html
drwxr-xr-x 12 root root 4096 2020-03-24 12:25 matomo
-rw-r--r-- 1 root root 19375918 2020-03-24 12:25 matomo-latest.zip
#授权 matomo 目录
[root@web01 /code]# chown -R www.www matomo
#创建 matomo 数据库和 matomo 数据库账户
[root@web01 /code]# mysql -uroot -p123456
MariaDB [(none)]> create database matomo;
MariaDB [(none)]> grant all on *.* to matomo@'localhost' identified by '123456';
matomo 页面配置
官网安装教程
https://matomo.org/docs/installation
#如果在配置页面出错时【下图】,需要检查php版本和matomo版本兼容问题,重启windows系统,更换浏览器
忽略SSL,直接下一步
下拉页面,点击下一步
复制代码
将代码粘贴到 discuz
GoAccess
1、GoAccess介绍
基于终端的快速的分析器,核心思想:实时的分析和查看web服务器的统计信息。
特点:
1. 安装简单
2. 操作容易
3. 界面酷炫
2、GoAccess安装
#官方网站
https://www.goaccess.cc/
#官方使用文档
https://www.goaccess.cc/?mod=man
#下载
[root@web01 ~]# wget https://tar.goaccess.io/goaccess-1.3.tar.gz
#解压
[root@web01 ~]# tar -xzf goaccess-1.3.tar.gz
#进入目录
[root@web01 ~]# cd goaccess-1.3/
#预编译
[root@web01 goaccess-1.3]# ./configure --enable-utf8 --enable-geoip=legacy
configure: error:
*** Missing development files for the GeoIP library
#预编译报错,需要安装依赖包
[root@web01 goaccess-1.3]# yum -y install GeoIP-devel ncurses-devel
#重新预编译
[root@web01 goaccess-1.3]# ./configure --enable-utf8 --enable-geoip=legacy
#编译安装
[root@web01 goaccess-1.3]# make && make install
#测试分析日志文件 access.log
[root@web01 ~]# goaccess -f ./access.log
+-----------------------------------------------------------+
| Log Format Configuration |
| [SPACE] to toggle - [ENTER] to proceed - [q] to quit |
| Parsing... [37,140] [0/s] - |
| [x] NCSA Combined Log Format |#选择此行按空格>回车
| [ ] NCSA Combined Log Format with Virtual Host |
| [ ] Common Log Format (CLF) |
| [ ] Common Log Format (CLF) with Virtual Host |
| [ ] W3C |
| [ ] Squid Native Format |
| |
| Log Format - [c] to add/edit format |
| %h %^[%d:%t %^] "%r" %s %b "%R" "%u" |
| |
| Date Format - [d] to add/edit format |
| %d/%b/%Y |
| |
| Time Format - [t] to add/edit format |
| %H:%M:%S |
+-----------------------------------------------------------+
#按 q 退出,? 查看帮助
#使用中文界面
[root@web01 ~]# export LANG=zh_CN.UTF8
[root@web01 ~]# goaccess -f ./access.log
+-----------------------------------------------------------+
| 日志格式设置 |
| [空格]切换 - [回车]继续 - [q]退出 |
| |
| [ ] NCSA Combined Log Format |
| [ ] NCSA Combined Log Format with Virtual Host |
| [ ] Common Log Format (CLF) |
| [ ] Common Log Format (CLF) with Virtual Host |
| [ ] W3C |
| [ ] Squid Native Format |
| |
| 日志格式 - [c]新建/修改格式 |
| |
| |
| 日期格式 - [d]新建/修改格式 |
| |
| |
| 时间格式 - [t]新建/修改格式 |
| |
+-----------------------------------------------------------+
3、Goaccess配置
#需要将这些分析的数据导出为html格式
#编辑 goaccess 配置文件
[root@web01 ~]# vim /usr/local/etc/goaccess/goaccess.conf
[root@web01 ~]# grep -Ev '^$|^#' /usr/local/etc/goaccess/goaccess.conf
time-format %H:%M:%S
date-format %d/%b/%Y
log-format %h %^[%d:%t %^] "%r" %s %b "%R" "%u"
#导出html文件
-f #指定日志文件
-o #指定导出HTML文件
-p #通过配置文件来指定日志格式
[root@web01 ~]# goaccess -f /root/access.log -o /code/log/index.html -p /usr/local/etc/goaccess/goaccess.conf
#写个定时任务 半小时 1小时
#定时将日志数据同步到GoAccess里面,
30 * * * * /usr/local/bin/goaccess -f /root/access.log -o /code/log/index.html -p /usr/local/etc/goaccess/goaccess.conf
#准备一个nginx页面
[root@web01 ~]# mkdir -p /code/log
[root@web01 ~]# goaccess -f /root/access.log -o /code/log/index.html -p /usr/local/etc/goaccess/goaccess.conf
[root@web01 ~]# ll /code/log/
-rw-r--r-- 1 root root 694780 2020-03-31 10:16 index.html
#配置 nginx 页面配置文件
[root@web01 ~]# vim /etc/nginx/conf.d/discuz.conf
[root@web01 ~]# cat /etc/nginx/conf.d/discuz.conf
server {
listen 80;
server_name localhost;
root /code/log;
location / {
index index.php index.html;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
#启动 nginx
[root@web01 ~]# systemctl restart nginx
#授权目录
[root@web01 ~]# chown -R www.www /code/log/