docker简单构建mysql-mariadb数据库安全策略1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586#创建用户CREATE USER 'gegewu'@'%' IDENTIFIED BY '123456';#授权运程登录用户GRANT ALL PRIVILEGES ON *.* TO 'gegewu'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION; /注:此用户只能用于远程登录 本地用户只能用于本地登录mysql -uroot -pzxcujvjdfkvdb#修改数据库密码SET PASSWORD FOR root@'localhost' = password('123456');SET PASSWORD FOR root@'localhost' = password('zxcujvjdfkvdb');SET PASSWORD FOR root@'%' = password('123456');set password for root@'%' = password ('123456');mysqladmin -u root password 'zxcujvjdfkvdb'mysqladmin -u root -p '123456' password 'zxcujvjdfkvdb'------------------------------------>#控制台执行语句1 ------------------->授权远程登录用户GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;#开放端口放行:firewall-cmd --zone=public --add-port=3306/tcp --permanent加上--permanet参数永久生效.如果前面修改了端口号.此处的3306就应改成对应的端口号.然后使用命令重新读取防火墙规则:firewall-cmd --reload#控制台执行语句2: 刷新FLUSH PRIVILEGES;#查看mysql端口show global variables like 'port'; #例出所有my.conf文件locate my.cnf#修改mysql默认端口vim /etc/my.conf[mysqld]port=2022#docker版mysql:5.7数据库构建docker run -d -p 3306:3306 --privileged=true \-v /mysql/log:/var/log/mysql \-v /mysql/data:/var/lib/mysql \-v /mysql/conf:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD=123456 \--name mysql1 mysql:5.7----------------------------------------->##docker版mysql:5.7数据库构建#账户:root 密码:123456-------------------------->#docker版mariadb数据库构建docker run -d -p 3306:3306 --privileged=true \-v /mariadb/log:/var/log/mysql \-v /mariadb/data:/var/lib/mysql \-v /mariadb/conf:/etc/mysql/ -e MYSQL_ROOT_PASSWORD=123456 \--name mariadb1 mariadb#docker版mariadb数据库构建#账户: root 密码:123456--------------------------------------------------- >#mariadb:/etc/mysql/my.cnf 安全策略插件配置#数据库密码:zxcujvjdfkvdb 账户:gegewu ip:10.0.0.11#密码复杂度插件plugin_load_add = simple_password_check.so #启动服务加载插件simple_password_check = FORCE_PLUS_PERMANENT #防止插件在运行过程中被卸载### 审计 ###plugin-load-add = server_audit.so #启动服务加载此插件server_audit_logging = ON #开启日志记录,默认是关闭server_audit = FORCE_PLUS_PERMANENT #防止插件被卸载server_audit_file_path = server_audit.log #定义审计日志文件名server_audit_file_rotate_now = OFF #是否强制切割审计日志server_audit_file_rotate_size = 1073741824 #定义切割审计日志的文件大小1073741824=1GBserver_audit_file_rotations = 9 #定义审计日志的轮询个数,0为不轮询server_audit_events = 'connect,query,table' #日志记录的操作server_audit_events = 'query_ddl,query_dml' #不记录select查询操作,只记录增删改、DDL操作server_audit_incl_users = 'gegewu,root' #审计的用户对象,不设置则针对所有用户#mysql社区版:/etc/mysql/my.cnf 安全策略插件配置#数据库密码:123456 账户:gegewu ip:10.0.0.10[mysqld]plugin-load-add = validate_password.so #服务器在启动时加载插件,并防止在服务器运行时删除插件。validate-password = FORCE_PLUS_PERMANENT #并防止在服务器运行时删除插件validate_password_policy= 2 #密码安全度等级2 ###安全策略密码检查延迟###plugin-load-add = connection_control.so #在启动时加载插件connection-control = FORCE_PLUS_PERMANENT #并防止它们在运行时被删除connection-control-failed-login-attempts = FORCE_PLUS_PERMANENT #并防止它们在运行时被删除 connection_control_min_connection_delay = 60000 #最小延迟时间connection_control_max_connection_delay = 86400 #最大延迟时间connection_control_failed_connections_threshold = 3 #延迟时间触发输错密码次数 截图