攜程 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.131 Dev config&& admin 172.16.150.132 Pro config && admin 172.16.150.133 #自定義環境參考:https://github.com/ctripcorp/apollo/wiki/%E9%83%A8%E7%BD%B2&%E5%BC%80%E5%8F%91%E9%81%87%E5%88%B0%E7%9A%84%E5%B8%B8%E8%A7%81%E9%97%AE%E9%A2%98#42-%E6%B7%BB%E5%8A%A0%E8%87%AA%E5%AE%9A%E4%B9%89%E7%9A%84%E7%8E%AF%E5%A2%83

關閉防火牆 同步時間

#注意事項:
如果實際部署的機器有多塊網卡(如docker),或者存在某些網卡的IP是Apollo客戶端和Portal無法訪問的(如網絡安全限制),那么我們就需要在apollo-configserviceapollo-adminservice中做相關限制以避免Eureka將這些網卡的IP注冊到Meta Server。
參考地址:https://github.com/ctripcorp/apollo/wiki/%E5%88%86%E5%B8%83%E5%BC%8F%E9%83%A8%E7%BD%B2%E6%8C%87%E5%8D%97#14%E7%BD%91%E7%BB%9C%E7%AD%96%E7%95%A5

二、服搭建數據庫服務及創建相關庫

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

 安裝MySQL

yum clean all && yum makecache
yum install mysql-community-server -y

 2.優化MySQL配置

[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in 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 # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, 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 = 4777216
read_rnd_buffer_size = 8554432
sort_buffer_size = 8554432
tmp_table_size = 32108864
join_buffer_size = 64217728



slow_query_log = 1
slow_query_log_file = /var/lib/mysql/slow.log
log_queries_not_using_indexes = 1
log_slow_admin_statements = 1
log_slow_slave_statements = 1
log_throttle_queries_not_using_indexes = 10
expire_logs_days = 7
long_query_time = 2
min_examined_row_limit = 100
binlog-rows-query-log-events = 1
log-bin-trust-function-creators = 1
log-slave-updates = 1


innodb_log_file_size=300M
innodb_page_size = 16384
innodb_buffer_pool_size = 300M
innodb_buffer_pool_instances = 8
innodb_buffer_pool_load_at_startup = 1
innodb_buffer_pool_dump_at_shutdown = 1
innodb_lru_scan_depth = 4096
innodb_lock_wait_timeout = 5
innodb_io_capacity = 10000
innodb_io_capacity_max = 20000
innodb_flush_method = O_DIRECT
innodb_file_format = Barracuda
innodb_file_format_max = Barracuda
innodb_undo_logs = 128
innodb_flush_neighbors = 0
innodb_log_buffer_size = 16777216
innodb_purge_threads = 4
innodb_large_prefix = 1
innodb_thread_concurrency = 64
innodb_print_all_deadlocks = 1
innodb_strict_mode = 1
innodb_sort_buffer_size = 67108864
innodb_write_io_threads = 16
innodb_read_io_threads = 16
innodb_file_per_table = 1
innodb_stats_persistent_sample_pages = 64
innodb_autoinc_lock_mode = 2

# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0

log-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 id is 152
Server version: 5.7.26 MySQL Community Server (GPL)   #MySQL版本號
...
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.  #默認第一次登錄MySQL需要重新設置root密碼,否則報錯

mysql> alter user 'root'@'localhost' identified by 'Qgg12#45';  #密碼要符合一定的強度,或者修改MySQL密碼策略
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

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.sql  source /root/V1.0.0__initialization.sql select `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/100003172 apollo-portal     /opt/logs/100003173

登錄Apollo,瀏覽器訪問apollo-portal服務,端口8070,初始用戶名是apollo,密碼是admin

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM