前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >CentOS 7.2 部署网站访问日志分析器 - Piwik

CentOS 7.2 部署网站访问日志分析器 - Piwik

作者头像
shaonbean
发布2019-05-26 09:34:46
8120
发布2019-05-26 09:34:46
举报
文章被收录于专栏:运维前线

版权声明:本文为木偶人shaon原创文章,转载请注明原文地址,非常感谢。 https://cloud.tencent.com/developer/article/1434691

一、Piwik简介

  1. Piwik是一个PHP和MySQL的开放源代码的Web统计软件. 它给你一些关于你的网站的实用统计报告,比如网页浏览人数, 访问最多的页面, 搜索引擎关键词等等… Piwik拥有众多不同功能的插件,你可以添加新的功能或是移除你不需要的功能,Piwik同样可以安装在你的服务器上面,数据就保存在你自己的服务器上面。你可以非常容易的插入统计图表到你的博客或是网站抑或是后台的控制面板中。安装完成后,你只需将一小段代码放到将要统计的网页中即可。
代码语言:txt
复制
1. Piwik官网:[https://piwik.org/](https://piwik.org/)
2. Piwik演示:[http://piwik.org/what-is-piwik/](http://piwik.org/what-is-piwik/)
3. Piwik下载:[https://piwik.org/download/](https://piwik.org/download/)

二、Piwik安装

  1. 安装网站访问分析器“Piwik”, Piwik不同于AWStats和其他软件,它分析一个网站,因此它需要在您想要分析访问的网站上添加Java Script代码。
代码语言:txt
复制
- 安装PHP,参考:[http://blog.csdn.net/wh211212/article/details/52982917](http://blog.csdn.net/wh211212/article/details/52982917)
- 安装MariaDB服务器  安装MariaDB 5.5(CentOS 7默认版本)以配置数据库服务器
代码语言:javascript
复制
[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
代码语言:javascript
复制
#[初始化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

代码语言:javascript
复制
[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

代码语言:javascript
复制
[root@linuxprobe ~]# firewall-cmd --add-service=mysql --permanent
success
[root@linuxprobe ~]# firewall-cmd --reload
success 

为Piwik创建数据库

代码语言:javascript
复制
[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, Oracle, 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

代码语言:javascript
复制
[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,请更改以下规则。

代码语言:javascript
复制
[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 /”,然后单击“下一步”。undefined

代码语言:txt
复制
 确认系统要求。如果一切OK,去下一步。  

注意:如果检测系统时提示的有报错,根据提示修改php.ini即可,修改完成重启php-fpm,root@linuxprobe ~# systemctl restart php-fpm

输入数据库的信息

如果数据库的信息正确,表格将正常创建。

设置admin用户。输入您喜欢的任何名称和密码。对于电子邮件地址字段,在互联网上输入真实的电子邮件地址。

代码语言:txt
复制
 输入您想要分析访问的网站信息 

JavaScript代码生成如下。您需要将其添加到您的网站上

初始设置完成。单击“继续Piwik”继续。

这是登录屏幕,与您添加的用户进行身份验证,piwikadmin,your_password

登入piwik显示如下:

需要我们添加生成的Java代码到Html文件的head之间,确保每个静态页面都能调用head头文件,添加完成,使用客户端浏览器访问域名,然后刷新piwik,查看如下:

实验总结

Piwik安装基于LNMP或LAMP环境,安装时对LANMP的架构进行设计,确保各个软件都是比较稳定且较新的版本,避免piwik不提供对低版本的支持。 Piwik FAQ:https://piwik.org/faq/

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2016年11月01日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一、Piwik简介
  • 二、Piwik安装
  • 实验总结
相关产品与服务
数据库
云数据库为企业提供了完善的关系型数据库、非关系型数据库、分析型数据库和数据库生态工具。您可以通过产品选择和组合搭建,轻松实现高可靠、高可用性、高性能等数据库需求。云数据库服务也可大幅减少您的运维工作量,更专注于业务发展,让企业一站式享受数据上云及分布式架构的技术红利!
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档