Piwik是一个PHP和MysqL的开放源代码的Web统计软件. 它给你一些关于你的网站的实用统计报告,比如网页浏览人数,
访问最多的页面,搜索引擎关键词等等…
Piwik拥有众多不同功能的插件,你可以添加新的功能或是移除你不需要的功能,Piwik同样可以安装在你的服务器上面,数据就保存在你自己的服务器上面。你可以非常容易的插入统计图表到你的博客或是网站抑或是后台的控制面板中。安装完成后,你只需将一小段代码放到将要统计的网页中即可。- Piwik官网:https://piwik.org/
- Piwik演示:http://piwik.org/what-is-piwik/
- Piwik下载:https://piwik.org/download/
二、Piwik安装
安装网站访问分析器“Piwik”,
Piwik不同于AWStats和其他软件,它分析一个网站,因此它需要在您想要分析访问的网站上添加Java Script代码。安装MariaDB服务器
安装MariaDB 5.5(CentOS 7默认版本)以配置数据库服务器
[1] 安装MariaDB 5.5 .
[root@linuxprobe ~]# yum -y install mariadb-server
[root@linuxprobe ~]# vi /etc/my.cnf
# add follows within [MysqLd] section
[MysqLd]
character-set-server=utf8
[root@linuxprobe ~]# systemctl start mariadb
[root@linuxprobe ~]# systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.servi
#[初始化MaribDB]
[root@linuxprobe ~]# MysqL_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it,we'll need the current
password for the root user. If you've just installed MariaDB,and
you haven't set the root password yet,the password will be blank,so you should just press enter here.
Enter current password for root (enter for none):
OK,successfully used password,moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
# set root password
Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default,a MariaDB installation has an anonymous user,allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing,and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
# remove anonymous users
Remove anonymous users? [Y/n] y
... Success!
Normally,root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
# disallow root login remotely
Disallow root login remotely? [Y/n] y
... Success!
By default,MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing,and should be removed
before moving into a production environment.
# remove test database
Remove test database and access to it? [Y/n] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
# reload privilege tables
Reload privilege tables now? [Y/n] y
... Success!
Cleaning up...
All done! If you've completed all of the above steps,your MariaDB
installation should now be secure.
Thanks for using MariaDB!
用root连接到MariaDB
[root@linuxprobe ~]# MysqL -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 12
Server version: 5.5.50-MariaDB MariaDB Server
Copyright (c) 2000,2016,Oracle,MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> select user,host,password from MysqL.user;
+------+-----------+-------------------------------------------+
| user | host | password | +------+-----------+-------------------------------------------+
| root | localhost | *F1DAE8BCDFCA7A57F246E0F834AC35830A3D640E | | root | 127.0.0.1 | *F1DAE8BCDFCA7A57F246E0F834AC35830A3D640E |
| root | ::1 | *F1DAE8BCDFCA7A57F246E0F834AC35830A3D640E | +------+-----------+-------------------------------------------+
3 rows in set (0.00 sec)
MariaDB [(none)]> show databases;
+--------------------+
| Database | +--------------------+
| information_schema | | MysqL | | performance_schema |
+--------------------+
3 rows in set (0.00 sec)
MariaDB [(none)]> exit
Bye
[3]如果Firewalld正在运行,并且从远程主机使用MariaDB,请按如下所示允许服务。 MariaDB使用3306 / TCP
[root@linuxprobe ~]# firewall-cmd --add-service=MysqL --permanent
success
[root@linuxprobe ~]# firewall-cmd --reload
success
为Piwik创建数据库
[root@linuxprobe ~]# MysqL -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 13
Server version: 5.5.50-MariaDB MariaDB Server
Copyright (c) 2000,2016,MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> create database piwik;
Query OK,1 row affected (0.00 sec)
MariaDB [(none)]> grant all privileges on piwik.* to piwik@'localhost' identified by 'password';
Query OK,0 rows affected (0.01 sec)
MariaDB [(none)]> flush privileges;
Query OK,0 rows affected (0.00 sec)
MariaDB [(none)]> exit
Bye
安装Piwik
[root@linuxprobe ~]# yum -y install PHP-MysqL PHP-pdo PHP-gd PHP-xml
[root@linuxprobe ~]# vi /etc/PHP.ini
# line 405: increase memory limit
memory_limit = 512M
[root@linuxprobe ~]# wget http://piwik.org/latest.zip -P /var/www/html
[root@linuxprobe ~]# unzip /var/www/html/latest.zip -d /var/www/html
[root@linuxprobe ~]# chown -R apache. /var/www/html/piwik/tmp
[root@linuxprobe ~]# chown -R apache. /var/www/html/piwik/config
[root@linuxprobe ~]# chmod +w /var/www/html/piwik/piwik.js
[root@linuxprobe ~]# chown apache:apache /var/www/html/piwik/piwik.js
如果启用了SELinux,请更改以下规则。
[root@linuxprobe ~]# setsebool -P httpd_can_network_connect_db on
[root@linuxprobe ~]# chcon -R -t httpd_sys_rw_content_t /var/www/html/piwik/tmp
[root@linuxprobe ~]# chcon -R -t httpd_sys_rw_content_t /var/www/html/piwik/config
[root@linuxprobe ~]# semanage fcontext -a -t httpd_sys_rw_content_t /var/www/html/piwik/tmp
[root@linuxprobe ~]# semanage fcontext -a -t httpd_sys_rw_content_t /var/www/html/piwik/config
访问“http://(服务器的主机名或IP地址)/ piwik /”,然后单击“下一步”。
确认系统要求。如果一切OK,去下一步。
注意:如果检测系统时提示的有报错,根据提示修改PHP.ini即可,修改完成重启PHP-fpm,[root@linuxprobe ~]# systemctl restart PHP-fpm
输入数据库的信息如果数据库的信息正确,表格将正常创建。
设置admin用户。输入您喜欢的任何名称和密码。对于电子邮件地址字段,在互联网上输入真实的电子邮件地址。
输入您想要分析访问的网站信息
JavaScript代码生成如下。您需要将其添加到您的网站上
初始设置完成。单击“继续Piwik”继续。
这是登录屏幕,与您添加的用户进行身份验证,piwikadmin,your_password
登入piwik显示如下:
需要我们添加生成的Java代码到Html文件的head之间,确保每个静态页面都能调用head头文件,添加完成,使用客户端浏览器访问域名,然后刷新piwik,查看如下:
实验总结
Piwik安装基于LNMP或LAMP环境,安装时对LANMP的架构进行设计,确保各个软件都是比较稳定且较新的版本,避免piwik不提供对低版本的支持。
Piwik FAQ:https://piwik.org/faq/