环境

window10
虚拟机:VMware Pro 12 centos7 、ubuntu16.04
CRT: 8
mysql:5.6

准备工作

虚拟机要准备好,我准备了两个centos7和一个ubuntu 16.04
window10 中装好MySQL

下载两个SQL

apolloportaldb.sql

apolloconfigdb.sql

执行上面SQL,创建好表;

apolloportaldb库的验证语句:

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

ApolloConfigDB库的验证语句:

select `Id`, `Key`, `Value`, `Comment` from `ApolloConfigDB`.`ServerConfig` limit 1;

我的设备环境

一台centos7虚拟机:地址:192.168.116.133(部署dev环境的apolloconfigapolloadmin

一台ubuntu虚拟机:地址:192.168.116.134(部署apolloportaldb

window10宿主机:地址:192.168.1.104 (装MySQL数据库)

下载安装包

也可以源码构建,但是目前我并不要二次改造,所以就直接下载安装包了

apollo-adminservice-1.5.1-github.zip
apollo-configservice-1.5.1-github.zip
apollo-portal-1.5.1-github.zip

最新版的地址:https://github.com/ctripcorp/apollo/releases

修改配置

下载了上面三个压缩包后,全部都解压;

修改apollo-configservice的配置

找到apollo-configservice-x.x.x-github/config/application-github.properties文件:

spring.datasource.url = jdbc:mysql://192.168.1.104:3306/ApolloConfigDB?useSSL=false&characterEncoding=utf8
spring.datasource.username = root
spring.datasource.password = root

因为我虚拟机上没有装mysql,所以我这里不能写localhost:3306,而是写window10主机的IP地址

修改apollo-adminservice的配置

找到apollo-adminservice-x.x.x-github/config/application-github.properties文件:

spring.datasource.url = jdbc:mysql://192.168.1.104:3306/ApolloConfigDB?useSSL=false&characterEncoding=utf8
spring.datasource.username = root
spring.datasource.password = root

修改apollo-portal的配置

找到将apollo-portal-x.x.x-github/config/apollo-env.properties文件:
目前我就部署dev环境

local.meta=http://localhost:8080
dev.meta=http://192.168.116.133:8080
# 假设还要部署fat环境
#fat.meta=http://192.168.116.135:8080

找到将apollo-portal-x.x.x-github/config/application-github.properties文件:

spring.datasource.url = jdbc:mysql://192.168.1.104:3306/ApolloConfigDB?useSSL=false&characterEncoding=utf8
spring.datasource.username = root
spring.datasource.password = root

修改MySQL数据库中数据

apolloconfigdb

找到serverconfig表中keyeureka.service.url,写eureka的地址;
又因为eurekaconfig目前的实现是和config是一个进程,所以只需要写config服务所在服务器的地址。
在这里插入图片描述

apolloportaldb

找到serverconfig表中keyapollo.portal.envs的数据

在这里插入图片描述

我这里只部署了dev,所以不用改,如果部署了devfatuat等,那么就要以逗号分割接着后面写;

开启MySQL远程连接

随便打开一个查询,执行如下SQL

# GRANT ALL PRIVILEGES ON *.* TO '账号'@'%' IDENTIFIED BY '密码';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root';

%代表所有主机,也可以具体到你的主机ip地址

window防火墙添加入站规则

因为虚拟机要远程访问window的数据库,得开放端口3306

虚拟机开放8080和8090端口

因为apollopartaldb需要去连接apolloconfig
所以apolloconfig所在的服务器,需要开放80808090端口

具体怎么开后门,根据自己的环境百度吧~

部署

再次打包成压缩包

window直接使用压缩软件进行压缩。

上传到虚拟机

可以使用rz命令进行上传。

再使用unzip进行解压

先启动apollo-configservice

我的路径:

/home/yutao/programefile/apollo/apollo-configservice-1.5.1-github/scripts

修改执行权:

sudo chmod 755 ./startup.sh
sudo chmod 755 ./shutdown.sh

然后执行:

[yutao@localhost scripts]$ ./startup.sh

提示
启动日志里面会报错误:

com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: 拒绝连接 (Connection refused)
        at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:187)
        at com.sun.jersey.api.client.filter.GZIPContentEncodingFilter.handle(GZIPContentEncodingFilter.java:123)
        at com.netflix.discovery.EurekaIdentityHeaderFilter.handle(EurekaIdentityHeaderFilter.java:27)
        at com.sun.jersey.api.client.Client.handle(Client.java:652)
        at com.sun.jersey.api.client.WebResource.handle(WebResource.java:682)
        at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74)
        at com.sun.jersey.api.client.WebResource$Builder.post(WebResource.java:570)
        at com.netflix.discovery.shared.transport.jersey.AbstractJerseyEurekaHttpClient.register(AbstractJerseyEurekaHttpClient.java:56)
        at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$1.execute(EurekaHttpClientDecorator.java:59)
        at com.netflix.discovery.shared.transport.decorator.MetricsCollectingEurekaHttpClient.execute(MetricsCollectingEurekaHttpClient.java:73)
        at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.register(EurekaHttpClientDecorator.java:56)
        at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$1.execute(EurekaHttpClientDecorator.java:59)
        at com.netflix.discovery.shared.transport.decorator.RedirectingEurekaHttpClient.executeOnNewServer(RedirectingEurekaHttpClient.java:118)
        at com.netflix.discovery.shared.transport.decorator.RedirectingEurekaHttpClient.execute(RedirectingEurekaHttpClient.java:79)
        at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.register(EurekaHttpClientDecorator.java:56)
        at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$1.execute(EurekaHttpClientDecorator.java:59)
        at com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient.execute(RetryableEurekaHttpClient.java:120)
        at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.register(EurekaHttpClientDecorator.java:56)
        at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$1.execute(EurekaHttpClientDecorator.java:59)
        at com.netflix.discovery.shared.transport.decorator.SessionedEurekaHttpClient.execute(SessionedEurekaHttpClient.java:77)
        at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.register(EurekaHttpClientDecorator.java:56)
        at com.netflix.discovery.DiscoveryClient.register(DiscoveryClient.java:829)
        at com.netflix.discovery.InstanceInfoReplicator.run(InstanceInfoReplicator.java:121)
        at com.netflix.discovery.InstanceInfoReplicator$1.run(InstanceInfoReplicator.java:101)
        at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
Caused by: java.net.ConnectException: 拒绝连接 (Connection refused)
        at java.net.PlainSocketImpl.socketConnect(Native Method)
        at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
        at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
        at java.net.Socket.connect(Socket.java:606)
        at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:121)
        at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:180)
        at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:144)
        at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:134)
        at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:610)
        at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:445)
        at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:835)
        at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:118)
        at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56)
        at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:173)
        ... 30 common frames omitted

2020-01-12 23:20:52.709  WARN 12525 --- [DiscoveryClient-InstanceInfoReplicator-0] c.n.d.s.t.d.RetryableEurekaHttpClient    : Request execution failed with message: java.net.ConnectException: 拒绝连接 (Connection refused)
2020-01-12 23:20:52.709  WARN 12525 --- [DiscoveryClient-InstanceInfoReplicator-0] com.netflix.discovery.DiscoveryClient    : DiscoveryClient_APOLLO-CONFIGSERVICE/localhost:apollo-configservice:8080 - registration failed Cannot execute request on any known server

刚启动报这个错是正常的,因为config service要向eureka注册,但是eureka还没启动好(因为eurekaconfig service是同一个进程),过一会儿就OK了。

启动apollo-adminservice

和上面类似的步骤;
先修改执行权,再执行./startup.sh来启动。

启动apollo-portal

和上面类似的步骤;
先修改执行权,再执行./startup.sh来启动。

访问

http://192.168.116.134:8070

参考地址:

分布式部署指南

启动错误

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐