Note left of eurekaClient8099/8098: 服务提供者(n个) Note left of eurekaService8091: 服务注册中心 Note left of ribbonClient8093: 服务消费者 eurekaClient8099/8098-->eurekaService8091: 注册 ribbonClient8093-->eurekaService8091: 注册 ribbonClient8093-->eurekaClient8099/8098: 通过ribbon负载均衡调用服务8099/8098
EMERGENCY! EUREKA MAY BE INCORRECTLY CLAIMING INSTANCES ARE UP WHEN THEY'RE NOT. RENEWALS ARE LESSER THAN THRESHOLD AND HENCE THE INSTANCES ARE NOT BEING EXPIRED JUST TO BE SAFE.
#ip为从库ip,设置为只有从库可以访问 GRANT REPLICATION SLAVE ON *.* TO 'app_sync'@'172.16.16.13' IDENTIFIED BY 'password'; GRANT ALL ON *.* TO 'app_root'@'%' IDENTIFIED BY 'password'; GRANT SELECT ON *.* TO 'app_read'@'%' IDENTIFIED BY 'password'; FLUSH PRIVILEGES;
然后执行show master status;
1 2 3 4 5 6
+------------------+----------+--------------+--------------------------+-------------------+ | File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set | +------------------+----------+--------------+--------------------------+-------------------+ | mysql-bin.000003 | 1164 | shenqics | information_schema,mysql | | +------------------+----------+--------------+--------------------------+-------------------+ 1 row in set (0.00 sec)
进入从库容器执行mysql -uroot -p
1 2 3 4 5 6 7
stop slave; change master to master_host='172.16.16.8',master_port=14036,master_user='app_sync',master_password='password',master_log_file='mysql-bin.000003', master_log_pos=1164; start slave; show slave status; #授权 GRANT SELECT ON *.* TO 'app_read'@'%' IDENTIFIED BY 'password'; FLUSH PRIVILEGES;
GRANT 权限 ON 数据库.表名 TO '用户'@'主机' IDENTIFIED BY '密码'
权限:all,select,等
主机:指定ip地址访问、localhost或127.0.0.1(本地访问)、%(任意主机均可访问)
密码:为空时则不需要密码
eg:
1 2
GRANT REPLICATION SLAVE ON *.* TO 'app_sync'@'172.16.16.13' IDENTIFIED BY 'admin'; #意思是创建一个专门的用户(app_sync)进行从库复制,复制任何库和任何表,密码是admin,可以访问的ip只有来源172.16.16.13(从库ip)
删除用户drop user test@'172.16.16.13';
常见错误
Too many connections症状,不断重启运行springboot并访问,出现如下错误
1 2 3 4 5 6
2018-04-0521:48:56.824 ERROR 6838 --- [ main] com.xhzg.xhzg.XhzgApplicationTests : nested exception is org.apache.ibatis.exceptions.PersistenceException: ### Error querying database. Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Data source rejected establishment of connection, message from server: "Too many connections" ### The error may exist in com/xhzg/xhzg/mapper/UserMapper.java (best guess) ### The error may involve com.xhzg.xhzg.mapper.UserMapper.loadUserByUsername ### The error occurred while executing a query ### Cause: org.springframework.jdbc.CannotGetJdbcConnectionException: Failed to obtain JDBC Connection; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Data source rejected establishment of connection, message from server: "Too many connections"
[Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 'information_schema.PROFILING.SEQ' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by