4.56-MariaDB的密碼重置php
若是記得root的密碼:html
mysqladmin -uroot -paminglinux password "aming-linux"
若是不記得root密碼:java
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
mysql在5.7.36版本以後把密碼字段存到了authentication_string字段裏,在以前版本存在password字段裏。 update user set password=password("aming-linux") where user='root';
4.57 MariaDB慢查詢日誌linux
爲何要配置慢查詢日誌?nginx
目的是爲了幫助咱們分析MariaDB的瓶頸點。
如何配置?web
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
擴展:sql
show processlist; show full processlist; mysql -uroot -pxxxx -e "show processlist"
4.58 Tomcat_JDK部署數據庫
JAVA 應用要運行起來,須要一個JVM(JAVA虛擬機)apache
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去訪問,能夠去裏面作一些細節的設置