MySQL5.7改密碼無password字段並存在1820的報錯,並部署zabbix和監控mysql

新安裝的MySQL5.7,登陸時提示密碼錯誤,安裝的時候並無更改密碼,後來經過免密碼登陸的方式更改密碼,輸入update mysql.user set password=password('123456') where user='root'時提示ERROR 1054 (42S22): Unknown column 'password' in 'field list',原來是mysql數據庫下已經沒有password這個字段了,password字段改爲了
authentication_string
MySQL5.7改密碼無password字段並存在1820的報錯,並部署zabbix和監控mysql
上圖是設置root密碼以後的加上註釋php

進去mysql裏設置root密碼
mysql> update mysql.user set authentication_string=password('123456') where user='root' ;
Query OK, 1 row affected, 1 warning (0.09 sec)
Rows matched: 1 Changed: 1 Warnings: 1
mysql> exit
Bye
MySQL5.7改密碼無password字段並存在1820的報錯,並部署zabbix和監控mysql
[root@mha ~]# vi /etc/my.cnf ###進去把skip-grant-tables註釋了
[root@mha ~]# systemctl restart mysqld
MySQL5.7改密碼無password字段並存在1820的報錯,並部署zabbix和監控mysqljava

ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
MySQL5.7改密碼無password字段並存在1820的報錯,並部署zabbix和監控mysqlmysql

一、修改用戶密碼:
mysql> alter user 'root'@'localhost' identified by 'youpassword'; 或者set password=password("xxxxx");
二、受權遠程訪問:
grant 權限 on . to '用戶'@'%’ identified by '123456';
##############%是表明全部地址;第一個是庫,第二個是表;
權限:
all privileges (全部權限)
insert,update,delete,select(增改刪查)
三、查看用戶的權限
select from mysql.user where user='root'\G;
四、添加中文字符集
在[mysqld]下添加
character_set_server=utf8
MySQL5.7改密碼無password字段並存在1820的報錯,並部署zabbix和監控mysql
五、經過受權:
mysql> grant all privileges on zabbix.
to 'zabbix'@'localhost' identified by '123456';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
MySQL5.7改密碼無password字段並存在1820的報錯,並部署zabbix和監控mysql
有時候,只是爲了本身測試,不想密碼設mysql> 置得那麼複雜,譬如說,我只想設置root的密碼爲123456。web

必須修改兩個全局參數:sql

首先,修改validate_password_policy參數的值數據庫

mysql> set global validate_password_policy=0;
Query OK, 0 rows affected (0.00 sec)
這樣,判斷密碼的標準就基於密碼的長度了。這個由validate_password_length參數來決定。bash

mysql> select @@validate_password_length;
+----------------------------+
| @@validate_password_length |
+----------------------------+
| 8 |
+----------------------------+
1 row in set (0.00 sec)
validate_password_length參數默認爲8,它有最小值的限制,最小值爲:
validate_password_number_countapp

  • validate_password_special_char_count
  • (2 * validate_password_mixed_case_count)

其中,validate_password_number_count指定了密碼中數據的長度,validate_password_special_char_count指定了密碼中特殊字符的長度,validate_password_mixed_case_count指定了密碼中大小字母的長度。frontend

這些參數,默認值均爲1,因此validate_password_length最小值爲4,若是你顯性指定validate_password_length的值小於4,儘管不會報錯,但validate_password_length的值將設爲4。以下所示:socket

mysql> select @@validate_password_length;
+----------------------------+
| @@validate_password_length |
+----------------------------+
| 8 |
+----------------------------+
1 row in set (0.00 sec)

mysql> set global validate_password_length=1;
Query OK, 0 rows affected (0.00 sec)

mysql> select @@validate_password_length;
+----------------------------+
| @@validate_password_length |
+----------------------------+
| 4 |
+----------------------------+
1 row in set (0.00 sec)
若是修改了validate_password_number_count,validate_password_special_char_count,validate_password_mixed_case_count中任何一個值,則validate_password_length將進行動態修改。

mysql> select @@validate_password_length;
+----------------------------+
| @@validate_password_length |
+----------------------------+
| 4 |
+----------------------------+
1 row in set (0.00 sec)

mysql> select @@validate_password_mixed_case_count;
+--------------------------------------+
| @@validate_password_mixed_case_count |
+--------------------------------------+
| 1 |
+--------------------------------------+
1 row in set (0.00 sec)

mysql> set global validate_password_mixed_case_count=2;
Query OK, 0 rows affected (0.00 sec)

mysql> select @@validate_password_mixed_case_count;
+--------------------------------------+
| @@validate_password_mixed_case_count |
+--------------------------------------+
| 2 |
+--------------------------------------+
1 row in set (0.00 sec)

mysql> select @@validate_password_length;
+----------------------------+
| @@validate_password_length |
+----------------------------+
| 6 |
+----------------------------+
1 row in set (0.00 sec)

https://repo.mysql.com//mysql57-community-release-el7-11.noarch.rpm
初始化mysql時候改的密碼
MySQL5.7改密碼無password字段並存在1820的報錯,並部署zabbix和監控mysql
MySQL5.7改密碼無password字段並存在1820的報錯,並部署zabbix和監控mysql

五、容許Zabbix web console 對特定IP段可用 (可選)
編輯文件 /etc/httpd/conf.d/zabbix.conf,

vi /etc/httpd/conf.d/zabbix.conf
添加容許訪問 zabbix web interface的ip段. 若是設置 ‘Allow from All’, 這能夠容許所有能夠訪問

#

Zabbix monitoring system php web frontend

#

Alias /zabbix /usr/share/zabbix

<Directory"/usr/share/zabbix">
Options FollowSymLinks
AllowOverride None
Require all granted

<IfModulemod_php5.c>
php_value max_execution_time 300
php_value memory_limit 128M
php_value post_max_size 16M
php_value upload_max_filesize 2M
php_value max_input_time 300
php_value date.timezone Asia/Shanghai
</IfModule>
</Directory>

<Directory"/usr/share/zabbix/conf">
Require all denied
</Directory>

<Directory"/usr/share/zabbix/include">
Require all denied
</Directory>
啓動zabbix-server 和zabbix-agent。重啓httpd,,並設置zabbix-server和zabbix-agent開機自動啓動

systemctl start zabbix-server

systemctl start zabbix-agent

systemctl restart httpd

systemctl restart mariadb

systemctl enable zabbix-server

systemctl enable zabbix-agent ---- (可選)

六、安裝並部署zabbix
準備:
rpm --import http://repo.zabbix.com/RPM-GPG-KEY-ZABBIX
rpm -Uv http://repo.zabbix.com/zabbix/2.4/rhel/7/x86_64/zabbix-release-2.4-1.el7.noarch.rpm
安裝:
yum install zabbix-server-mysql zabbix-web-mysql zabbix-agent zabbix-java-gateway
部署:
(1)編輯 file /etc/httpd/conf.d/zabbix:

vi /etc/httpd/conf.d/zabbix.conf
更新時區:

php_value date.timezone Asia/Shanghai
重啓httpd

systemctl restart httpd
(2)建立MySQL 數據庫和用戶
登陸MariaDB:

mysql –u root –p
建立一個數據庫‘zabbixdb’和數據庫用戶‘zabbix’

MariaDB [(none)]> create database zabbix character set utf8;

MariaDB [(none)]> grant all privileges on zabbix.* to 'zabbix'@'localhost' identified by '123456';

MariaDB [(none)]> flush privileges;
(3)數據庫導入zabbix template
使用數據庫用戶zabbix登陸數據庫

mysql –uzabbix –p
切換到zabbix數據庫

use zabbix
導入模板數據

MariaDB [zabbix]> source /usr/share/doc/zabbix-server-mysql-2.4.8/create/schema.sql

MariaDB [zabbix]> source /usr/share/doc/zabbix-server-mysql-2.4.8/create/images.sql

MariaDB [zabbix]> source /usr/share/doc/zabbix-server-mysql-2.4.8/create/data.sql
(4)配置Zabbix server
編輯文件/etc/zabbix/zabbix_server.conf,

vi /etc/zabbix/zabbix_server.conf
配置下面的三個參數

[...]
DBName=zabbix
[...]
DBUser=zabbix
[...]
DBPassword=123456
[...]
(5)配置zabbix-agent
vi /etc/zabbix/zabbix_agentd.conf
配置zabbix server 的ip

[...]

Line 85 - Specify Zabbix server

Server=127.0.0.1

[...]

Line 126 - Specify Zabbix server

ServerActive=127.0.0.1

[...]

Line 137 - Specify Zabbix server Hostname or IP address

Hostname=127.0.0.1

[...]
(6)修改PHP 設置
修改php.ini爲zabbix 建議的設置

編輯文件 php.ini,

vi /etc/php.ini
設置下面的參數.

max_execution_time = 600
max_input_time = 600
memory_limit = 256
Mpost_max_size = 32M
upload_max_filesize = 16M
date.timezone = Asia/Shanghai

(7)web頁面安裝zabbix
MySQL5.7改密碼無password字段並存在1820的報錯,並部署zabbix和監控mysql
前期工做作好了,就都OK
MySQL5.7改密碼無password字段並存在1820的報錯,並部署zabbix和監控mysql
MySQL5.7改密碼無password字段並存在1820的報錯,並部署zabbix和監控mysql
web頁面默認登錄密碼和用戶名,Admin/zabbix
MySQL5.7改密碼無password字段並存在1820的報錯,並部署zabbix和監控mysql

zabbix監控mysql
zabbix客戶端的mysql配置要把client配置好:
[client]
#socket=/app/mysql/lib/mysql.sock
socket=/var/lib/mysql/mysql.sock
user=root
host=localhost
password=123456

mysql的zabbix客戶端正確自定義key (若是按照百度出來的key:mysql.version mysql.status mysql.ping的這樣配置是錯誤致使沒法啓動zabbix-agent服務,多是版本的緣由吧),下面是正確配置:
UnsafeUserParameters=1

UserParameter=version,mysql -V
UserParameter=status[],/etc/zabbix/scripts/check_mysql.sh $1
UserParameter=ping[
],mysqladmin -u zabbix -p123456 ping | grep -c alive
MySQL5.7改密碼無password字段並存在1820的報錯,並部署zabbix和監控mysql

zabbix客戶端的mysql腳本:
[root@mariadb02 zabbix]# cat scripts/check_mysql.sh
#!/bin/bash
source /etc/profile

用戶名

#MYSQL_USER='zabbix'

密碼

#MYSQL_PWD='123456'

主機地址/IP

#MYSQL_HOST='127.0.0.1'

端口

#MYSQL_PORT='3306'

數據鏈接

#mysqladmin=/usr/bin/mysqladmin -u${MYSQL_USER} -p${MYSQL_PWD} -h${MYSQL_HOST} -P${MYSQL_PORT}
mysqladmin=which mysqladmin

case $1 in
Uptime)
result=${mysqladmin} status|cut -f2 -d":"|cut -f1 -d"T"
echo $result
;;
Com_update)
result=${mysqladmin} extended-status |grep -w "Com_update"|cut -d"|" -f3
echo $result
;;
Slow_queries)
result=${mysqladmin} status |cut -f5 -d":"|cut -f1 -d"O"
echo $result
;;
Com_select)
result=${mysqladmin} extended-status |grep -w "Com_select"|cut -d"|" -f3
echo $result
;;
Com_rollback)
result=${mysqladmin} extended-status |grep -w "Com_rollback"|cut -d"|" -f3
echo $result
;;
Questions)
result=${mysqladmin} status|cut -f4 -d":"|cut -f1 -d"S"
echo $result
;;
Com_insert)
result=${mysqladmin} extended-status |grep -w "Com_insert"|cut -d"|" -f3
echo $result
;;
Com_delete)
result=${mysqladmin} extended-status |grep -w "Com_delete"|cut -d"|" -f3
echo $result
;;
Com_commit)
result=${mysqladmin} extended-status |grep -w "Com_commit"|cut -d"|" -f3
echo $result
;;
Bytes_sent)
result=${mysqladmin} extended-status |grep -w "Bytes_sent" |cut -d"|" -f3
echo $result
;;
Bytes_received)
result=${mysqladmin} extended-status |grep -w "Bytes_received" |cut -d"|" -f3
echo $result
;;
Com_begin)
result=${mysqladmin} extended-status |grep -w "Com_begin"|cut -d"|" -f3
echo $result
;;

*) 
    echo "Usage:$0(Uptime|Com_update|Slow_queries|Com_select|Com_rollback|Questions|Com_insert|Com_delete|Com_commit|Bytes_sent|Bytes_received|Com_begin)" 
    ;;

esac

zabbix服務端的log日誌
MySQL5.7改密碼無password字段並存在1820的報錯,並部署zabbix和監控mysql

相關文章
相關標籤/搜索