CentOS7-部署测试Apollo
linux部署apollo环境要求:jdk1.8、mysql5.7
centos7安装jdk1.8跟mysql5.7可以参考我这两篇文章
https://www.cnblogs.com/reasonzzy/p/11149530.html
https://www.cnblogs.com/reasonzzy/p/11150131.html
从github上将源码down下来
https://github.com/ctripcorp/apollo.git
这两个是打包脚本,都可以执行,sh脚本可以用git bash面板执行,
执行前可以修改eureka注册ip跟数据库账号密码参数,如果是本地,
可不做修改,打包方式有两种,一种是quick start方式,另一种是打成三个压缩包形式
quick start方式参考如下文档:
https://github.com/ctripcorp/apollo/wiki/Quick-Start
源码地址:
https://github.com/nobodyiam/apollo-build-scripts.git
主要步骤
修改apollo-configservice, apollo-adminservice和apollo-portal的pom.xml,注释掉spring-boot-maven-plugin和maven-assembly-plugin
在根目录下执行mvn clean package -pl apollo-assembly -am -DskipTests=true
复制apollo-assembly/target下的jar包,rename为apollo-all-in-one.jar
第二种方式压缩包github上面也有现成的,如果不需要调整源码,直接从github上下载
https://github.com/ctripcorp/apollo/releases
数据库脚本在source code.zip这个压缩包里面,源代码scripts/db/migration文件夹里面的sql文件也可以
压缩包下载好之后,只需要修改下配置文件即可
#!/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= # apollo portal db info
apollo_portal_db_url=jdbc:mysql://localhost:3306/ApolloPortalDB?characterEncoding=utf8
apollo_portal_db_username=root
apollo_portal_db_password= # =============== Please do not modify the following content =============== # if [ "$(uname)" == "Darwin" ]; then
windows=""
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
windows=""
elif [ "$(expr substr $(uname -s) 1 5)" == "MINGW" ]; then
windows=""
else
windows=""
fi # meta server url
config_server_url=http://localhost:8080
admin_server_url=http://localhost:8090
eureka_service_url=$config_server_url/eureka/
portal_url=http://localhost:8070 # JAVA OPTS
BASE_JAVA_OPTS="-Denv=dev"
CLIENT_JAVA_OPTS="$BASE_JAVA_OPTS -Dapollo.meta=$config_server_url"
SERVER_JAVA_OPTS="$BASE_JAVA_OPTS -Dspring.profiles.active=github -Deureka.service.url=$eureka_service_url"
PORTAL_JAVA_OPTS="$BASE_JAVA_OPTS -Ddev_meta=$config_server_url -Dspring.profiles.active=github,auth -Deureka.client.enabled=false -Dhibernate.query.plan_cache_max_size=192" # executable
JAR_FILE=apollo-all-in-one.jar
SERVICE_DIR=./service
SERVICE_JAR_NAME=apollo-service.jar
SERVICE_JAR=$SERVICE_DIR/$SERVICE_JAR_NAME
SERVICE_LOG=$SERVICE_DIR/apollo-service.log
PORTAL_DIR=./portal
PORTAL_JAR_NAME=apollo-portal.jar
PORTAL_JAR=$PORTAL_DIR/$PORTAL_JAR_NAME
PORTAL_LOG=$PORTAL_DIR/apollo-portal.log
CLIENT_DIR=./client
CLIENT_JAR=$CLIENT_DIR/apollo-demo.jar # go to script directory
cd "${0%/*}" function checkJava {
if [[ -n "$JAVA_HOME" ]] && [[ -x "$JAVA_HOME/bin/java" ]]; then
if [ "$windows" == "" ]; then
tmp_java_home=`cygpath -sw "$JAVA_HOME"`
export JAVA_HOME=`cygpath -u $tmp_java_home`
echo "Windows new JAVA_HOME is: $JAVA_HOME"
fi
_java="$JAVA_HOME/bin/java"
elif type -p java > /dev/null; then
_java=java
else
echo "Could not find java executable, please check PATH and JAVA_HOME variables."
exit
fi if [[ "$_java" ]]; then
version=$("$_java" -version >& | awk -F '"' '/version/ {print $2}')
if [[ "$version" < "1.8" ]]; then
echo "Java version is $version, please make sure java 1.8+ is in the path"
exit
fi
fi
} function checkServerAlive {
declare -i counter=
declare -i max_counter= # *=120s
declare -i total_time= SERVER_URL="$1" until [[ (( counter -ge max_counter )) || "$(curl -X GET --silent --connect-timeout 1 --max-time 2 --head $SERVER_URL | grep "HTTP")" != "" ]];
do
printf "."
counter+=
sleep
done total_time=counter* if [[ (( counter -ge max_counter )) ]];
then
return $total_time
fi return
} checkJava if [ "$1" = "start" ] ; then
echo "==== starting service ===="
echo "Service logging file is $SERVICE_LOG"
export JAVA_OPTS="$SERVER_JAVA_OPTS -Dlogging.file=./apollo-service.log -Dspring.datasource.url=$apollo_config_db_url -Dspring.datasource.username=$apollo_config_db_username -Dspring.datasource.password=$apollo_config_db_password" if [[ -f $SERVICE_JAR ]]; then
rm -rf $SERVICE_JAR
fi ln $JAR_FILE $SERVICE_JAR
chmod a+x $SERVICE_JAR $SERVICE_JAR start --configservice --adminservice rc=$?
if [[ $rc != ]];
then
echo "Failed to start service, return code: $rc. Please check $SERVICE_LOG for more information."
exit $rc;
fi printf "Waiting for config service startup"
checkServerAlive $config_server_url rc=$?
if [[ $rc != ]];
then
printf "\nConfig service failed to start in $rc seconds! Please check $SERVICE_LOG for more information.\n"
exit ;
fi printf "\nConfig service started. You may visit $config_server_url for service status now!\n" printf "Waiting for admin service startup"
checkServerAlive $admin_server_url rc=$?
if [[ $rc != ]];
then
printf "\nAdmin service failed to start in $rc seconds! Please check $SERVICE_LOG for more information.\n"
exit ;
fi printf "\nAdmin service started\n" echo "==== starting portal ===="
echo "Portal logging file is $PORTAL_LOG"
export JAVA_OPTS="$PORTAL_JAVA_OPTS -Dlogging.file=./apollo-portal.log -Dserver.port=8070 -Dspring.datasource.url=$apollo_portal_db_url -Dspring.datasource.username=$apollo_portal_db_username -Dspring.datasource.password=$apollo_portal_db_password" if [[ -f $PORTAL_JAR ]]; then
rm -rf $PORTAL_JAR
fi ln $JAR_FILE $PORTAL_JAR
chmod a+x $PORTAL_JAR $PORTAL_JAR start --portal rc=$?
if [[ $rc != ]];
then
echo "Failed to start portal, return code: $rc. Please check $PORTAL_LOG for more information."
exit $rc;
fi printf "Waiting for portal startup"
checkServerAlive $portal_url rc=$?
if [[ $rc != ]];
then
printf "\nPortal failed to start in $rc seconds! Please check $PORTAL_LOG for more information.\n"
exit ;
fi printf "\nPortal started. You can visit $portal_url now!\n" exit ;
elif [ "$1" = "client" ] ; then
if [ "$windows" == "" ]; then
java -classpath "$CLIENT_DIR;$CLIENT_JAR" $CLIENT_JAVA_OPTS com.ctrip.framework.apollo.demo.api.SimpleApolloConfigDemo
else
java -classpath $CLIENT_DIR:$CLIENT_JAR $CLIENT_JAVA_OPTS com.ctrip.framework.apollo.demo.api.SimpleApolloConfigDemo
fi elif [ "$1" = "stop" ] ; then
echo "==== stopping portal ===="
cd $PORTAL_DIR
./$PORTAL_JAR_NAME stop cd .. echo "==== stopping service ===="
cd $SERVICE_DIR
./$SERVICE_JAR_NAME stop else
echo "Usage: demo.sh ( commands ... )"
echo "commands:"
echo " start start services and portal"
echo " client start client demo program"
echo " stop stop services and portal"
exit
fi
quick start方式修改下demo.sh这个文件,将localhost改成对应的ip,还有数据库账号密码。
第二种方式,如果是部署在linux系统上,有且只有一个网卡的情况,只需要修改下数据库配置文件,
如果是用的virtualbox安装的centos7系统,并且有两个网卡的情况,类似于云主机,同样适用我下面
这种方法,详情请参考官方文档分布式部署指南:
1.4节网络策略
在启动脚本里面强制指定eureka注册的ip
-Deureka.instance.ip-address=${指定的IP}
官方文档写是写得很详细,但是对于我这种小白来说,一脸懵逼,
我当时看到这里,一脸黑人问号,这行代码加在哪,后来群里各种
寻求帮助,终于有大神告诉我了,详细操作看代码,
修改apollo-adminservice或apollo-configservice的startup.sh
#!/bin/bash
SERVICE_NAME=apollo-configservice
## Adjust log dir if necessary
LOG_DIR=/opt/logs/
## Adjust server port if necessary
#SERVER_PORT=
SERVER_PORT=${SERVER_PORT:=} ## Create log directory if not existed because JDK + won't do that
mkdir -p $LOG_DIR ## Adjust memory settings if necessary
#export JAVA_OPTS="-Xms6144m -Xmx6144m -Xss256k -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=384m -XX:NewSize=4096m -XX:MaxNewSize=4096m -XX:SurvivorRatio=8" ## Only uncomment the following when you are using server jvm
#export JAVA_OPTS="$JAVA_OPTS -server -XX:-ReduceInitialCardMarks" ########### The following is the same for configservice, adminservice, portal ###########
export JAVA_OPTS="$JAVA_OPTS -XX:ParallelGCThreads=4 -XX:MaxTenuringThreshold=9 -XX:+DisableExplicitGC -XX:+ScavengeBeforeFullGC -XX:SoftRefLRUPolicyMSPerMB=0 -XX:+ExplicitGCInvokesConcurrent -XX:+HeapDumpOnOutOfMemoryError -XX:-OmitStackTraceInFastThrow -Duser.timezone=Asia/Shanghai -Dclient.encoding.override=UTF-8 -Dfile.encoding=UTF-8 -Djava.security.egd=file:/dev/./urandom -Deureka.instance.ip-address=${指定的IP}"
# DataSource URL USERNAME PASSWORD
if [ "$DS_URL"x != x ]
then
export JAVA_OPTS="$JAVA_OPTS -Dspring.datasource.url=$DS_URL -Dspring.datasource.username=$DS_USERNAME -Dspring.datasource.password=$DS_PASSWORD"
fi
export JAVA_OPTS="$JAVA_OPTS -Dserver.port=$SERVER_PORT -Dlogging.file=$LOG_DIR/$SERVICE_NAME.log -XX:HeapDumpPath=$LOG_DIR/HeapDumpOnOutOfMemoryError/" PATH_TO_JAR=$SERVICE_NAME".jar"
SERVER_URL="http://localhost:$SERVER_PORT" function checkPidAlive {
for i in `ls -t $SERVICE_NAME*.pid >/dev/null`
do
read pid < $i result=$(ps -p "$pid")
if [ "$?" -eq ]; then
return
else
printf "\npid - $pid just quit unexpectedly, please check logs under $LOG_DIR and /tmp for more information!\n"
exit ;
fi
done printf "\nNo pid file found, startup may failed. Please check logs under $LOG_DIR and /tmp for more information!\n"
exit ;
} if [ "$(uname)" == "Darwin" ]; then
windows=""
elif [ "$(expr substr $(uname -s) 1 5)" == "Linux" ]; then
windows=""
elif [ "$(expr substr $(uname -s) 1 5)" == "MINGW" ]; then
windows=""
else
windows=""
fi # for Windows
if [ "$windows" == "" ] && [[ -n "$JAVA_HOME" ]] && [[ -x "$JAVA_HOME/bin/java" ]]; then
tmp_java_home=`cygpath -sw "$JAVA_HOME"`
export JAVA_HOME=`cygpath -u $tmp_java_home`
echo "Windows new JAVA_HOME is: $JAVA_HOME"
fi # Find Java
if [[ -n "$JAVA_HOME" ]] && [[ -x "$JAVA_HOME/bin/java" ]]; then
javaexe="$JAVA_HOME/bin/java"
elif type -p java > /dev/null >&; then
javaexe=$(type -p java)
elif [[ -x "/usr/bin/java" ]]; then
javaexe="/usr/bin/java"
else
echo "Unable to find Java"
exit
fi if [[ "$javaexe" ]]; then
version=$("$javaexe" -version >& | awk -F '"' '/version/ {print $2}')
version=$(echo "$version" | awk -F. '{printf("%03d%03d",$1,$2);}')
# now version is of format (9.3.x)
if [ $version -ge ]; then
JAVA_OPTS="$JAVA_OPTS -Xlog:gc*:$LOG_DIR/gc.log:time,level,tags -Xlog:safepoint -Xlog:gc+heap=trace"
elif [ $version -ge ]; then
JAVA_OPTS="$JAVA_OPTS -Xlog:gc*:$LOG_DIR/gc.log:time,level,tags -Xlog:safepoint -Xlog:gc+heap=trace"
elif [ $version -ge ]; then
JAVA_OPTS="$JAVA_OPTS -Xlog:gc*:$LOG_DIR/gc.log:time,level,tags -Xlog:safepoint -Xlog:gc+heap=trace"
else
JAVA_OPTS="$JAVA_OPTS -XX:+UseParNewGC"
JAVA_OPTS="$JAVA_OPTS -Xloggc:$LOG_DIR/gc.log -XX:+PrintGCDetails"
JAVA_OPTS="$JAVA_OPTS -XX:+UseConcMarkSweepGC -XX:+UseCMSCompactAtFullCollection -XX:+UseCMSInitiatingOccupancyOnly -XX:CMSInitiatingOccupancyFraction=60 -XX:+CMSClassUnloadingEnabled -XX:+CMSParallelRemarkEnabled -XX:CMSFullGCsBeforeCompaction=9 -XX:+CMSClassUnloadingEnabled -XX:+PrintGCDateStamps -XX:+PrintGCApplicationConcurrentTime -XX:+PrintHeapAtGC -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=5M"
fi
fi cd `dirname $`/.. for i in `ls $SERVICE_NAME-*.jar >/dev/null`
do
if [[ ! $i == *"-sources.jar" ]]
then
PATH_TO_JAR=$i
break
fi
done if [[ ! -f PATH_TO_JAR && -d current ]]; then
cd current
for i in `ls $SERVICE_NAME-*.jar >/dev/null`
do
if [[ ! $i == *"-sources.jar" ]]
then
PATH_TO_JAR=$i
break
fi
done
fi if [[ -f $SERVICE_NAME".jar" ]]; then
rm -rf $SERVICE_NAME".jar"
fi printf "$(date) ==== Starting ==== \n" ln $PATH_TO_JAR $SERVICE_NAME".jar"
chmod a+x $SERVICE_NAME".jar"
./$SERVICE_NAME".jar" start rc=$?; if [[ $rc != ]];
then
echo "$(date) Failed to start $SERVICE_NAME.jar, return code: $rc"
exit $rc;
fi declare -i counter=
declare -i max_counter= # *=240s
declare -i total_time= printf "Waiting for server startup"
until [[ (( counter -ge max_counter )) || "$(curl -X GET --silent --connect-timeout 1 --max-time 2 --head $SERVER_URL | grep "HTTP")" != "" ]];
do
printf "."
counter+=
sleep checkPidAlive
done total_time=counter* if [[ (( counter -ge max_counter )) ]];
then
printf "\n$(date) Server failed to start in $total_time seconds!\n"
exit ;
fi printf "\n$(date) Server started in $total_time seconds!\n" exit ;
修改apollo-portal里面的apollo-env.properties文件
dev.meta=http://{内网ip}:{端口}
修改完之后,依次执行apollo-configservice、apollo-adminservice、apollo-portal
如果报错请查看日志,日志在opt/logs/目录下
如果是本地开发做测试的话,需要引入maven依赖
<dependency>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo-client</artifactId>
<version>1.4.0</version>
</dependency>
<dependency>
<groupId>com.ctrip.framework.apollo</groupId>
<artifactId>apollo-core</artifactId>
<version>1.4.0</version>
</dependency>
创建配置文件application.properties
app.id=SimpleAapp
apollo.meta=http://192.168.56.6:8080
启动类加上@EnableApolloConfig注解
app.id对应如图的AppId
如果启动项目报错说不能注册未知的服务,拒绝连接eureka,
可以强制指定下IDEA或者Eclipse的启动参数
-Dapollo.configService=http://config-service的公网IP:端口
至此,部署算完成了,如有不懂,请详细阅读下官方文档。
CentOS7-部署测试Apollo的更多相关文章
- [原]CentOS7安装Rancher2.1并部署kubernetes (三)---解决登录kubernets超时和部署测试Pod和Containter[nginx为例]
################## Rancher v2.1.7 + Kubernetes 1.13.4 ################ ##################### ...
- centos7部署openstack-ocata
1.前言 本文旨在记录本人的一个实验过程,因为其中有一些坑,方便以后回顾查询. 其中限于篇幅(大部分是配置部分)有些内容省略掉了,官网都有,各位如果是安装部署的话可以参考官网,不建议使用本文. 以下是 ...
- centos7 部署 docker、shipyard
=============================================== 2019/4/9_第3次修改 ccb_warlock 更新说 ...
- Linux Centos7部署环境安装-CentOS
Linux Centos7部署环境安装-CentOS Centos7部署环境安装及Linux常用命令 centos系统下各文件夹的作用 centos7修改系统默认语言 centos7安装rz/sz命令 ...
- HDFS部署测试记录(2019/05)
目录 HDFS部署测试记录 0.HDFS基础知识 1.基本组成结构与文件访问过程 2.NameNode启动时如何维护元数据 3.HDFS文件上传流程 1.系统环境 1.安装大致记录: 2.磁盘分区 3 ...
- C++的性能C#的产能?! - .Net Native 系列《三》:.NET Native部署测试方案及样例
之前一文<c++的性能, c#的产能?!鱼和熊掌可以兼得,.NET NATIVE初窥> 获得很多朋友支持和鼓励,也更让我坚定做这项技术的推广者,希望能让更多的朋友了解这项技术,于是先从官方 ...
- [原]CentOS7部署osm2pgsql
转载请注明原作者(think8848)和出处(http://think8848.cnblogs.com) 部署Postgresql和部署PostGis请参考前两篇文章 本文主要参考GitHub上osm ...
- 记录使用gogs,drone搭建自动部署测试环境
使用gogs,drone,docker搭建自动部署测试环境 Gogs是一个使用go语言开发的自助git服务,支持所有平台 Docker是使用go开发的开源容器引擎 Drone是一个基于容器技术的持续集 ...
- centos7 部署ssserver
centos7 部署shadowsocks服务端 为什么要选centos7? 以后centos7 肯定是主流,在不重要的环境还是尽量使用新系统吧 centos7 的坑 默认可能会有firewall 或 ...
- 易用性测试、本地化测试、部署测试、无障碍测试、回归测试、冒烟测试、A/B测试
1.易用性定义: 易用性测试是指测试用户使用软件时是否感觉方便,是否能保证用户使用的测试类型2.本地化测试: ·定义:针对软件的本地化版本实施的针对性测试 ·测试内容: (1)语言,书写习惯 (2)时 ...
随机推荐
- python动态视频下载器
这里向大家分享一下python爬虫的一些应用,主要是用爬虫配合简单的GUI界面实现视频,音乐和小说的下载器.今天就先介绍如何实现一个动态视频下载器. 爬取电影天堂视频 首先介绍的是python爬取电影 ...
- MySQL查询——select
SELECT select的完整语法: select col1, col2,... # 业务查询的字段 from table_name # 选取的哪张表 [where single_condition ...
- javascript getElementsByClassName扩展函数
代码: function getElementsByClassName(){ if(!arguments[0]){return []};//未指定任何参数,直接返回 var args=argument ...
- html基础简介
一.html概念 1.定义:(Hyper Text Markup Language)超文本标记语言,主要是通过html标记对网页中的文本,图片,声音等内容进行描述,同时也可以在文本中包含“超级链接”, ...
- elasticsearch安装中文分词器插件smartcn
原文:http://blog.java1234.com/blog/articles/373.html elasticsearch安装中文分词器插件smartcn elasticsearch默认分词器比 ...
- CDH5.13快速体验
相对于易用性很差Apache Hadoop,其他商业版Hadoop的性能易用性都有更好的表现,如Cloudera.Hortonworks.MapR以及国产的星环,下面使用CDH(Cloudera Di ...
- 苹果电脑Mac系统如何安装Adobe Flash Player
一)安装/更新Adobe Flash Player 开系统偏好设置 , Flash player 更新,立即检查/立刻安装: Flash插件官方每月常规更新1~2次,为避免频繁过期,建议设置为允许A ...
- “GIS DICTIONARY A-Z” 查询页面开发(2)——INSERT INTO数据库
今日工作:数据库连接.数据写入 一.数据库连接:使用了pymysql库 from G2_dataClean import defList import pymysql db = pymysql.con ...
- Nginx 核心配置-根目录root指令与别名alias指令实战案例
Nginx 核心配置-根目录root指令与别名alias指令实战案例 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.试验环境说明 1>.虚拟机环境说明 [root@nod ...
- socket小程序写一个客户端,实现给服务端发送hello World字符串,将客户端发送的数据变成大写后返回
写一个客户端,实现给服务端发送hello World字符串,将客户端发送的数据变成大写后返回 本机id是192.168.xx.xy 服务端 import socket soc = socket.soc ...