4.56 MariaDB密码重置
- 记得
root
密码:
mysqladmin -uroot -p****** password "******"
- 没有
root
密码:
1)编辑/etc/my.cnf
,增加skip-grant
,然后重启mysql
服务;
2)登录进MariaDB
,切换到mysql
库,执行desc user
查看user
表的所有字段,执行update user set authentication_string=password("******") where user='root';
修改用户的密码;
3)退出MariaDB
,删除/etc/my.cnf
里面的skip-grant
, 重启服务;
4)用新密码登录即可
4.57 MariaDB慢查询日志
为什么要学会配置和查看MariaDB的慢查询日志——它能帮助我们分析MariaDB的瓶颈点。
- 进入MariaDB,查看当前配置:
[root@rice01 ~]# mysql -uroot -p111111
MariaDB [(none)]> show variables like 'slow%';
+---------------------+-----------------+
| Variable_name | Value |
+---------------------+-----------------+
| slow_launch_time | 2 |
| slow_query_log | OFF | // 当前慢查询日志为关闭状态
| slow_query_log_file | rice01-slow.log | // 慢查询日志的名称为rice01-slow.log
+---------------------+-----------------+
MariaDB [(none)]> show variables like 'datadir%';
+---------------+--------------+
| Variable_name | Value |
+---------------+--------------+
| datadir | /data/mysql/ | // 日志存放的路径在/data/mysql下
+---------------+--------------+
MariaDB [(none)]> show variables like 'long%';
+-----------------+-----------+
| Variable_name | Value |
+-----------------+-----------+
| long_query_time | 10.000000 | // 慢查询日志记录的查询时间点,当前为查询时间超过10s记录日志
+-----------------+-----------+
- 配置慢查询日志:
[root@rice01 ~]# vi /etc/my.cnf
// 增加以下配置:
slow_query_log = ON // 开启慢查询日志
slow_query_log_file = /data/mysql/rice01-slow.log // 定义慢查询日志的路径及文件名
long_query_time = 2 // 定义慢查询日志记录的查询时间点,当查询时间超过2s时记录日志
[root@rice01 ~]# /etc/init.d/mysqld restart // 重启mysql
- 模拟慢查询:
[root@rice01 ~]# mysql -uroot -p111111
MariaDB [(none)]> select sleep(5); // 在MySQL/MariaDB中执行select sleep(N)可以让此语句运行N秒钟
+----------+
| sleep(5) |
+----------+
| 0 |
+----------+
[root@rice01 ~]# cat /data/mysql/rice01-slow.log
/usr/local/mysql/bin/mysqld, Version: 5.5.63-MariaDB (MariaDB Server). started with:
Tcp port: 0 Unix socket: /tmp/mysql.sock
Time Id Command Argument
# Time: 190223 12:05:32
# User@Host: root[root] @ localhost []
# Thread_id: 3 Schema: QC_hit: No
# Query_time: 5.019433 Lock_time: 0.000000 Rows_sent: 1 Rows_examined: 0
SET timestamp=1550894732;
select sleep(5);
关于sleep (N)函数的相关知识:
通过在MySQL/MariaDB中执行select sleep(N)可以让此语句运行N秒钟:
mysql> select sleep(1);
+----------+
| sleep(1) |
+----------+
| 0 |
+----------+
1 row in set (1.00 sec)
返回给客户端的执行时间显示出等待了1秒钟。
借助于sleep(N)这个函数我们可以在MySQL/MariaDB的PROCESSLIST中捕获到执行迅速不易被查看到的语句以确定我们的程序是否确实在Server端发起了该语句。比如我们在调试时想确定一下程序是否确确实实向Server发起了执行SQL语句的请求,那么我们可以通过执行show processlist或者由information_schema.processlist表来查看语句是否出现。但往往语句执行速度可能非常快,这样的话就很难通过上述办法确定语句是否真正被执行了。例如下面语句的执行时间为0.00秒,线程信息一闪而过,根本无从察觉。
mysql> select name from animals where name='tiger';
+-------+
| name |
+-------+
| tiger |
+-------+
1 row in set (0.00 sec)
在这种情况下,可以通过在语句中添加一个sleep(N)函数,强制让语句停留N秒钟,来查看后台线程,例如:
mysql> select sleep(1),name from animals where name='tiger';
+----------+-------+
| sleep(1) | name |
+----------+-------+
| 0 | tiger |
+----------+-------+
1 row in set (1.00 sec)
同样的条件该语句返回的执行时间为1.0秒。
但是使用这个办法是有前提条件的,也只指定条件的记录存在时才会停止指定的秒数,例如查询条件为name=‘pig’,结果表明记录不存在,执行时间为0
mysql> select name from animals where name='pig';
Empty set (0.00 sec)
在这样一种条件下,即使添加了sleep(N)这个函数,语句的执行还是会一闪而过,例如:
mysql> select sleep(1),name from animals where name='pig';
Empty set (0.00 sec)
另外需要注意的是,添加sleep(N)这个函数后,语句的执行具体会停留多长时间取决于满足条件的记录数,MySQL会对每条满足条件的记录停留N秒钟。
例如,name like '%ger’的记录有三条
mysql> select name from animals where name like '%ger';
+-------+
| name |
+-------+
| ger |
| iger |
| tiger |
+-------+
3 rows in set (0.00 sec)
那么针对该语句添加了sleep(1)这个函数后语句总的执行时间为3.01秒,可得出,MySQL对每条满足条件的记录停留了1秒中。
mysql> select sleep(1),name from animals where name like '%ger';
+----------+-------+
| sleep(1) | name |
+----------+-------+
| 0 | ger |
| 0 | iger |
| 0 | tiger |
+----------+-------+
3 rows in set (3.01 sec)
4.58 Tomcat_JDK部署
安装JDK、Tomcat:
[root@rice01 ~]# yum install -y java-1.8.0-openjdk
[root@rice01 ~]# cd /usr/local/src/
[root@rice01 src]# wget http://mirror.bit.edu.cn/apache/tomcat/tomcat-9/v9.0.16/bin/apache-tomcat-9.0.16.tar.gz
[root@rice01 src]# tar zxf apache-tomcat-9.0.16.tar.gz
[root@rice01 src]# rm -f apache-tomcat-9.0.16.tar.gz
[root@rice01 src]# mv apache-tomcat-9.0.16 /usr/local/tomcat
[root@rice01 local]# /usr/local/tomcat/bin/startup.sh // 启动tomcat
[root@rice01 local]# ps aux |grep java // 查看进程,也可以grep tomcat
[root@rice01 local]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 7003/php-fpm: maste
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 7210/mysqld
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 6917/nginx: master
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 6895/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 7295/master
tcp 0 0 0.0.0.0:443 0.0.0.0:* LISTEN 6917/nginx: master
tcp6 0 0 :::8009 :::* LISTEN 7616/java // 8009为AJP端口
tcp6 0 0 :::8080 :::* LISTEN 7616/java // 8080为web端口
tcp6 0 0 :::22 :::* LISTEN 6895/sshd
tcp6 0 0 ::1:25 :::* LISTEN 7295/master
tcp6 0 0 127.0.0.1:8005 :::* LISTEN 7616/java // 8005为管理端口
[root@rice01 webapps]# firewall-cmd --add-port=8080/tcp --permanent
[root@rice01 webapps]# firewall-cmd --add-port=8005/tcp --permanent
[root@rice01 webapps]# firewall-cmd --reload
tomcat ajp端口的作用:
tomcat最主要的功能是提供Servlet/JSP容器,尽管它也可以作为独立的Java Web服务器,它在对静态资源(如HTML文件或图像文件)的处理速度,以及提供的Web服务器管理功能方面都不如其他专业的HTTP服务器,如IIS和Apache服务器。
因此在实际应用中,常常把Tomcat与其他HTTP服务器集成。对于不支持Servlet/JSP的HTTP服务器,可以通过Tomcat服务器来运行Servlet/JSP组件。
当Tomcat与其他HTTP服务器集成时,Tomcat服务器的工作模式通常为进程外的Servlet容器,Tomcat服务器与其他HTTP服务器之间通过专门的插件来通信。
4.59 安装zrlog
- Linux安装zrlog:
[root@rice01 ~]# cd /usr/local/src/
[root@rice01 src]# wget 'http://dl.zrlog.com/release/zrlog-2.1.0-3617b2e-release.war?attname=ROOT.war&ref=index'
[root@rice01 src]# mv zrlog-2.1.0-3617b2e-release.war\?attname\=ROOT.war\&ref\=index /usr/local/tomcat/webapps/zrlog-2.1.0.war
[root@rice01 src]# cd /usr/local/tomcat/webapps/
[root@rice01 webapps]# mv ROOT ROOT.bak
[root@rice01 webapps]# mv zrlog-2.1.0 ROOT
// 客户端访问IP:8080时,访问的其实是webapps文件夹下的内容,而页面的内容又放置在ROOT文件夹下,所以我们需要将zrlog改名为ROOT,让客户端访问IP:8080时直接访问zrlog的内容
[root@rice01 webapps]# rm -f zrlog-2.1.0.war
- 创建数据库:
[root@rice01 webapps]# mysql -uroot -111111 -e "create database zrlog"
[root@rice01 webapps]# mysql -uroot -111111 -e "grant all on zrlog.* to 'zrlog'@'127.0.0.1' identified by '111111'"
- 浏览器安装zrlog:
打开浏览器,访问192.168.142.131:8080,填好相应信息后安装完成。