Matomo 统计系统安装及配置

工具2年前更新 Webmaster
969 0 0

Matomo 统计系统安装及配置
Matomo 是领先的 Free/Libre 开放分析平台。

Matomo 是一个功能齐全的基于PHP+Mysql的网站统计程序,您可以下载并安装在您自己的网络服务器上。 在五分钟的安装过程结束时,您将获得一段 JavaScript 代码。 只需将此标签复制并粘贴到您想要跟踪并实时访问分析报告的网站上即可。

Matomo 的目标是成为 Google Analytics 的免费软件替代品,目前已在超过 1,400,000 个网站上使用!

项目主页: https://wwww.webmaster.me/sites/1271.html

安装

首先在项目主页:https://github.com/matomo-org/matomo/releases 查询最新的稳定版本号,目前是4.15.0。

进入服务器准备部署的目录克隆最新的4.15.0版本:
git clone -b 4.15.0 --depth 1 https://github.com/matomo-org/matomo.git

提示:后续如果你想升级版本,比如升级到4.20.0,则进入项目目录执行命令:
git fetch origin tag 4.20.0 –no-tags –depth 1
git checkout 4.15.0

修改目录权限,允许下面三个文件/目录可以写入:
chmod -R a+w matomo/config matomo/tmp/ matomo/js/piwik.js

安装php composer:

  1. curl -sS https://getcomposer.org/installer | php
  2. mv composer.phar /usr/local/bin/composer
  3. chmod +x /usr/local/bin/composer

进入克隆的代码目录安装依赖:

  1. composer install

克隆查看详细访问日志需要的icon:

  1. cd plugins/Morpheus
  2. rm -rf icons
  3. git clone https://github.com/matomo-org/matomo-icons.git icons

配置Nginx,可以按实际情况修改:

  1. server {
  2. listen [::]:80; # remove this if you don't want Matomo to be reachable from IPv6
  3. listen 80;
  4. server_name matomo.example.com;
  5. # Redirect all HTTP requests to HTTPS with a 301 Moved Permanently response.
  6. location / {
  7. return 301 https://$host$request_uri;
  8. }
  9. }
  10. server {
  11. listen [::]:443 ssl http2; # remove this if you don't want Matomo to be reachable from IPv6
  12. listen 443 ssl http2;
  13. server_name matomo.example.com; # list all domains Matomo should be reachable from
  14. access_log /var/log/nginx/matomo.access.log;
  15. error_log /var/log/nginx/matomo.error.log;
  16.  
  17. ## uncomment if you want to enable HSTS with 6 months cache
  18. ## ATTENTION: Be sure you know the implications of this change (you won't be able to disable HTTPS anymore)
  19. #add_header Strict-Transport-Security max-age=15768000 always;
  20.  
  21. ## replace with your SSL certificate
  22. ssl_certificate /etc/letsencrypt/live/matomo.example.com/fullchain.pem;
  23. ssl_certificate_key /etc/letsencrypt/live/matomo.example.com/privkey.pem;
  24.  
  25. include ssl.conf; # if you want to support older browsers, please read through this file
  26.  
  27. add_header Referrer-Policy origin always; # make sure outgoing links don't show the URL to the Matomo instance
  28. add_header X-Content-Type-Options "nosniff" always;
  29. add_header X-XSS-Protection "1; mode=block" always;
  30.  
  31. root /var/www/matomo/; # replace with path to your matomo instance
  32.  
  33. index index.php;
  34.  
  35. ## only allow accessing the following php files
  36. location ~ ^/(index|matomo|piwik|js/index|plugins/HeatmapSessionRecording/configs)\.php$ {
  37. include snippets/fastcgi-php.conf; # fetch it from https://github.com/nginx/nginx/blob/master/conf/fastcgi.conf
  38. try_files $fastcgi_script_name =404; # protects against CVE-2019-11043. If this line is already included in your snippets/fastcgi-php.conf you can comment it here.
  39. fastcgi_param HTTP_PROXY ""; # prohibit httpoxy: https://httpoxy.org/
  40. fastcgi_pass unix:/var/run/php/php7.2-fpm.sock; #replace with the path to your PHP socket file
  41. #fastcgi_pass 127.0.0.1:9000; # uncomment if you are using PHP via TCP sockets (e.g. Docker container)
  42. }
  43.  
  44. ## deny access to all other .php files
  45. location ~* ^.+\.php$ {
  46. deny all;
  47. return 403;
  48. }
  49.  
  50. ## serve all other files normally
  51. location / {
  52. try_files $uri $uri/ =404;
  53. }
  54.  
  55. ## disable all access to the following directories
  56. location ~ ^/(config|tmp|core|lang) {
  57. deny all;
  58. return 403; # replace with 404 to not show these directories exist
  59. }
  60.  
  61. location ~ /\.ht {
  62. deny all;
  63. return 403;
  64. }
  65.  
  66. location ~ js/container_.*_preview\.js$ {
  67. expires off;
  68. add_header Cache-Control 'private, no-cache, no-store';
  69. }
  70.  
  71. location ~ \.(gif|ico|jpg|png|svg|js|css|htm|html|mp3|mp4|wav|ogg|avi|ttf|eot|woff|woff2)$ {
  72. allow all;
  73. ## Cache images,CSS,JS and webfonts for an hour
  74. ## Increasing the duration may improve the load-time, but may cause old files to show after an Matomo upgrade
  75. expires 1h;
  76. add_header Pragma public;
  77. add_header Cache-Control "public";
  78. }
  79.  
  80. location ~ ^/(libs|vendor|plugins|misc|node_modules) {
  81. deny all;
  82. return 403;
  83. }
  84.  
  85. ## properly display textfiles in root directory
  86. location ~/(.*\.md|LEGALNOTICE|LICENSE) {
  87. default_type text/plain;
  88. }
  89. }

打开浏览器,输入域名可以看到如下界面即表示安装成功,安装界面提示一步步配置即可。
Matomo 统计系统安装及配置
如果你使用的是WordPress,可以安装插件直接使用,步骤参考:https://matomo.org/faq/new-to-piwik/how-do-i-install-the-matomo-tracking-code-on-wordpress/

如果你的站点接入了Cloudflare ,可以使用Cloudflare的APP进行统计,步骤参考:https://matomo.org/faq/new-to-piwik/how-do-i-install-the-matomo-tracking-code-on-my-cloudflare-setup/

优化

1、将php.ini的memory_limit 值设置为 512M以上。

2、如果你的站点访问量较大,按照官方建议禁用实时归档,改为定时后台统计,减少服务器压力。进入后台->管理->系统->通用设置,按下图设置:
Matomo 统计系统安装及配置
添加一条cronjob计划任务,定时执行归档:
5 * * * * /usr/bin/php /path/to/matomo/console core:archive --url=http://example.org/matomo/ > /dev/null
命令中的php路径、matomo安装目录、matomo访问地址按实际情况修改。

3、在config/config.ini.php的[General]底下增加一行:
browser_archiving_disabled_enforce = 1

© 版权声明

相关文章

暂无评论

none
暂无评论...