mkdir /usr/local/software/Apollo
将zip包传到/usr/local/software/Apollo下,解压缩。
在mysql命令终端下执行sql/apolloportaldb.sql 并验证
mysql> source /usr/local/software/Apollo/sql/apolloportaldb.sql
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
.......
mysql> select `Id`, `AppId`, `Name` from ApolloPortalDB.App;
+----+-----------+------------+
| Id | AppId | Name |
+----+-----------+------------+
| 1 | SampleApp | Sample App |
+----+-----------+------------+
1 row in set (0.00 sec)
在mysql命令终端下执行sql/apolloconfigdb.sql 并验证
mysql> source apolloconfigdb.sql
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (0.00 sec)
mysql> select `NamespaceId`, `Key`, `Value`, `Comment` from ApolloConfigDB.Item;
+-------------+---------+-------+----------------------+
| NamespaceId | Key | Value | Comment |
+-------------+---------+-------+----------------------+
| 1 | timeout | 100 | sample timeout配置 |
+-------------+---------+-------+----------------------+
1 row in set (0.00 sec)
[root@iZwz94664y88ud9aroa5veZ Apollo]# lsof -i:8080
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 17127 root 46u IPv4 4421816 0t0 TCP *:webcache (LISTEN)
发现被监听了,kill掉避免冲突!
修改demo.sh连接mysql的部分,其他不需要改:
vim demo.sh
#!/bin/bash
# apollo config db info
apollo_config_db_url=jdbc:mysql://localhost:3306/ApolloConfigDB?characterEncoding=utf8
apollo_config_db_username=root
apollo_config_db_password=xxxxxxxxxxxx
# apollo portal db info
apollo_portal_db_url=jdbc:mysql://localhost:3306/ApolloPortalDB?characterEncoding=utf8
apollo_portal_db_username=root
apollo_portal_db_password=xxxxxxxxx
# =============== Please do not modify the following content =============== #
要确保8070,8080,8090这三个端口没有占用!
[root@iZwz94664y88ud9aroa5veZ Apollo]# ./demo.sh start
==== starting service ====
Service logging file is ./service/apollo-service.log
Started [14223]
Waiting for config service startup.
...........
Config service started. You may visit http://localhost:8080 for service status now!
Waiting for admin service startup..
Admin service started
==== starting portal ====
Portal logging file is ./portal/apollo-portal.log
Started [14482]
Waiting for portal startup...........
Portal started. You can visit http://localhost:8070 now!
启动客户端
修改apollo配置中心的timeout配置为200
添加说明即可发布
可以看到客户端运行时,打印出了配置中心的改动!
root@iZwz94664y88ud9aroa5veZ Apollo]# ./demo.sh client
[apollo-demo][main]2020-03-31 18:53:08,026 INFO [com.ctrip.framework.foundation.internals.provider.DefaultApplicationProvider] App ID is set to SampleApp by app.id property from /META-INF/app.properties
[apollo-demo][main]2020-03-31 18:53:08,039 INFO [com.ctrip.framework.foundation.internals.provider.DefaultServerProvider] Environment is set to [dev] by JVM system property 'env'.
[apollo-demo][main]2020-03-31 18:53:08,105 INFO [com.ctrip.framework.apollo.internals.DefaultMetaServerProvider] Located meta services from apollo.meta configuration: http://localhost:8080!
[apollo-demo][main]2020-03-31 18:53:08,106 INFO [com.ctrip.framework.apollo.core.MetaDomainConsts] Located meta server address http://localhost:8080 for env DEV from com.ctrip.framework.apollo.internals.DefaultMetaServerProvider
Apollo Config Demo. Please input key to get the value. Input quit to exit.
>
> timeout
Loading key : timeout with value: 100
> Changes for namespace application
Change - key: timeout, oldValue: 100, newValue: 200, changeType: MODIFIED
而且timeout再次获取值变为200.
> timeout
Loading key : timeout with value: 200
>
http://ip:8080打开eureka可以看到注册的服务。
Eureka作为AdminService和ConfigService的服务注册中心提供服务发现的功能,提供java访问客户端给Portal和Apollo Client使用,但是对其他语言的Eureka就做不到支持了,于是Apollo架构引入了MetaServer作为Eureka的代理来对Portal和Apollo Client提供简单的http调用,这样就屏蔽了语言的异构性,做到通用。
架构图如下: