一.簡介
piwik現已改名為Matomo,這是一套國外著名的開源網站統計系統,類似於百度統計、Google Analytics等系統。可以分析流量、訪客數、PV、UV等信息。
Matomo相當於將流量復制了一份進行分析,所以對配置的要求比較高,盡量和負載均衡所在機器的配置一樣。matomo的使用非常簡單清晰,在部署后多點點就可以熟悉了。
二.程序部署
環境聲明
[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.語言默認英文,可選中文
3.系統檢查是否滿足條件
4.數據庫配置
5.建表(piwik會自動建表)
6.設置超級賬戶
7.設置網站
8.跟蹤代碼,將生成的代碼復制粘貼到要跟蹤的頁面標簽之前,要注意這里的網址要填寫被追蹤網站的域名
9.安裝完成
四.配置redis擴展
默認這個是非常慢的,性能高也扛不住,還是很卡。推薦安裝redis擴展,就非常快了。
1.安裝redis和依賴
yum -y install php72w-pecl-redis redis
systemctl start redis
systemctl enable redis
2.在matomo操作界面上,菜單路徑是:系統=》插件,拖到頁面最下方,添加一個新的插件,然后在搜索框里面輸入Queued Tracking字樣,然后點擊安裝即可。
在系統=》通用設置中找到QueuedTracking設置。redis相關設置中,注意里面的有個選項:Enable Redis Sentinel,這個配置不要勾選。
設置好端口和密碼