携程分布式mysql_携程 Apollo分布式部署

一、环境准备

操作系统:CentOS release 7.5 (启动脚本理论上支持所有Linux发行版,建议CentOS 7)JDK :jdk1.8.0_162 (建议安装Java 1.8+)

MySQL:5.7.26(Apollo的表结构对timestamp使用了多个default声明,所以需要5.6.5以上版本)

架构:(官方默认支持DEV(开发环境)、FAT(功能测试)、UAT(回归测试)、PRO(生产环境),由于机器有限,只部署Dev,Pro)

Portal service:172.16.150.131Dev config&& admin 172.16.150.132Pro config&& admin 172.16.150.133

二、服搭建数据库服务及创建相关库

1.搭建MySQL

wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm

rpm -ivh mysql80-community-release-el7-3.noarch.rpm

vim mysql-community.repo #启动5.7,禁用8.0

039cf37e24e9303efb0b63ec529b9da8.png

安装MySQL

yum clean all &&yum makecache

yum install mysql-community-server -y

2.优化MySQL配置

8f900a89c6347c561fdf2122f13be562.png

961ddebeb323a10fe0623af514929fc1.png

[mysqld]

#

# Remove leading # andset to the amount of RAM forthe most important data

# cachein MySQL. Start at 70% of total RAM for dedicated server, else 10%.

# innodb_buffer_pool_size=128M

#

# Remove leading # to turn on a very important data integrity option: logging

# changes to the binary log between backups.

# log_bin

#

# Remove leading # toset options mainly useful forreporting servers.

# The server defaults are fasterfortransactions and fast SELECTs.

# Adjust sizesasneeded, experiment to find the optimal values.

# join_buffer_size=128M

# sort_buffer_size=2M

# read_rnd_buffer_size=2M

datadir=/var/lib/mysql

socket=/var/lib/mysql/mysql.sock

read_buffer_size= 4777216read_rnd_buffer_size= 8554432sort_buffer_size= 8554432tmp_table_size= 32108864join_buffer_size= 64217728slow_query_log= 1slow_query_log_file= /var/lib/mysql/slow.log

log_queries_not_using_indexes= 1log_slow_admin_statements= 1log_slow_slave_statements= 1log_throttle_queries_not_using_indexes= 10expire_logs_days= 7long_query_time= 2min_examined_row_limit= 100binlog-rows-query-log-events = 1log-bin-trust-function-creators = 1log-slave-updates = 1innodb_log_file_size=300M

innodb_page_size= 16384innodb_buffer_pool_size=300M

innodb_buffer_pool_instances= 8innodb_buffer_pool_load_at_startup= 1innodb_buffer_pool_dump_at_shutdown= 1innodb_lru_scan_depth= 4096innodb_lock_wait_timeout= 5innodb_io_capacity= 10000innodb_io_capacity_max= 20000innodb_flush_method=O_DIRECT

innodb_file_format=Barracuda

innodb_file_format_max=Barracuda

innodb_undo_logs= 128innodb_flush_neighbors= 0innodb_log_buffer_size= 16777216innodb_purge_threads= 4innodb_large_prefix= 1innodb_thread_concurrency= 64innodb_print_all_deadlocks= 1innodb_strict_mode= 1innodb_sort_buffer_size= 67108864innodb_write_io_threads= 16innodb_read_io_threads= 16innodb_file_per_table= 1innodb_stats_persistent_sample_pages= 64innodb_autoinc_lock_mode= 2# Disabling symbolic-links isrecommended to prevent assorted security risks

symbolic-links=0log-error=/var/log/mysqld-error.log

pid-file=/var/run/mysqld/mysqld.pid

my.cnf

启动MySQL服务并设置登录密码

systemctl start mysqld

grep"temporary password" /var/log/mysqld.log #获取MySQL初始化密码

mysql-uroot -p

Enter password:

Welcome to the MySQL monitor. Commands end with ; or \g.

Your MySQL connection idis 152Server version:5.7.26MySQL Community Server (GPL) #MySQL版本号

...

mysql>show databases;

ERROR1820 (HY000): You must reset your password using ALTER USER statement before executing thisstatement. #默认第一次登录MySQL需要重新设置root密码,否则报错

mysql> alter user 'root'@'localhost' identified by 'Qgg12#45'; #密码要符合一定的强度,或者修改MySQL密码策略

Query OK,0 rows affected (0.00sec)

mysql>flush privileges;

Query OK,0 rows affected (0.00sec)

mysql>\q

Bye

#以上操作在三台服务器都需要执行

2.创建Apollo PortalDB数据库(在Portal service:172.16.150.131服务器上操作)

wget https://raw.githubusercontent.com/ctripcorp/apollo/master/scripts/db/migration/portaldb/V1.0.0__initialization.sql #下载官方提供的SQL文件

mysql -uroot -p

mysql> source /root/V1.0.0__initialization.sql #手动导入

show databases;

use ApolloPortalDB;

show tables;select `Id`, `Key`, `Value`, `Comment` from `ApolloPortalDB`.`ServerConfig` limit 1;

3.创建ApolloConfigDB数据库(172.16.150.132、172.16.150.133上部署)

wget https://raw.githubusercontent.com/ctripcorp/apollo/master/scripts/db/migration/configdb/V1.0.0__initialization.sqlsource/root/V1.0.0__initialization.sqlselect `Id`, `Key`, `Value`, `Comment` from `ApolloConfigDB`.`ServerConfig` limit 1;

三、安装Apollo服务

1.安装apollo-portal 服务(在Portal service:172.16.150.131服务器上执行)

https://github.com/ctripcorp/apollo/releases/download/v1.4.0/apollo-portal-1.4.0-wget github.zip

unzip apollo-portal-1.4.0-github.zip

cd apollo-portal/cat config/application-github.properties #ApolloPortalDB数据库连接串信息

# DataSource

spring.datasource.url= jdbc:mysql://172.16.150.131:3306/ApolloPortalDB?characterEncoding=utf8

spring.datasource.username =xxxx

spring.datasource.password=xxx

cat config/apollo-env.properties #配置apollo-portal的meta service信息

dev.meta=http://172.16.150.132:8080

pro.meta=http://172.16.150.133:8080

修改Apollo-portal启动脚本

[root@localhost ~]# grep "^export JAVA_OPTS" apollo-portal/scripts/startup.sh #根据实际情况修改相应的值

export JAVA_OPTS="-server -Xms1024m -Xmx1024m -Xss256k -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=256m -XX:NewSize=512m -XX:MaxNewSize=512m -XX:SurvivorRatio=8"

2.配置apollo-configservice、apollo-adminservice(172.16.150.132、172.16.150.133上操作)

https://github.com/ctripcorp/apollo/releases/download/v1.4.0/apollo-adminservice-1.4.0-github.zip

https://github.com/ctripcorp/apollo/releases/download/v1.4.0/apollo-configservice-1.4.0-github.zip

unzip apollo-adminservice-1.4.0-github.zip

unzip apollo-configservice-1.4.0-github.zip

[root@localhost~]# cat apollo-adminservice/config/application-github.properties

# DataSource

spring.datasource.url= jdbc:mysql://172.16.150.132:3306/ApolloConfigDB?characterEncoding=utf8 #注意修改MySQL连接地址

spring.datasource.username =root

spring.datasource.password=xxxx

[root@localhost~]# cat apollo-configservice/config/application-github.properties #注意修改MySQL连接地址

# DataSource

spring.datasource.url= jdbc:mysql://172.16.150.132:3306/ApolloConfigDB?characterEncoding=utf8

spring.datasource.username =root

spring.datasource.password= xxx

修改apollo-configservice、apollo-adminservice启动脚本

[root@localhost ~]# grep "^export JAVA_OPTS" apollo-configservice/scripts/startup.sh #根据实际情况修改相应的值

export JAVA_OPTS="-server -Xms1024m -Xmx1024m -Xss256k -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=256m -XX:NewSize=512m -XX:MaxNewSize=512m -XX:SurvivorRatio=8"

[root@localhost ~]# grep "^export JAVA_OPTS" apollo-adminservice/scripts/startup.sh

export JAVA_OPTS="-server -Xms1024m -Xmx1024m -Xss256k -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=256m -XX:NewSize=512m -XX:MaxNewSize=512m -XX:SurvivorRatio=8"

3.启动服务

#要先启动apollo-configservice再启动apollo-adminservice等所有apollo-configservice和apollo-adminservice启动完成后再启动apollo-portal

scripts/startup.sh #启动

scripts/shutdown.sh #关闭服务

日志文件查看

apollo-configservice /opt/logs/100003171/ #日志路径启动脚本中可定义路径apollo-adminservice /opt/logs/100003172apollo-portal     /opt/logs/100003173

登录Apollo,浏览器访问apollo-portal服务,端口8070,初始用户名是apollo,密码是admin

20a7bb51927a4ba8f5d86248a0cadc4f.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值