四、kod业务由内置数据库修改为mysql
因为我刚刚在阿里云删除了redis,直接访问会报错,我们需要先删除下kod数据库的配置文件的内容

把有关redis信息删掉即可,注意web01和web02都需要删
1. [root@web02 ~]# cat /code/kod/config/setting_user.php
2. <?php
3. $config['database'] = array (
4. 'DB_TYPE' => 'sqlite3',
5. 'DB_NAME' => USER_SYSTEM.'kGdiwtmrh4ZW.php',
6. 'DB_SQL_LOG' => true,
7. 'DB_FIELDS_CACHE' => true,
8. 'DB_SQL_BUILD_CACHE' => false,
9. );
10. $config['cache']['sessionType'] = 'file';
11. $config['cache']['cacheType'] = 'file';
在网站上配置,与redis同理,需要做两遍,但是第二遍的时候会提示无法执行,所以我们做完一遍后scp到另一台web,注意不要目标文件与源文件搞混了,不然还需要重新搞。

1. [root@web01 config]# cat /code/kod/config/setting_user.php
2. <?php
3. $config['database'] = array (
4. 'DB_TYPE' => 'mysqli',
5. 'DB_HOST' => 'rm-xxxx.mysql.rds.aliyuncs.com',
6. 'DB_PORT' => 3306,
7. 'DB_USER' => 'username',
8. 'DB_PWD' => 'password',
9. 'DB_NAME' => 'kodbox',
10. 'DB_SQL_LOG' => true,
11. 'DB_FIELDS_CACHE' => true,
12. 'DB_SQL_BUILD_CACHE' => false,
13. );
14.
15. $config['cache']['sessionType'] = 'file';
16. $config['cache']['cacheType'] = 'file';
17.
18. [root@web01 config]# scp setting_user.php 172.18.3.150:/code/kod/config/setting_user.php
19. root@172.18.3.150's password:
20. setting_user.php 100% 399 1.2MB/s 00:00
五、申请公网连接访问

这里取消勾选
六、在虚拟机远程测试连接mysql公网地址
1. [root@Web01 ~]# mysql -uusername -pPassword -h rm-xxxx.mysql.rds.aliyuncs.com
2. Welcome to the MariaDB monitor. Commands end with ; or \g.
3. Your MySQL connection id is 3449
4. Server version: 5.7.40-log Source distribution
5.
6. Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
7.
8. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
9.
10. MySQL [(none)]> show databases;
11. +--------------------+
12. | Database |
13. +--------------------+
14. | information_schema |
15. | __recycle_bin__ |
16. | kodbox |
17. | mysql |
18. | performance_schema |
19. | sys |
20. +--------------------+
21. 6 rows in set (0.01 sec)
22.
23. MySQL [(none)]>
七、提升主从配置为读写分离版 获取proxy代理地址 通过ECS进行连接测试
刚才买错了,咱们先变更配置到高可用版本



高可用配置,这里显示读写分离。

购买只读实例




设置代理终端,点击直接确定即可。


复制连接地址

也就是这个地址

尝试登录,没有问题,需要将项目中的配置文件的mysql地址修改成这个,才算使用上,这一点不再演示。
1. [root@web01 config]# mysql -umysql_db01 -pMysqldb01 -h jxjkffytkozbenzpd27c-rw4rm.rwlb.rds.aliyuncs.com
2. Welcome to the MariaDB monitor. Commands end with ; or \g.
3. Your MySQL connection id is 268436052
4. Server version: 5.7.40-log Source distribution
5.
6. Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
7.
8. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
9.
10. MySQL [(none)]> show databases;
11. +--------------------+
12. | Database |
13. +--------------------+
14. | information_schema |
15. | __recycle_bin__ |
16. | kodbox |
17. | mysql |
18. | performance_schema |
19. | sys |
20. +--------------------+
21. 6 rows in set (0.01 sec)
22.
23. MySQL [(none)]>