网站访问统计Matomo(Piwik)部署


一.简介

piwik现已改名为Matomo,这是一套国外著名的开源网站统计系统,类似于百度统计、Google Analytics等系统。可以分析流量、访客数、PV、UV等信息。

Matomo相当于将流量复制了一份进行分析,所以对配置的要求比较高,尽量和负载均衡所在机器的配置一样。matomo的使用非常简单清晰,在部署后多点点就可以熟悉了。
file

二.程序部署

环境声明

[matomo-Server]
    主机名 = host-1
    系统 = centos-7.3
    地址 = 1.1.1.1
    软件 = php-7.2 9000
           mysql-5.7 3306
           nginx-1.16 80
		   matomo-3.13.4

部署

1.安装epel扩展
rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

2.安装php7.2和相关模块
yum -y install wget unzip php72w php72w-cli php72w-common php72w-devel yum-utils php-mysqli php72w-fpm php72w-redis php72w-pecl-redis php72w-mbstring php72w-gd nginx

启动并加入自启动中
systemctl start php-fpm
systemctl enable php-fpm

3.配置nginx支持php
vim /etc/nginx/nginx.conf

    server {
        listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  xx.xxx.cn;   #这里要改成对应域名,本地的话改成ip也行
        root         /etc/nginx/matomo;  #php文件所在目录

        include /etc/nginx/default.d/*.conf;

        location / {
          index index.php index.html index.htm; #加入index.php
        }

        error_page 404 /404.html;

        location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  /etc/nginx/matomo$fastcgi_script_name; #变更php目录
        include        fastcgi_params;
    }

            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }

4.下载官方包
mkdir /etc/nginx/matomo
cd /etc/nginx/matomo/
wget http://builds.piwik.org/piwik.zip
unzip piwik

若下载官方缓慢,可下载社区缓存的固定版本包
wget https://shell-auto-install.oss-cn-zhangjiakou.aliyuncs.com/package/piwik.zip

启动nginx并加入自启动
systemctl start nginx
systemctl enable nginx

5.参照文档安装mysql-5.7,并添加权限
chown -R apache:apache /etc/nginx/matomo/piwik

登陆后创建数据库

[root@linkops ~]# mysql -uroot -p
mysql> create database piwik;
mysql> grant all on piwik.* to piwik@localhost identified by 'china';
mysql> flush privilege

三.图形设置

1.登陆http://1.1.1.1/piwik

2.语言默认英文,可选中文
file

3.系统检查是否满足条件
file

4.数据库配置
file

5.建表(piwik会自动建表)
file

6.设置超级账户
file

7.设置网站
file

8.跟踪代码,将生成的代码复制粘贴到要跟踪的页面标签之前,要注意这里的网址要填写被追踪网站的域名
file

9.安装完成
file

四.配置redis扩展

默认这个是非常慢的,性能高也扛不住,还是很卡。推荐安装redis扩展,就非常快了。

1.安装redis和依赖
yum -y install php72w-pecl-redis redis
systemctl start redis
systemctl enable redis

2.在matomo操作界面上,菜单路径是:系统=》插件,拖到页面最下方,添加一个新的插件,然后在搜索框里面输入Queued Tracking字样,然后点击安装即可。
file

在系统=》通用设置中找到QueuedTracking设置。redis相关设置中,注意里面的有个选项:Enable Redis Sentinel,这个配置不要勾选。
file

设置好端口和密码
file


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM