一、框架简介
AG-Admin是基于Spring Cloud微服务化开发平台,具有统一授权、认证后台管理系统,其中包含具备用户管理、资源权限管理、网关API管理等多个模块,支持多业务系统并行开发,可以作为后端服务的开发脚手架。代码简洁,架构清晰,适合学习和直接项目中使用。核心技术采用Eureka、Fegin、Ribbon、Zuul、Hystrix、JWT Token、Mybatis等主要框架和中间件,前端采用vue-element-admin组件。
模块说明:
二、环境搭建
(一)、导入源码
首先下载源码到本地,这里下载的2.2版本,最新的有可能有问题。。。
然后导入到IDEA中,并更新maven依赖,由于项目中使用了lombok,所有需要安装lombok插件,否则你的IDE会报代码缺失。
项目结构如下
├─ace-security
│ │
│ ├─ace-admin----------------管理端服务层
│ │
│ ├─ace-auth-----------------鉴权中心
│ │
│ ├─ace-gate-----------------网关负载中心
│ │
│ ├─ace-center---------------服务注册中心
│ │
│ ├─ace-monitor--------------统一监控中心
│ │
│ ├─ace-config---------------统一配置中心
│ │
│ ├─ace-api------------------公共服务接口包
│ │
│ ├─ace-demo-----------------示例服务代码
│ │
│ └─ace-sidebar--------------调用第三方语言
(二)、安装Redis与rabbitmq和node
Redis安装可参考我先前的zheng环境搭建篇,node安装也很简单一直下一步下一步,就行了,安装好之后,更换成淘宝源就行了。
2.1、rabbitmq安装
Rabbit MQ 是建立在Erlang OTP平台上,所以在安装rabbitMQ之前,需要先安装Erlang ,下载地址为http://www.erlang.org/downloads
下载好之后,双击进行安装
安装完成之后创建一个名为ERLANG_HOME的环境变量,其值指向erlang的安装目录
同时将%ERLANG_HOME%\bin加入到Path中
最后打开命令行,输入erl
如果出现erlang的版本信息就表示erlang语言环境安装成功;
然后下载Rabbitmq,下载地址为:http://www.rabbitmq.com/download.html
下载好之后,双击进行安装
默认安装的RabbitMQ 监听端口是5672,默认用户名:guest,密码:guest。
2.2、RabbitMQ-Plugins插件安装
这个插件相当于是一个管理界面,方便我们在浏览器界面查看RabbitMQ各个消息队列以及exchange的工作情况,安装方法是:打开命令行cd进入rabbitmq的sbin目录(我的目录是:C:\Program Files\RabbitMQ Server\rabbitmq_server-3.7.2\sbin),输入:
rabbitmq-plugins enable rabbitmq_management
命令,稍等会会发现出现plugins安装成功的提示
然后重启服务,使用命令(此时最后以管理员运行CMD):
net stop RabbitMQ && net start RabbitMQ
插件安装完之后,在浏览器输入http://localhost:15672进行验证
(三)、初始化数据
分别导入ace-admin/db/init.sql、ace-auth-server/db/init.sql 这两个脚本,导入成功之后,会创建ag_admin和ag_auth两个数据库以及以下一些表:
表竟然没有中文注释。。。。
(四)、配置hosts文件
127.0.0.1 ace-admin
127.0.0.1 ACE-ADMIN
修改项目里所有的defaultZone参数,他默认用的是docker,但是我们是这本地开发的,所以改成本地的
(五)、修改数据库配置文件
修改ace-admin/src/main/resources/application.yml、ace-gate/src/main/resources/application.yml这两个配置文件中连接数据库的一些信息:
(六)、按顺序运行main类:CenterBootstrap(ace-center)、ConfigServerBootstrap(ace-config)、AuthBootstrap(ace-auth-server)、AdminBootstrap(ace-admin)、GateBootstrap(ace-gate)
如果报以下错误MQ超时:
Caused by: org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused: connect at org.springframework.amqp.rabbit.support.RabbitExceptionTranslator.convertRabbitAccessException(RabbitExceptionTranslator.java:62) at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:368) at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.createConnection(CachingConnectionFactory.java:565) at org.springframework.amqp.rabbit.core.RabbitTemplate.doExecute(RabbitTemplate.java:1430) at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:1411) at org.springframework.amqp.rabbit.core.RabbitTemplate.send(RabbitTemplate.java:712) at org.springframework.integration.amqp.outbound.AmqpOutboundEndpoint.send(AmqpOutboundEndpoint.java:134) at org.springframework.integration.amqp.outbound.AmqpOutboundEndpoint.handleRequestMessage(AmqpOutboundEndpoint.java:122) at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:109) at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:127) ... 55 more Caused by: java.net.ConnectException: Connection refused: connect at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method) at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85) 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.PlainSocketImpl.connect(PlainSocketImpl.java:172) at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) at java.net.Socket.connect(Socket.java:589) at com.rabbitmq.client.impl.SocketFrameHandlerFactory.create(SocketFrameHandlerFactory.java:50) at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:907) at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:859) at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:799) at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:352) ... 63 more
如果报以下错误:
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2018-01-14 17:25:15.447 ERROR [bootstrap,,,] 16896 --- [ main] o.s.boot.SpringApplication : Application startup failed
java.lang.IllegalStateException: Failed to execute CommandLineRunner
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:735)
at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:716)
at org.springframework.boot.SpringApplication.afterRefresh(SpringApplication.java:703)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:304)
at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:134)
at com.github.wxiaoqi.security.admin.AdminBootstrap.main(AdminBootstrap.java:31)
Caused by: com.netflix.hystrix.exception.HystrixRuntimeException: ServiceAuthFeign#getUserPublicKey(String,String) timed-out and no fallback available.
at com.netflix.hystrix.AbstractCommand$22.call(AbstractCommand.java:819)
at com.netflix.hystrix.AbstractCommand$22.call(AbstractCommand.java:804)
at rx.internal.operators.OperatorOnErrorResumeNextViaFunction$4.onError(OperatorOnErrorResumeNextViaFunction.java:140)
at rx.internal.operators.OnSubscribeDoOnEach$DoOnEachSubscriber.onError(OnSubscribeDoOnEach.java:87)
at rx.internal.operators.OnSubscribeDoOnEach$DoOnEachSubscriber.onError(OnSubscribeDoOnEach.java:87)
at com.netflix.hystrix.AbstractCommand$DeprecatedOnFallbackHookApplication$1.onError(AbstractCommand.java:1472)
at com.netflix.hystrix.AbstractCommand$FallbackHookApplication$1.onError(AbstractCommand.java:1397)
at rx.internal.operators.OnSubscribeDoOnEach$DoOnEachSubscriber.onError(OnSubscribeDoOnEach.java:87)
at rx.observers.Subscribers$5.onError(Subscribers.java:230)
at rx.internal.operators.OnSubscribeThrow.call(OnSubscribeThrow.java:44)
at rx.internal.operators.OnSubscribeThrow.call(OnSubscribeThrow.java:28)
at rx.Observable.unsafeSubscribe(Observable.java:10211)
at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:51)
at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:35)
at rx.Observable.unsafeSubscribe(Observable.java:10211)
at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:41)
at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:30)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
at rx.Observable.unsafeSubscribe(Observable.java:10211)
at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:41)
at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:30)
at rx.Observable.unsafeSubscribe(Observable.java:10211)
at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:41)
at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:30)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
at rx.Observable.unsafeSubscribe(Observable.java:10211)
at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:41)
at rx.internal.operators.OnSubscribeDoOnEach.call(OnSubscribeDoOnEach.java:30)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:48)
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30)
at rx.Observable.unsafeSubscribe(Observable.java:10211)
at rx.internal.operators.OperatorOnErrorResumeNextViaFunction$4.onError(OperatorOnErrorResumeNextViaFunction.java:142)
at rx.internal.operators.OnSubscribeDoOnEach$DoOnEachSubscriber.onError(OnSubscribeDoOnEach.java:87)
at rx.internal.operators.OnSubscribeDoOnEach$DoOnEachSubscriber.onError(OnSubscribeDoOnEach.java:87)
at com.netflix.hystrix.AbstractCommand$HystrixObservableTimeoutOperator$1$1.run(AbstractCommand.java:1154)
at com.netflix.hystrix.strategy.concurrency.HystrixContextRunnable$1.call(HystrixContextRunnable.java:45)
at com.netflix.hystrix.strategy.concurrency.HystrixContextRunnable$1.call(HystrixContextRunnable.java:41)
at org.springframework.cloud.sleuth.instrument.hystrix.SleuthHystrixConcurrencyStrategy$HystrixTraceCallable.call(SleuthHystrixConcurrencyStrategy.java:154)
at com.netflix.hystrix.strategy.concurrency.HystrixContextRunnable.run(HystrixContextRunnable.java:61)
at com.netflix.hystrix.AbstractCommand$HystrixObservableTimeoutOperator$1.tick(AbstractCommand.java:1159)
at com.netflix.hystrix.util.HystrixTimer$1.run(HystrixTimer.java:99)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.util.concurrent.TimeoutException: null
at com.netflix.hystrix.AbstractCommand.handleTimeoutViaFallback(AbstractCommand.java:997)
at com.netflix.hystrix.AbstractCommand.access$500(AbstractCommand.java:60)
at com.netflix.hystrix.AbstractCommand$12.call(AbstractCommand.java:610)
at com.netflix.hystrix.AbstractCommand$12.call(AbstractCommand.java:601)
at rx.internal.operators.OperatorOnErrorResumeNextViaFunction$4.onError(OperatorOnErrorResumeNextViaFunction.java:140)
... 16 common frames omitted
版本问题。。
全部启动之后
(七)、启动前端项目
首先下载UI:https://gitee.com/geek_qi/AG-Admin-v2.0 下载下来之后,解压如下
然后在该目录下执行以下命令安装依赖,用的是淘宝的源,不清楚地朋友可以百度node更换淘宝源:
cnpm install
安装成功之后,会多出一个node_modules目录
然后启动服务
# 本地开发 开启服务
npm run dev
然后点击登陆。
登陆成功之后如上。。
(八)、部署nginx配置参考
nginx配置如下:
location / {
# 指向我们打包后上传的前端文件
root /opt/nginx/dist;
index index.html;
}
location /jwt/ {
# 转发请求到后端服务网关
proxy_pass http://127.0.0.1:8765/jwt/;
}
location /api/ {
proxy_pass http://127.0.0.1:8765/api/;
}