# Apollo安裝
准備:
環境要求:jdk1.8 mysql5.7.27
下載:https://github.com/ctripcorp/apollo/wiki

***
上傳壓縮包:

在Apollo目錄下創建三個文件夾,因為在同一目錄下解壓會有名稱相同的文件。
在三個文件夾下分別解壓,logs是記錄日志的文件。
下載sql文件:生成數據庫:
地址:同上找一下。apolloconfigdb.sql和apolloportaldb.sql 導入MySQL生成數據庫。
上傳sql文件到/root/目錄下:

導入mysql:
~~~shell
mysql> source /root/apolloconfigdb.sql
mysql> source /root/apolloportaldb.sql
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| ApolloConfigDB |
| ApolloPortalDB |
| mysql |
| performance_schema |
| sys |
+--------------------+
6 rows in set (0.00 sec)
mysql> flush privileges;
~~~

***
### 三個服務的配置信息:
#### 修改一:
~~~shell
每個對應文件下有個/config/application-github.properties文件,修改數據庫url 用戶 密碼。
[root@docker-angent_1 ~]# cd /apollo/adminservice/apollo-adminservice-1.3.0/config/
[root@docker-angent_1 config]# vim application-github.properties
# DataSource
spring.datasource.url = jdbc:mysql://10.160.103.100:3306/ApolloConfigDB?characterEncoding=utf8
spring.datasource.username = root
spring.datasource.password = 123
別遺漏,改三個文件!!
~~~

***
#### 修改二:
~~~shell
修改startup.sh文件:
同樣:每個對應文件下有個scripts/startup.sh文件
[root@docker-angent_1 scripts]# pwd
/apollo/adminservice/apollo-adminservice-1.3.0/scripts
[root@docker-angent_1 scripts]# vim startup.sh
#!/bin/bash
SERVICE_NAME=apollo-adminservice
## Adjust log dir if necessary
LOG_DIR=/apollo/logs 修改日志地址
## Adjust server port if necessary
SERVER_PORT=9002 是否被占用
別遺漏,改三個文件!!
~~~

***
#### 修改三:
~~~shell
修改portal服務下的meta配置:
[root@docker-angent_1 ~]# cd /apollo/portal/apollo-portal-1.3.0/config
[root@docker-angent_1 config]# vim apollo-env.properties
local.meta=http://localhost:9001
dev.meta=http://localhost:9001
fat.meta=http://fill-in-fat-meta-server:8080
uat.meta=http://fill-in-uat-meta-server:8080
lpt.meta=${lpt_meta}
pro.meta=http://fill-in-pro-meta-server:8080
~~~
***
### 修改數據庫meta地址:
~~~shell
mysql> use ApolloConfigDB;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> show tables;
+--------------------------+
| Tables_in_ApolloConfigDB |
+--------------------------+
| AccessKey |
| App |
| AppNamespace |
| Audit |
| Cluster |
| Commit |
| GrayReleaseRule |
| Instance |
| InstanceConfig |
| Item |
| Namespace |
| NamespaceLock |
| Release |
| ReleaseHistory |
| ReleaseMessage |
| ServerConfig |
+--------------------------+
16 rows in set (0.01 sec)
mysql> use ServerConfig;
ERROR 1049 (42000): Unknown database 'ServerConfig'
mysql> select * from ServerConfig;
+----+------------------------------+---------+-------------------------------+---------------------------------------------------------------------------------------------+-----------+----------------------+------------------------+---------------------------+---------------------+
| Id | Key | Cluster | Value | Comment | IsDeleted | DataChange_CreatedBy | DataChange_CreatedTime | DataChange_LastModifiedBy | DataChange_LastTime |
+----+------------------------------+---------+-------------------------------+---------------------------------------------------------------------------------------------+-----------+----------------------+------------------------+---------------------------+---------------------+
| 1 | eureka.service.url | default | http://localhost:8080/eureka/ | Eureka服務Url,多個service以英文逗號分隔 | | default | 2020-11-27 14:28:57 | | 2020-11-27 14:28:57 |
| 2 | namespace.lock.switch | default | false | 一次發布只能有一個人修改開關 | | default | 2020-11-27 14:28:57 | | 2020-11-27 14:28:57 |
| 3 | item.value.length.limit | default | 20000 | item value最大長度限制 | | default | 2020-11-27 14:28:57 | | 2020-11-27 14:28:57 |
| 4 | config-service.cache.enabled | default | false | ConfigService是否開啟緩存,開啟后能提高性能,但是會增大內存消耗! | | default | 2020-11-27 14:28:57 | | 2020-11-27 14:28:57 |
| 5 | item.key.length.limit | default | 128 | item key 最大長度限制 | | default | 2020-11-27 14:28:57 | | 2020-11-27 14:28:57 |
+----+------------------------------+---------+-------------------------------+---------------------------------------------------------------------------------------------+-----------+----------------------+------------------------+---------------------------+---------------------+
5 rows in set (0.00 sec)
mysql> exit
# eureka地址修改為真實的地址:
mysql> update ServerConfig set Value="http://10.162.1.76:8761/eureka/" where id = 1;
-----------------------------------------------------------
設置最大連接數為1500、默認是100太小了。
mysql> show variables like 'max_connections';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 1000 |
+-----------------+-------+
1 row in set (0.02 sec)
mysql> set global max_connections = 1500;
Query OK, 0 rows affected (0.00 sec)
mysql> show variables like 'max_connections';
+-----------------+-------+
| Variable_name | Value |
+-----------------+-------+
| max_connections | 1500 |
+-----------------+-------+
1 row in set (0.00 sec)
~~~

***
#### 啟動三個服務
啟動三個/scripts/startup.sh 注意服務的啟動順序:
configservice—adminservice—portal
### 核算微服務apollo配置與使用
1. 使用apollo新建項目添加配置文件
1.1. 登錄apollo
測試環境地址:http://10.162.1.76:9003/
用戶名:apollo
密碼:admin
1.2. 新建項目

輸入ID與名稱,一般與應用名保持一致,輸入完成點擊提交

默認application.properties,核算配置文件為application.yml,需要新建namespace,點擊添加namespace

點擊創建namespace

點擊private

選擇yml輸入application,點擊提交

點擊返回項目首頁

點擊編輯

粘貼進去配置文件的所有內容(注意license內容是單行的,出現以下情況需要刪除回車符),然后點擊✔號

點擊發布


這樣apollo項目就建好了,如果一個應用在多個環境使用apollo配置,只需要新建集群即可,步驟如下:
點擊添加集群

輸入集群名稱

點擊返回項目首頁,這樣就有一個環境單獨使用的配置

按照之前步驟添加配置信息即可
1.3. 修改項目配置使用apollo
在配置文件bootstrap.yml中添加apollo
注意信息如下如果多個環境新建了多個集群,每個環境的cluster都要改為相應的集群名稱
app:
id: ycloans-file-service
apollo:
meta: http://10.200.9.7:9001
cluster: DEV #集群名稱
cacheDir: ../apollo/ #apollo配置文件存放目錄
bootstrap:
enabled: ***\*true\****
namespace: application.yml
應用的main方法添加相應的注解
@EnableApolloConfig({"application.yml"})

以上就完成了apollo的配置使用。
ycloans-pay-service (namespace 配置)
~~~shell
EUREKA:
eureka.instance.prefer-ip-address = true
eureka.instance.instanceId = ${spring.cloud.client.ip-address}:${spring.application.name}:${server.port}
eureka.instance.lease-renewal-interval-in-seconds = 5
eureka.instance.lease-expiration-duration-in-seconds = 10
eureka.instance.status-page-url-path = /management/info
eureka.instance.health-check-url-path = /management/health
eureka.instance.metadata-map.profile = ${spring.profiles.active}
eureka.instance.metadata-map.version = ${info.project.version}
eureka.client.service-url.defaultZone = http://10.162.1.76:8761/eureka/,http://10.162.1.100:8762/eureka/
eureka.client.enabled = true
eureka.client.healthcheck.enabled = true
eureka.client.fetch-registry = true
eureka.client.register-with-eureka = true
eureka.client.instance-info-replication-interval-seconds = 10
eureka.client.registry-fetch-interval-seconds = 10
----------------------------------------------------------
############################################
#### ActiveMq 消息隊列配置
############################################
# 采用的消息隊列類型:
# 0-default,僅內存模擬
# 1-redisMq
# 2-activeMq
spring.mq.type = 2
# 消費通知方式 0-開啟線程調用borker接口; 1-開啟線程放入消息隊列
# 如果此值被設置成1,則broker啟動時需要開啟監聽通知結果的隊列,隊列命名
# 規則是: 業務對列:result
reliable.message.consumer.notify.type = 1
reliable.message.consumer.notify.thread.corePerSize = 100
reliable.message.consumer.notify.thread.maxPerSize = 500
reliable.message.consumer.notify.thread.keepAliveTime = 500
reliable.message.consumer.notify.thread.blockingQueueSize = 500
test.activemq.net-address = 127.0.0.1
# spring.activemq.broker-url = tcp://10.162.1.245:61616 測試環境
spring.activemq.broker-url = tcp://10.162.1.100:61616
#spring.activemq.broker-url = tcp://activemq-net:61616
spring.activemq.user = admin
spring.activemq.password = admin
# 在考慮結束之前等待的時間
spring.activemq.close-timeout = 15s
# 默認代理URL是否應該在內存中。如果指定了顯式代理,則忽略此值。
spring.activemq.in-memory = false
# 是否在回滾消息之前停止消息傳遞。這意味着當啟用此命令時,消息順序不會被保留。
spring.activemq.non-blocking-redelivery = false
# 等待消息發送響應的時間。設置為0等待永遠。
spring.activemq.send-timeout = 0
spring.activemq.queue-name = aa:pay:mock
spring.activemq.response-queue-name = aa:pay:mock:result
# 表示使用Topic模式還是queue模式,默認使用topic模式
spring.activemq.toTopic = true
spring.pool.enabled = true
spring.pool.max-connections = 10
spring.pool.idle-timeout = 30000
#默認情況下activemq提供的是queue模式,若要使用topic模式需要配置下面配置
spring.jms.pub-sub-domain = true
# 是否信任所有包
#spring.activemq.packages.trust-all=
# 要信任的特定包的逗號分隔列表(當不信任所有包時)
#spring.activemq.packages.trusted=
# 當連接請求和池滿時是否阻塞。設置false會拋“JMSException異常”。
#spring.activemq.pool.block-if-full=true
# 如果池仍然滿,則在拋出異常前阻塞時間。
#spring.activemq.pool.block-if-full-timeout=-1ms
# 是否在啟動時創建連接。可以在啟動時用於加熱池。
#spring.activemq.pool.create-connection-on-startup=true
# 是否用Pooledconnectionfactory代替普通的ConnectionFactory。
#spring.activemq.pool.enabled=false
# 連接過期超時。
#spring.activemq.pool.expiry-timeout=0ms
# 連接空閑超時
#spring.activemq.pool.idle-timeout=30s
# 連接池最大連接數
#spring.activemq.pool.max-connections=1
# 每個連接的有效會話的最大數目。
#spring.activemq.pool.maximum-active-session-per-connection=500
# 當有"JMSException"時嘗試重新連接
#spring.activemq.pool.reconnect-on-exception=true
# 在空閑連接清除線程之間運行的時間。當為負數時,沒有空閑連接驅逐線程運行。
#spring.activemq.pool.time-between-expiration-check=-1ms
# 是否只使用一個MessageProducer
#spring.activemq.pool.use-anonymous-producers=true
----------------------------------
YCLOANS-PUBLIC:
license.licenseContext = <?xml version="1.0" encoding="UTF-8"?><license build-time="Mon May 06 11:39:46 CST 2019" validate-code="FC6107A40B8E7CF356B4EC5CC39A9CA6"><element name="license_code">0000011874</element><element name="product_code">0000001122</element><element name="product_name_zh-cn">宇信科技基於微服務框架統一開發平台</element><element name="product_name_en-us">YUSP</element><element name="version_major">1</element><element name="version_sub">0</element><element name="version_publish">1</element><element name="complie_date">2018-03-20</element><element name="license_type">內部試用許可證</element><element name="customer_name"/><element name="contract_code"/><element name="license_start_time">2019-05-06</element><element name="license_end_time">2119-06-01</element></license>
license.licenseModel = TRIAL
management.health.rabbit.enabled = false
management.health.ycloansmq.enabled = true
management.endpoints.web.base-path = /api/system/actuator
management.endpoint.health.show-details = always
management.endpoints.web.exposure.include = *
management.security.enabled = false
swagger.enabled = true
swagger.title = YUSP APP ycloans-starter Application API
swagger.description = YUSP APP ycloans-starter API documentation
swagger.version = 2.1.1.RELEASE
spring.liquibase.enabled = false
spring.liquibase.change-log = classpath:config/liquibase/master.xml
spring.cloud.inetutils.preferred-networks = 172.20.*
spring.jackson.serialization.INDENT_OUTPUT = true
spring.messages.cache-duration = 1
pagehelper.helperDialect = mysql
pagehelper.reasonable = true
mapper.mappers[0] = cn.com.yusys.yusp.commons.mapper.CommonMapper
-----------------------------------------------
MYSQL:
######################################
## MYSQL數據庫配置
######################################
spring.datasource.url = jdbc:mysql://10.162.1.102:3306/apolloconfigdb?useUnicode=true&characterEncoding=utf8&useSSL=false
spring.datasource.username = apollo
spring.datasource.password = apollo
spring.datasource.hikari.minimum-idle = 20
spring.datasource.hikari.maximum-pool-size = 500
spring.datasource.hikari.data-source-properties.cachePrepStmts = true
spring.datasource.hikari.data-source-properties.prepStmtCacheSize = 250
spring.datasource.hikari.data-source-properties.prepStmtCacheSqlLimit = 2048
spring.datasource.hikari.data-source-properties.useServerPrepStmts = true
# 特別注意此處,否則存儲mysql將無效
mybatis.mapperLocations = classpath*:mapper/**/*.xml
mybatis.configuration.map-underscore-to-camel-case = true
~~~




ycloans-agent-service
~~~shell
application:
spring.application.name = ycloans-pay-service
spring.liquibase.enabled = false
spring.liquibase.change-log = classpath:config/liquibase/master.xml
spring.cloud.inetutils.preferred-networks = 10
spring.cloud.inetutils.ignored-interfaces = lo,lo:0
spring.jackson.serialization.INDENT_OUTPUT = true
spring.datasource.driver-class-name = oracle.jdbc.OracleDriver
spring.datasource.type = com.zaxxer.hikari.HikariDataSource
spring.datasource.url = jdbc:oracle:thin:@10.162.1.57:1521:orcl
spring.datasource.username = ycloanspay
spring.datasource.password = ycloanspay
spring.datasource.hikari.minimum-idle = 2
spring.datasource.hikari.maximum-pool-size = 2
spring.datasource.hikari.data-source-properties.cachePrepStmts = true
spring.datasource.hikari.data-source-properties.prepStmtCacheSize = 250
spring.datasource.hikari.data-source-properties.prepStmtCacheSqlLimit = 2048
spring.datasource.hikari.data-source-properties.useServerPrepStmts = true
spring.messages.cache-duration = 1
############################################
#### ActiveMq 消息隊列配置
############################################
# 采用的消息隊列類型:
# 0-default,僅內存模擬
# 1-redisMq
# 2-activeMq
spring.mq.type = 2
# 消費通知方式 0-開啟線程調用borker接口; 1-開啟線程放入消息隊列
# 如果此值被設置成1,則broker啟動時需要開啟監聽通知結果的隊列,隊列命名
# 規則是: 業務對列:result
reliable.message.consumer.notify.type = 1
reliable.message.consumer.notify.thread.corePerSize = 100
reliable.message.consumer.notify.thread.maxPerSize = 500
reliable.message.consumer.notify.thread.keepAliveTime = 500
reliable.message.consumer.notify.thread.blockingQueueSize = 500
test.activemq.net-address = 127.0.0.1
# spring.activemq.broker-url = tcp://10.162.1.245:61616 測試環境
spring.activemq.broker-url = tcp://10.162.1.100:61616
#spring.activemq.broker-url = tcp://activemq-net:61616
spring.activemq.user = admin
spring.activemq.password = admin
# 在考慮結束之前等待的時間
spring.activemq.close-timeout = 15s
# 默認代理URL是否應該在內存中。如果指定了顯式代理,則忽略此值。
spring.activemq.in-memory = false
# 是否在回滾消息之前停止消息傳遞。這意味着當啟用此命令時,消息順序不會被保留。
spring.activemq.non-blocking-redelivery = false
# 等待消息發送響應的時間。設置為0等待永遠。
spring.activemq.send-timeout = 0
spring.activemq.queue-name = CommonPaySendQueue
spring.activemq.response-queue-name = CommonPayResultQueue
spring.activemq.topic-name = abc
spring.activemq.respone-topic-name = abc
# 表示使用Topic模式還是queue模式,默認使用topic模式
spring.activemq.toTopic = true
spring.pool.enabled = true
spring.pool.max-connections = 10
spring.pool.idle-timeout = 30000
#默認情況下activemq提供的是queue模式,若要使用topic模式需要配置下面配置
spring.jms.pub-sub-domain = true
############################################
#### 業務參數配置
############################################
moneyPay.pay = http://10.162.4.92:8080/paybatch/receipt/order11
moneyPay.qry = http://10.162.4.92:8080/paybatch/receipt/query11
moneyPay.notify = http://10.162.4.92:8080/paybatch/receipt/batch/state/notify11
############################################
#### 注冊中心 配置
############################################
eureka.instance.prefer-ip-address = true
eureka.instance.instanceId = ${spring.cloud.client.ip-address}:${spring.application.name}:${server.port}
eureka.instance.lease-renewal-interval-in-seconds = 5
eureka.instance.lease-expiration-duration-in-seconds = 10
eureka.instance.status-page-url-path = /management/info
eureka.instance.health-check-url-path = /management/health
eureka.instance.metadata-map.profile = ${spring.profiles.active}
eureka.instance.metadata-map.version = ${info.project.version}
eureka.client.service-url.defaultZone = http://10.162.1.76:8761/eureka/,http://10.162.1.100:8762/eureka/
eureka.client.enabled = true
eureka.client.healthcheck.enabled = true
eureka.client.fetch-registry = true
eureka.client.register-with-eureka = true
eureka.client.instance-info-replication-interval-seconds = 10
eureka.client.registry-fetch-interval-seconds = 10
~~~

ycloans-common-reliable-message
~~~shell
EUREKA:
eureka.instance.prefer-ip-address = true
eureka.instance.instanceId = ${spring.cloud.client.ip-address}:${spring.application.name}:${server.port}
eureka.instance.lease-renewal-interval-in-seconds = 5
eureka.instance.lease-expiration-duration-in-seconds = 10
eureka.instance.status-page-url-path = /management/info
eureka.instance.health-check-url-path = /management/health
eureka.instance.metadata-map.profile = ${spring.profiles.active}
eureka.instance.metadata-map.version = ${info.project.version}
eureka.client.service-url.defaultZone = http://10.162.1.76:8761/eureka/,http://10.162.1.100:8762/eureka/
eureka.client.enabled = true
eureka.client.healthcheck.enabled = true
eureka.client.fetch-registry = true
eureka.client.register-with-eureka = true
eureka.client.instance-info-replication-interval-seconds = 10
eureka.client.registry-fetch-interval-seconds = 10
--------------------------------
ActiveMq:
############################################
#### ActiveMq 消息隊列配置
############################################
# 采用的消息隊列類型:
# 0-default,僅內存模擬
# 1-redisMq
# 2-activeMq
spring.mq.type = 2
# 消費通知方式 0-開啟線程調用borker接口; 1-開啟線程放入消息隊列
# 如果此值被設置成1,則broker啟動時需要開啟監聽通知結果的隊列,隊列命名
# 規則是: 業務對列:result
reliable.message.consumer.notify.type = 1
reliable.message.consumer.notify.thread.corePerSize = 100
reliable.message.consumer.notify.thread.maxPerSize = 500
reliable.message.consumer.notify.thread.keepAliveTime = 500
reliable.message.consumer.notify.thread.blockingQueueSize = 500
test.activemq.net-address = 127.0.0.1
# spring.activemq.broker-url = tcp://10.162.1.245:61616 測試環境
spring.activemq.broker-url = tcp://10.162.1.100:61616
#spring.activemq.broker-url = tcp://activemq-net:61616
spring.activemq.user = admin
spring.activemq.password = admin
# 在考慮結束之前等待的時間
spring.activemq.close-timeout = 15s
# 默認代理URL是否應該在內存中。如果指定了顯式代理,則忽略此值。
spring.activemq.in-memory = false
# 是否在回滾消息之前停止消息傳遞。這意味着當啟用此命令時,消息順序不會被保留。
spring.activemq.non-blocking-redelivery = false
# 等待消息發送響應的時間。設置為0等待永遠。
spring.activemq.send-timeout = 0
spring.activemq.queue-name = aa:pay:mock
spring.activemq.response-queue-name = aa:pay:mock:result
# 表示使用Topic模式還是queue模式,默認使用topic模式
spring.activemq.toTopic = true
spring.pool.enabled = true
spring.pool.max-connections = 10
spring.pool.idle-timeout = 30000
#默認情況下activemq提供的是queue模式,若要使用topic模式需要配置下面配置
spring.jms.pub-sub-domain = true
# 是否信任所有包
#spring.activemq.packages.trust-all=
# 要信任的特定包的逗號分隔列表(當不信任所有包時)
#spring.activemq.packages.trusted=
# 當連接請求和池滿時是否阻塞。設置false會拋“JMSException異常”。
#spring.activemq.pool.block-if-full=true
# 如果池仍然滿,則在拋出異常前阻塞時間。
#spring.activemq.pool.block-if-full-timeout=-1ms
# 是否在啟動時創建連接。可以在啟動時用於加熱池。
#spring.activemq.pool.create-connection-on-startup=true
# 是否用Pooledconnectionfactory代替普通的ConnectionFactory。
#spring.activemq.pool.enabled=false
# 連接過期超時。
#spring.activemq.pool.expiry-timeout=0ms
# 連接空閑超時
#spring.activemq.pool.idle-timeout=30s
# 連接池最大連接數
#spring.activemq.pool.max-connections=1
# 每個連接的有效會話的最大數目。
#spring.activemq.pool.maximum-active-session-per-connection=500
# 當有"JMSException"時嘗試重新連接
#spring.activemq.pool.reconnect-on-exception=true
# 在空閑連接清除線程之間運行的時間。當為負數時,沒有空閑連接驅逐線程運行。
#spring.activemq.pool.time-between-expiration-check=-1ms
# 是否只使用一個MessageProducer
#spring.activemq.pool.use-anonymous-producers=true
--------------------------------------------------------
YCLOANS-PUBLIC:
license.licenseContext = <?xml version="1.0" encoding="UTF-8"?><license build-time="Mon May 06 11:39:46 CST 2019" validate-code="FC6107A40B8E7CF356B4EC5CC39A9CA6"><element name="license_code">0000011874</element><element name="product_code">0000001122</element><element name="product_name_zh-cn">宇信科技基於微服務框架統一開發平台</element><element name="product_name_en-us">YUSP</element><element name="version_major">1</element><element name="version_sub">0</element><element name="version_publish">1</element><element name="complie_date">2018-03-20</element><element name="license_type">內部試用許可證</element><element name="customer_name"/><element name="contract_code"/><element name="license_start_time">2019-05-06</element><element name="license_end_time">2119-06-01</element></license>
license.licenseModel = TRIAL
management.health.rabbit.enabled = false
management.health.ycloansmq.enabled = true
management.endpoints.web.base-path = /api/system/actuator
management.endpoint.health.show-details = always
management.endpoints.web.exposure.include = *
management.security.enabled = false
swagger.enabled = true
swagger.title = YUSP APP ycloans-starter Application API
swagger.description = YUSP APP ycloans-starter API documentation
swagger.version = 2.1.1.RELEASE
spring.liquibase.enabled = false
spring.liquibase.change-log = classpath:config/liquibase/master.xml
spring.cloud.inetutils.preferred-networks = 172.20.*
spring.jackson.serialization.INDENT_OUTPUT = true
spring.messages.cache-duration = 1
pagehelper.helperDialect = mysql
pagehelper.reasonable = true
mapper.mappers[0] = cn.com.yusys.yusp.commons.mapper.CommonMapper
----------------------------------------------------------------------
MYSQL:
######################################
## MYSQL數據庫配置
######################################
spring.datasource.url = jdbc:mysql://10.162.1.102:3306/apolloconfigdb?useUnicode=true&characterEncoding=utf8&useSSL=false
spring.datasource.username = apollo
spring.datasource.password = apollo
spring.datasource.hikari.minimum-idle = 20
spring.datasource.hikari.maximum-pool-size = 500
spring.datasource.hikari.data-source-properties.cachePrepStmts = true
spring.datasource.hikari.data-source-properties.prepStmtCacheSize = 250
spring.datasource.hikari.data-source-properties.prepStmtCacheSqlLimit = 2048
spring.datasource.hikari.data-source-properties.useServerPrepStmts = true
# 特別注意此處,否則存儲mysql將無效
mybatis.mapperLocations = classpath*:mapper/**/*.xml
mybatis.configuration.map-underscore-to-camel-case = true
~~~

#### **Eureka配置:**

Eureka注冊主要在本地(服務:pay/ agent/ nc*)進行配置,如下:
~~~shell
[root@mysql01 ycloans-pay-service]# pwd
/home/hxusr/ap/app/ycloans-pay-service
[root@mysql01 ycloans-pay-service]# ls
bootstrap.yml config-cache nohup.out out1130.log out.log robotcenter.sh ycloans_app.jar ycloans_app.jar.1 ycloans_app.jar4
[root@mysql01 ycloans-pay-service]# cat bootstrap.yml
spring:
application:
name: ycloans-pay-service #應用名 集群名
liquibase:
enabled: false
change-log: "classpath:config/liquibase/master.xml"
server:
port: 6002 #應用啟動端口
app:
id: ycloans-pay-service # Apollo集群名稱
apollo:
meta: http://10.162.1.76:9001
#meta: http://10.162.1.102:9081/
cluster: SIT #環境
cacheDir: ../apollo/ #apollo配置文件存放目錄
bootstrap:
enabled: true
namespaces: application,EUREKA,YCLOANS-PUBLIC,ACTIVE_MQ
# 命名空間注意:namespace 和 namespaces。
# 日志相關
logging:
path: ../logs #日志文件路徑
file: ${spring.application.name}_${server.port}.log #日志文件名稱
level:
root: INFO
springfox.documentation.spring.web.readers.operation: OFF #springfox日志關閉輸出
#actuator監控配置
management:
health:
rabbit:
enabled: false
# 停啟 腳本: robotcenter.sh
# 日志 : out.log
-------------------------------------------------------------
[root@peer1-dev ~]# cd /home/ap/app/mock/order/
[root@peer1-dev order]# ls
bootstrap.yml logs out.log robotcenter.sh ycloans_app.jar
[root@peer1-dev order]# cat bootstrap.yml
spring:
application:
name: ycloans-common-reliable-message-mock-order #應用名稱
liquibase:
enabled: false
change-log: "classpath:config/liquibase/master.xml"
server:
port: 18814 #應用啟動端口
test:
apollo:
env: SIT
log:
level: INFO
app:
id: ycloans-common-reliable-message
apollo:
#meta: http://10.200.10.13:9001 # 湖北消金的配置
#meta: http://10.162.1.102:9081 # 北銀消金的配置
meta: http://10.162.1.76:9001
cluster: ${test.apollo.env} #集群名稱
cacheDir: ../apollo/ #apollo配置文件存放目錄
bootstrap:
enabled: true
namespaces: application,YCLOANS-PUBLIC,EUREKA,UNDERTOW,LOAD_BALANCE,LEVEL_CACHE,MYSQL,ACTIVE_MQ
# 日志相關
logging:
path: ./logs #日志文件路徑
file: ${spring.application.name}_${server.port}.log #日志文件名稱
level:
root: ${test.log.level}
springfox.documentation.spring.web.readers.operation: OFF #springfox日志關閉輸出
#actuator監控配置
management:
health:
rabbit:
enabled: false
~~~
### 2. 避坑指南
統一開發平台的配置會有影響,導致啟動報錯,原因未知,如果不用請刪除

***
# Eureka安裝
### 安裝包位置:
G:\宇信\北銀核算\項目文檔\北銀核算\包
eureka.zip
兩台服務器互相注冊:
### 配置hosts文件:
~~~shell
## 兩台都要配:
[root@hexin2 eureka]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
10.162.1.100 peer2-dev
10.162.1.76 peer1-dev
~~~
### 配置76:
~~~shell
## 上傳解壓:
[root@peer1-dev ~]# cd eureka
eureka/ eureka.zip
[root@peer1-dev ~]# cd eureka
[root@peer1-dev eureka]# ls
application.yml ncloan-registry-server-eureka.log startup-peer4-dev.sh
ncloan-registry-server-eureka.jar startup-peer1-dev.sh
~~~
##### 配置application.yml:
~~~shell
[root@peer1-dev eureka]# cat application.yml
eureka:
client:
#是否要注冊到其他Eureka Server實例
register-with-eureka: true
#是否要從其他Eureka Server實例獲取數據
fetch-registry: true
service-url:
defaultZone: http://peer1-dev:8761/eureka/,http://peer2-dev:8762/eureka/
instance:
prefer-ip-address: true #將自己的ip地址注冊到Eureka服務中
#服務過期時間配置,默認90s
lease-expiration-duration-in-seconds: 30
#租期更新時間間隔
lease-renewal-interval-in-seconds: 10
server:
#啟用主動失效,並且每次主動失效檢測間隔為3s
eviction-interval-timer-in-ms: 3000
# 關閉自我保護機制,保證不可用服務及時踢出
enable-self-preservation: false
spring:
application:
name: servers-eureka
logging:
level:
com.netflix.eureka: OFF
com.netflix.discovery: OFF
---
spring:
#指定profile=peer1_dev
profiles: peer1-dev
server:
port: 8761
eureka:
instance:
#指定當profile=peer1_dev時,主機名是peer1_dev
hostname: peer1-dev
---
spring:
#指定profile=peer2
profiles: peer2-dev
server:
port: 8762
eureka:
instance:
#指定當profile=peer2_dev時,主機名是peer2_dev
hostname: peer2-dev
~~~
##### 啟動腳本:startup-peer1-dev.sh
~~~shell
[root@peer1-dev eureka]# vim startup-peer1-dev.sh
注意必須:jdk1.8
#!/bin/bash
nohup /usr/local/java1.8/bin/java -jar -Dfile.encoding=UTF-8 -Dapollo.bootstrap.enabled=false ncloan-registry-server-eureka.jar --spring.profiles.active=peer1-dev --spring.config.location=application.yml > ncloan-registry-server-eureka.log 2>& 1 &
~~~
### 配置100:
~~~shell
上傳解壓:
[root@hexin2 ~]# cd eureka
eureka/ eureka.zip
[root@hexin2 ~]# cd eureka
[root@hexin2 eureka]# ll
application.yml ncloan-registry-server-eureka.log startup-peer4-dev.sh
ncloan-registry-server-eureka.jar startup-peer2-dev.sh
~~~
##### 配置application.yml:
~~~shell
[root@hexin2 eureka]# cat application.yml
eureka:
client:
#是否要注冊到其他Eureka Server實例
register-with-eureka: true
#是否要從其他Eureka Server實例獲取數據
fetch-registry: true
service-url:
defaultZone: http://peer2-dev:8762/eureka/,http://peer1-dev:8761/eureka/
instance:
prefer-ip-address: true #將自己的ip地址注冊到Eureka服務中
#服務過期時間配置,默認90s
lease-expiration-duration-in-seconds: 30
#租期更新時間間隔
lease-renewal-interval-in-seconds: 10
server:
#啟用主動失效,並且每次主動失效檢測間隔為3s
eviction-interval-timer-in-ms: 3000
# 關閉自我保護機制,保證不可用服務及時踢出
enable-self-preservation: false
spring:
application:
name: servers-eureka
logging:
level:
com.netflix.eureka: OFF
com.netflix.discovery: OFF
---
spring:
#指定profile=peer1_dev
profiles: peer1-dev
server:
port: 8761
eureka:
instance:
#指定當profile=peer1_dev時,主機名是peer1_dev
hostname: peer1-dev
---
spring:
#指定profile=peer2
profiles: peer2-dev
server:
port: 8762
eureka:
instance:
#指定當profile=peer2_dev時,主機名是peer2_dev
hostname: peer2-dev
~~~
##### 配置啟動腳本:startup-peer2-dev.sh
~~~shell
[root@needyou eureka]# cat startup-peer2-dev.sh
注意必須:jdk1.8
#!/bin/bash
nohup java -jar -Dfile.encoding=UTF-8 -Dapollo.bootstrap.enabled=false ncloan-registry-server-eureka.jar --spring.profiles.active=peer2-dev --spring.config.location=application.yml > ncloan-registry-server-eureka.log 2>& 1 &
~~~
***
# 時間同步:
ntpdate time1.aliyun.com 需要外網環境!
ntpdate 10.162.2.100 搭建內網時間服務器
10.162.2.100是唯一能連外網的服務器。作為內網的時間服務器。
主節點(時間服務器)10.162.2.100
~~~shell
# 查看是否安裝 ntp 服務
[root@waiwang ~]# rpm -qa ntp
ntp-4.2.2p1-15.el5
# 如果有、查看服務配置文件
[root@waiwang ~]# rpm -qc ntp
/etc/ntp.conf
/etc/ntp/keys
/etc/ntp/step-tickers
/etc/rc.d/init.d/ntpd
/etc/sysconfig/ntpd
# 沒有則安裝:
[root@waiwang ~]# yum -y install ntp
# 配置
[root@waiwang ~]# more /etc/ntp.conf
# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
# Permit all access over the loopback interface. This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict 127.0.0.1
restrict -6 ::1
# Hosts on local network are less restricted.
restrict 10.162.2.100 mask 255.255.0.0 nomodify notrap
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server 0.rhel.pool.ntp.org
server 1.rhel.pool.ntp.org
server 2.rhel.pool.ntp.org
#broadcast 192.168.1.255 key 42 # broadcast server
#broadcastclient # broadcast client
#broadcast 224.0.1.1 key 42 # multicast server
#multicastclient 224.0.1.1 # multicast client
#manycastserver 239.255.254.254 # manycast server
#manycastclient 239.255.254.254 key 42 # manycast client
# Undisciplined Local Clock. This is a fake driver intended for backup
# and when no outside source of synchronized time is available.
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 10
# Drift file. Put this in a directory which the daemon can write to.
# No symbolic links allowed, either, since the daemon updates the file
# by creating a temporary in the same directory and then rename()'ing
# it to the file.
driftfile /var/lib/ntp/drift
# Key file containing the keys and key identifiers used when operating
# with symmetric key cryptography.
keys /etc/ntp/keys
# Specify the key identifiers which are trusted.
#trustedkey 4 8 42
# Specify the key identifier to use with the ntpdc utility.
#requestkey 8
# Specify the key identifier to use with the ntpq utility.
#controlkey 8
~~~
客戶端:
~~~shell
[root@hx245 ~]# yum -y install ntpdate
[root@hx245 ~]# ntpdate 10.162.2.100
2 Dec 17:52:30 ntpdate[38066]: step time server 10.162.2.100 offset -26113.326900 sec
[root@hx245 ~]# date
Wed Dec 2 17:52:33 CST 2020
~~~