CentOS 7.2 部署网站访问日志分析器,centos日志分析器


一、Piwik简介

二、Piwik安装

[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, 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

[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/

相关内容

    暂无相关文章