[root@localhost ~]# 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? [Y/n] y //设置root密码
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? [Y/n] n //是否删除匿名用户 n
... skipping.
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? [Y/n] n //运行远程登录
... skipping.
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 and access to it? [Y/n] n //删除测试数据库 n
... skipping.
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
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!
6.数据库初始化完成后,即可登录数据库
[root@localhost ~]# mysql -uroot –p //使用root 用户登录数据库
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 6
Server version: 5.5.60-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)]> create database zabbix character set utf8 collate utf8_bin; //创建zabbix 数据库,被设置字符集为简体中文
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> show databases; //查看数据库
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
| zabbix |
+--------------------+
5 rows in set (0.00 sec)
MariaDB [(none)]> grant all privileges on *.* to 'zabbix'@'%' identified by 'admin123';
//创建zabbix用户,所有库、表都给zabbix 管理,密码为:admin123
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> flush privileges; //刷新数据库
Query OK, 0 rows affected (0.00 sec)
使用创建用户zabbix登录数据库
[root@localhost html]# mysql -uzabbix -p
Enter password:
ERROR 1045 (28000): Access denied for user 'zabbix'@'localhost' (using password: YES)
使用 zabbix 用户登录数据库失败,其原因是有空用户名称占用导致本地无法连接,解决方法为删除空用户名
以root 用户登录数据库,删除空用户名
[root@localhost html]# mysql -uroot -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 8
Server version: 5.5.60-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)]> select user,host from mysql.user; //查看当前用户
+--------+-----------------------+
| user | host |
+--------+-----------------------+
| zabbix | % |
| root | 127.0.0.1 |
| root | ::1 |
| | localhost | //存在两个空用户名
| root | localhost |
| | localhost.localdomain |
| root | localhost.localdomain |
+--------+-----------------------+
7 rows in set (0.00 sec)
MariaDB [(none)]> drop user ''@localhost; //删除空用户
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> drop user ''@localhost.localdomain;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> quit
Bye
此时退出,再以 zabbix 用户登录数据库
[root@localhost html]# mysql -uzabbix -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 5.5.60-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)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
| zabbix |
+--------------------+
5 rows in set (0.00 sec)
7. 测试 php ,能否使用 zabbix 用户连接数据库
[root@localhost ~]# cd /var/www/html/
[root@localhost html]# ls
[root@localhost html]# vim index.php 编辑php首页
[root@localhost aaa]# vim /etc/mail.rc //注意如使用网易或qq邮箱需要开启客户端授权码进行第三方登录
set from=1947…@qq.com //qq邮箱地址
set smtp=smtp.qq.com
set smtp-auth-user=1947….@qq.com
set smtp-auth-password=ahixbfxiuztjcfjb //第三方授权码
set smtp-auth=login
qq邮箱的第三方授权码获得方法如下,进入qq邮箱,选择“设置” ,然后“账户”
发送邮件测试
[root@localhost aaa]# echo "this is zabbix" | mail -s "testmail" 1947….@qq.com //测试发送邮件,查看是否能收到
2.编写发邮件脚本
[root@localhost aaa]# cd /usr/lib/zabbix/
[root@localhost zabbix]# ls
alertscripts externalscripts
[root@localhost zabbix]# cd alertscripts/
[root@localhost alertscripts]# ls
[root@localhost alertscripts]# vim mail.sh