4.56-MariaDB的密码重置
如果记得root的密码:
mysqladmin -uroot -paminglinux password "aming-linux"
如果不记得root密码:
1)编辑/etc/my.cnf
增加:skip-grant
重启服务
2)登录进MariaDB,执行
use mysql 切换到mysql库
desc user 查看user表的所有字段
update user set authentication_string=password("aming-linux") where user='root';
3)退出MariaDB,删除/etc/my.cnf里面的skip-grant, 重启服务
4)用新密码登录即可
常识:
mysql在5.7.36版本之后把密码字段存到了authentication_string字段里,在之前版本存在password字段里。
update user set password=password("aming-linux") where user='root';
4.57 MariaDB慢查询日志
为什么要配置慢查询日志?
目的是为了帮助我们分析MariaDB的瓶颈点。
如何配置?
1)进入MariaDB里面执行:
show variables like 'slow%';
show variables like 'datadir';
show variables like 'long%';
2)打开配置文件/etc/my.cnf,编辑,增加:
slow_query_log = ON
slow_query_log_file = /data/mysql/aminglinux01-slow.log
long_query_time = 2
3)重启服务
4)模拟慢查询
select sleep(5);
5)查看慢查询日志:
cat /data/mysql/aminglinux01-slow.log
扩展:
show processlist;
show full processlist;
mysql -uroot -pxxxx -e "show processlist"
4.58 Tomcat_JDK部署
JAVA 应用要运行起来,需要一个JVM(JAVA虚拟机)
JVM --> JDK
Oracle官方JDK下载地址: https://www.oracle.com/technetwork/java/javase/downloads/index.html
CentOS7上yum安装openjdk
yum install -y java-1.8.0-openjdk
Tomcat官方网站:
http://tomcat.apache.org/
Tomcat版本:
7.0 8.5 9.0
下载地址:
https://tomcat.apache.org/download-90.cgi
wget https://www-eu.apache.org/dist/tomcat/tomcat-9/v9.0.14/bin/apache-tomcat-9.0.14.tar.gz
安装Tomcat
tar zxf apache-tomcat-9.0.14.tar.gz
mv apache-tomcat-9.0.14 /usr/local/tomcat
启动
/usr/local/tomcat/bin/startup.sh
查看端口
netstat -lntp |grep java
8080为WEB端口
8005 shutdown(管理端口)
8009 AJP端口(第三方的应用连接这个接口,和Tomcat结合起来)
查看进程
ps aux |grep java ; ps aux |grep tomcat
4.59 zrlog安装
zrlog 是一款开源的JAVA应用,博客系统 官网: https://www.zrlog.com/
下载:
wget 'http://dl.zrlog.com/release/zrlog-2.1.0-3617b2e-release.war?attname=ROOT.war&ref=index'
mv zrlog-2.1.0-3617b2e-release.war\?attname\=ROOT.war\&ref\=index zrlog-2.1.0.war
安装:
mv zrlog-2.1.0.war /usr/local/tomcat/webapps/
cd !$
mv ROOT ROOT.bak
mv zrlog-2.1.0 ROOT
浏览器访问:
添加防火墙规则: firewall-cmd --add-port=8080/tcp --permanent
firewall-cmd --reload
http://ip:8080/ 开始安装
数据库操作:
mysql -uroot -paming-linux -e "create database zrlog"
mysql -uroot -paming-linux -e "grant all on zrlog.* to 'zrlog'@'127.0.0.1' identified by 'zrlog-pass'"
4.60 Nginx代理Tomcat
为什么要为Tomcat配置反向代理?
1)如果同一台机器又有Nginx又有Tomcat,则会产生端口冲突。
2)我们需要把8080端口变成80端口
3)Nginx对于静态的请求速度上要优于Tomcat,Tomcat不擅长做高并发的静态文件请求处理
如何配置?
server {
server_name z.aminglinux.cc;
location /
{
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
代码后续慢慢补齐
4.56 MariaDB密码重置
如果不记得mysql的root密码
[root@test01 ~]# vi /etc/my.cnf
[mysqld]
datadir=/data/mysql
socket=/tmp/mysql.sock
skip-grant
[root@test01 ~]# /etc/init.d/mysqld restart 重启
Restarting mysqld (via systemctl): [ 确定 ]
[root@test01 ~]# mysql -uroot 此时就不需要再输入密码了
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 10.3.12-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
MariaDB [(none)]> use mysql 切换到mysql库下面去
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [mysql]> desc user; 看一下
+------------------------+-----------------------------------+------+-----+----------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------------+-----------------------------------+------+-----+----------+-------+
| Host | char(60) | NO | PRI | | |
| User | char(80) | NO | PRI | | |
| Password | char(41) | NO | | | |
| Select_priv | enum('N','Y') | NO | | N | |
| Insert_priv | enum('N','Y') | NO | | N | |
| Update_priv | enum('N','Y') | NO | | N | |
| Delete_priv | enum('N','Y') | NO | | N | |
| Create_priv | enum('N','Y') | NO | | N | |
| Drop_priv | enum('N','Y') | NO | | N | |
| Reload_priv | enum('N','Y') | NO | | N | |
| Shutdown_priv | enum('N','Y') | NO | | N | |
| Process_priv | enum('N','Y') | NO | | N | |
| File_priv | enum('N','Y') | NO | | N | |
| Grant_priv | enum('N','Y') | NO | | N | |
| References_priv | enum('N','Y') | NO | | N | |
| Index_priv | enum('N','Y') | NO | | N | |
| Alter_priv | enum('N','Y') | NO | | N | |
| Show_db_priv | enum('N','Y') | NO | | N | |
| Super_priv | enum('N','Y') | NO | | N | |
| Create_tmp_table_priv | enum('N','Y') | NO | | N | |
| Lock_tables_priv | enum('N','Y') | NO | | N | |
| Execute_priv | enum('N','Y') | NO | | N | |
| Repl_slave_priv | enum('N','Y') | NO | | N | |
| Repl_client_priv | enum('N','Y') | NO | | N | |
| Create_view_priv | enum('N','Y') | NO | | N | |
| Show_view_priv | enum('N','Y') | NO | | N | |
| Create_routine_priv | enum('N','Y') | NO | | N | |
| Alter_routine_priv | enum('N','Y') | NO | | N | |
| Create_user_priv | enum('N','Y') | NO | | N | |
| Event_priv | enum('N','Y') | NO | | N | |
| Trigger_priv | enum('N','Y') | NO | | N | |
| Create_tablespace_priv | enum('N','Y') | NO | | N | |
| Delete_history_priv | enum('N','Y') | NO | | N | |
| ssl_type | enum('','ANY','X509','SPECIFIED') | NO | | | |
| ssl_cipher | blob | NO | | NULL | |
| x509_issuer | blob | NO | | NULL | |
| x509_subject | blob | NO | | NULL | |
| max_questions | int(11) unsigned | NO | | 0 | |
| max_updates | int(11) unsigned | NO | | 0 | |
| max_connections | int(11) unsigned | NO | | 0 | |
| max_user_connections | int(11) | NO | | 0 | |
| plugin | char(64) | NO | | | |
| authentication_string | text | NO | | NULL | |
| password_expired | enum('N','Y') | NO | | N | |
| is_role | enum('N','Y') | NO | | N | |
| default_role | char(80) | NO | | | |
| max_statement_time | decimal(12,6) | NO | | 0.000000 | |
+------------------------+-----------------------------------+------+-----+----------+-------+
47 rows in set (0.022 sec)
新版本的MariaDB 密码文件是这个authentication_string
MariaDB [mysql]> update user set authentication_string=password("champin") where user='root';
Query OK, 4 rows affected (0.001 sec)
Rows matched: 4 Changed: 4 Warnings: 0
MariaDB [mysql]> Bye
[root@test01 ~]# vi /etc/my.cnf
删除
skip-grant
[root@test01 ~]# /etc/init.d/mysqld restart 重启
[root@test01 ~]# mysql -uroot -pchampin 重新登录
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 10.3.12-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
MariaDB [(none)]> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [mysql]> select user,host from user; 我们可以看一下有很多用户
+---------+-----------+
| user | host |
+---------+-----------+
| bbs | 127.0.0.1 |
| blogtop | 127.0.0.1 |
| root | 127.0.0.1 |
| root | ::1 |
| | localhost |
| root | localhost |
| | test01 |
| root | test01 |
+---------+-----------+
8 rows in set (0.000 sec)
4.57 MariaDB慢查询日志
MariaDB [(none)]> show variables like 'slow%'; 查看它的slow相关的
+---------------------+-----------------+
| Variable_name | Value |
+---------------------+-----------------+
| slow_launch_time | 2 |
| slow_query_log | OFF |
| slow_query_log_file | test01-slow.log |
+---------------------+-----------------+
3 rows in set (0.002 sec)
MariaDB [(none)]> show variables like 'datadir';查看它的datadir
+---------------+--------------+
| Variable_name | Value |
+---------------+--------------+
| datadir | /data/mysql/ |
+---------------+--------------+
1 row in set (0.003 sec)
MariaDB [(none)]> show variables like 'long%'; 查看它的超时时间
+-----------------+-----------+
| Variable_name | Value |
+-----------------+-----------+
| long_query_time | 10.000000 |
+-----------------+-----------+
1 row in set (0.004 sec)
MariaDB [(none)]> Bye
[root@test01 ~]# vi /etc/my.cnf
增加如下
slow_query_log = ON
slow_query_log_file = /data/mysql/test01-slow.log
long_query_time = 2
[root@test01 ~]# /etc/init.d/mysqld restart
Restarting mysqld (via systemctl): [ 确定 ]
[root@test01 ~]# mysql -uroot -pchampin 进入MariaDB里面
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 10.3.12-MariaDB-log MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> select sleep(5); 模拟慢查询
+----------+
| sleep(5) |
+----------+
| 0 |
+----------+
1 row in set (5.001 sec)
MariaDB [(none)]> Bye
[root@test01 ~]# cat /data/mysql/t
tc.log test/ test01.pid test01-slow.log
[root@test01 ~]# cat /data/mysql/test01-slow.log 查看慢查询日志
/usr/local/mysql/bin/mysqld, Version: 10.3.12-MariaDB-log (MariaDB Server). started with:
Tcp port: 0 Unix socket: /tmp/mysql.sock
Time Id Command Argument
# Time: 190311 23:12:52
# User@Host: root[root] @ localhost []
# Thread_id: 9 Schema: QC_hit: No
# Query_time: 5.000687 Lock_time: 0.000000 Rows_sent: 1 Rows_examined: 0
# Rows_affected: 0 Bytes_sent: 63
SET timestamp=1552317172;
select sleep(5);
扩展
[root@test01 ~]# mysql -uroot -pchampin
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 10.3.12-MariaDB-log MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> show processlist; 查看所有的队列(跟查看所有的进程一个道理)
+----+-------------+-----------+------+---------+------+--------------------------+------------------+----------+
| Id | User | Host | db | Command | Time | State | Info | Progress |
+----+-------------+-----------+------+---------+------+--------------------------+------------------+----------+
| 1 | system user | | NULL | Daemon | NULL | InnoDB purge worker | NULL | 0.000 |
| 2 | system user | | NULL | Daemon | NULL | InnoDB purge coordinator | NULL | 0.000 |
| 3 | system user | | NULL | Daemon | NULL | InnoDB purge worker | NULL | 0.000 |
| 4 | system user | | NULL | Daemon | NULL | InnoDB purge worker | NULL | 0.000 |
| 5 | system user | | NULL | Daemon | NULL | InnoDB shutdown handler | NULL | 0.000 |
| 10 | root | localhost | NULL | Query | 0 | Init | show processlist | 0.000 |
+----+-------------+-----------+------+---------+------+--------------------------+------------------+----------+
6 rows in set (0.001 sec)
MariaDB [(none)]> show rull processlist; 显示完整的语句
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'rull processlist' at line 1
MariaDB [(none)]> show full processlist;
+----+-------------+-----------+------+---------+------+--------------------------+-----------------------+----------+
| Id | User | Host | db | Command | Time | State | Info | Progress |
+----+-------------+-----------+------+---------+------+--------------------------+-----------------------+----------+
| 1 | system user | | NULL | Daemon | NULL | InnoDB purge worker | NULL | 0.000 |
| 2 | system user | | NULL | Daemon | NULL | InnoDB purge coordinator | NULL | 0.000 |
| 3 | system user | | NULL | Daemon | NULL | InnoDB purge worker | NULL | 0.000 |
| 4 | system user | | NULL | Daemon | NULL | InnoDB purge worker | NULL | 0.000 |
| 5 | system user | | NULL | Daemon | NULL | InnoDB shutdown handler | NULL | 0.000 |
| 10 | root | localhost | NULL | Query | 0 | Init | show full processlist | 0.000 |
+----+-------------+-----------+------+---------+------+--------------------------+-----------------------+----------+
6 rows in set (0.000 sec)
4.58 Tomcat_JDK部署
[root@test01 ~]# yum install -y java-1.8.0-openj
[root@test01 ~]# cd /usr/local/src/
[root@test01 src]# wget http://mirror.bit.edu.cn/apache/tomcat/tomcat-9/v9.0.16/bin/apache-tomcat-9.0.16.tar.gz
[root@test01 src]# ls
apache-tomcat-9.0.16.tar.gz nginx-1.14.2
apache-tomcat-9.0.16.tar.gz.1 nginx-1.14.2.tar.gz
mariadb-10.3.12-linux-x86_64.tar.gz php-7.3.1
mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz php-7.3.1.tar.bz2
[root@test01 src]# tar zxf apache-tomcat-9.0.16.tar.gz
[root@test01 src]# ls
apache-tomcat-9.0.16 mariadb-10.3.12-linux-x86_64.tar.gz nginx-1.14.2.tar.gz
apache-tomcat-9.0.16.tar.gz mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz php-7.3.1
apache-tomcat-9.0.16.tar.gz.1 nginx-1.14.2 php-7.3.1.tar.bz2
[root@test01 src]# mv apache-tomcat-9.0.16 /usr/local/tomcat
[root@test01 src]# /usr/local/tomcat/bin/startup.sh 启动Tomcat
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.
[root@test01 src]# ps aux |grep java 查看进程
root 7340 10.9 7.8 2289972 78204 pts/3 Sl 23:39 0:03 /usr/bin/java -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -Dignore.endorsed.dirs= -classpath /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat -Dcatalina.home=/usr/local/tomcat -Djava.io.tmpdir=/usr/local/tomcat/temp org.apache.catalina.startup.Bootstrap start
root 7356 0.0 0.0 112728 976 pts/3 R+ 23:39 0:00 grep --color=auto java
[root@test01 src]# netstat -ltnp |grep java 查看监听端口,有3个端口
8080为WEB端口
8005 shutdown(管理端口)
8009 AJP端口(第三方的应用连接这个接口,和Tomcat结合起来)
tcp6 0 0 :::8080 :::* LISTEN 7340/java
tcp6 0 0 127.0.0.1:8005 :::* LISTEN 7340/java
tcp6 0 0 :::8009 :::* LISTEN 7340/java
4.59 安装zrlog
[root@test01 src]# cd
[root@test01 ~]# wget http://dl.zrlog.com/release/zrlog-2.1.0-3617b2e-release.war?attname=ROOT.war&ref=index
[root@test01 ~]# ls
11.txt 2.txt anaconda-ks.cfg startingup.sh
1.txt 3.txt DiscuzX zrlog-2.1.0-3617b2e-release.war?attname=ROOT.war
[root@test01 ~]# du -sh zrlog-2.1.0-3617b2e-release.war\?attname\=ROOT.war 也属于一种压缩包
不用管怎么解压,至于要放到某个目录下就可以,会自动解压
9.9M zrlog-2.1.0-3617b2e-release.war?attname=ROOT.war
[root@test01 ~]# mv zrlog-2.1.0.war /usr/local/tomcat/webapps/
[root@test01 ~]# cd !$
cd /usr/local/tomcat/webapps/
[root@test01 webapps]# ls
docs examples host-manager manager ROOT zrlog-2.1.0 zrlog-2.1.0.war
[root@test01 webapps]# mv zrlog-2.1.0 zrlog 改个名字,不需要带版本号了。因为等访问的时候要带目录
[root@test01 webapps]# ls
docs examples host-manager manager ROOT zrlog zrlog-2.1.0.war
用浏览器访问tomcat默认界面 192.168.28.107:8080 如果不能访问,检查是不是防火墙阻拦了8080
[root@test01 webapps]# iptables -nvL |grep 8080 检查有没有8080端口,结果没有
[root@test01 webapps]# firewall-cmd --add-port=8080/tcp --permanent 添加防火墙规则,8080端口
success
[root@test01 webapps]# firewall-cmd --reload 还要重载一下
success
然后再用浏览器访问tomcat默认界面 192.168.28.107:8080
要想访问zrlog,这样192.168.28.107:8080/zrlog
也就是说zrlog在/usr/local/tomcat/webapps这个目录 访问8080实际访问的是/usr/local/tomcat/webapps这个目录
下面这两步不太建议做。访问不了tomcat默认主页
[root@test01 webapps]# mv ROOT ROOT.bak
[root@test01 webapps]# mv zrlog ROOT
[root@test01 webapps]# mysql -uroot -pchampin -e "create database zrlog" 创建库
[root@test01 webapps]# mysql -uroot -pchampin -e "grant all on zrlog.* to 'zrlog'@'127.0.0.1'identified by 'champin'" 创建用户及密码
浏览器访问192.168.28.107:8080/zrlog
填入数据库,安装完成
4.60 Nginx代理Tomcat
[root@test01 webapps]# cd /etc/nginx/conf.d/
[root@test01 conf.d]# ls
2.conf bbs.champin.top.conf default.conf www.champin.top.conf
[root@test01 conf.d]# vi z.champinlinux.cc.conf
server {
server_name z.chamlinux.cc;
location /
{
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
[root@test01 conf.d]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@test01 conf.d]# nginx -s reload
还是因为是本机测试,要再windows绑定一个hosts 去ping一下 z.chamlinux.cc
然后在用浏览器访问z.chamlinux.cc去访问,可以去里面做一些细节的设置