AG-Admin微服务框架入门

AG-Admin微服务框架入门

 @qq群:一群: 837736451  二群 169824183

一 概要介绍

AG-Admin后台地址:https://gitee.com/minull/ace-security

AG-Admin前端地址:https://gitee.com/minull/AG-Admin-v2.0

要想玩儿转spring cloud必须进行一大波儿的学习哦,先有个心理准备。

AG-Admin基于Spring Cloud微服务化开发平台,具有统一授权、认证微服务云框架。其中包含了服务注册与发现、用户管理、资源权限管理、网关API管理等多个模块,支持多业务系统并行开发,是一个完整的微服务脚手架开发框架。

AG-Admin采用前后端分离架构,前端基于vue-admin-element框架,项目地址:https://github.com/PanJiaChen/vue-element-admin

二 基础安装

1 下载安装git

对git必要的熟练使用,因为现有的开源项目都是在git开源中国或者github上。你应具有熟练的项目拉取,提交代码能力。说了那么多来一个简单的教程:https://backlog.com/git-tutorial/cn/

2 下载安装idea

请使用IDEA集成工具开发Spring应用,什么eclipse,myeclipse还是别了,来一个IDEA安装教程

https://blog.csdn.net/yangying496875002/article/details/73603303

3 下载安装Maven,

安装教程

https://www.cnblogs.com/yyiou/archive/2017/08/22/7411409.html

想进一步了解Maven:

https://www.cnblogs.com/rjjs/p/9339632.html

4 下载安装nodejs

你应对前端框架Vue有所了解,或者对前端三大框架react,angular,vue任意一个框架有所了解,或者最低要求能够对nodejs有所了解。因为AG-Admin前端是基于vue的vue-admin-element一个 开源项目。来一个nodejs的入门教程:

https://www.cnblogs.com/zhouyu2017/p/6485265.html

5 下载并配置nginx

首先去Nginx官网下载一个最新版本的Nginx,下载地址:http://nginx.org/en/download.html。我这里下载的版本是:nginx/Windows-1.11.6。下载完成之后,得到一个.zip的压缩包,把压缩包解压到D盘根目录。

1) 修改配置文件。打开“conf”文件夹下的“nginx.conf”文件,使用如下配置全部覆盖

#user  nobody;

worker_processes  1;

#error_log  logs/error.log;

#error_log  logs/error.log  notice;

#error_log  logs/error.log  info;

#pid        logs/nginx.pid;

events {

worker_connections  1024;

}

http {

include       mime.types;

default_type  application/octet-stream;

#log_format  main  ‘$remote_addr - $remote_user [$time_local] "$request" ‘

#                  ‘$status $body_bytes_sent "$http_referer" ‘

#                  ‘"$http_user_agent" "$http_x_forwarded_for"‘;

#access_log  logs/access.log  main;

sendfile        on;

#tcp_nopush     on;

#keepalive_timeout  0;

keepalive_timeout  65;#长连接超时时间,单位秒

#gzip  on;#启用Gzip压缩

server{

listen       8104;#监听8020端口,可以改成其他端口

server_name  localhost;#当前服务的域名

#charset koi8-r;

#access_log  logs/host.access.log  main;

location / {

if ($request_method = ‘OPTIONS‘) {

add_header ‘Access-Control-Allow-Origin‘ ‘http://localhost:9527‘;

add_header ‘Access-Control-Allow-Methods‘ ‘GET, POST, OPTIONS‘;

add_header ‘Access-Control-Allow-Credentials‘ ‘true‘;

#

# Custom headers and headers various browsers *should* be OK with but aren‘t

#

add_header ‘Access-Control-Allow-Headers‘ ‘DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization‘;

#

# Tell client that this pre-flight info is valid for 20 days

#

return 204;

}

proxy_pass http://localhost:8765;

proxy_redirect default;

proxy_set_header   Host             $host;

proxy_set_header   X-Real-IP        $remote_addr;

proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;

proxy_cookie_path /nginx/ /;

proxy_set_header Cookie $http_cookie;

proxy_cookie_domain domino.server localhost;

include  uwsgi_params;

add_header ‘Access-Control-Allow-Origin‘ ‘http://localhost:9527‘;

add_header ‘Access-Control-Allow-Credentials‘ ‘true‘;

add_header ‘Access-Control-Allow-Methods‘ ‘GET, POST, OPTIONS‘;

add_header ‘Access-Control-Allow-Headers‘ ‘DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type‘;

}

}

}

 

 

2)打开命令行,定位到Nginx当前目录,使用“start nginx”命令启动nginx

6了解Spring boot

因为Ag-Admin是基于Spring Cloud,而Spring Cloud是基于Spring boot,因此他是基础你必须有所了解。

来一个简单的教程:

https://www.cnblogs.com/black-spike/p/8017768.html

三 启动AG-Admin

3.1 把AG-Admin弄到自己家里来

克隆到本地

3.2 AG-Admin组成结构

使用idea打开

在这里先认识一下API网关就可以了,API网关是所有服务对外暴露API接口的唯一有效入口,也就是前端访问后台都是走API网关就可以了,至于API网关具体怎么回事先不要捉急去深究。其他没有标注的暂时不用去关心,我们先入门,别急。

3.3 安装Rabbit MQ

1)由于Rabbit MQ是基于erlang因此先把erlang装上,下载地址

http://www.erlang.org/downloads

安装完成之后创建一个名为ERLANG_HOME的环境变量,其值指向erlang的安装目录,同时将%ERLANG_HOME%\bin加入到Path中

进入cmd输入:erl出现下图说明安装配置ok,如果不行请检查上行步骤

下载安装Rabbit MQ,地址:http://www.rabbitmq.com/download.html

默认安装的RabbitMQ 监听端口是5672,默认用户名:guest,密码:guest。

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进行验证

3.4 安装redies

地址:https://github.com/MSOpenTech/redis/releases

启动resies-server

3.5 数据库

分别执行ace-admin/db/init.sql、ace-auth-server/db/init.sql 这两个脚本,执行成功之后,会创建ag_admin_v1和ag_auth_v1两个数据库以及以下一些表:

配置hosts文件

进入:C:\Windows\System32\drivers\etc

将hosts拷贝到桌面然后使用记事本打开,加入以下2句,保存将后将桌面上的hosts文件复制,到原来系统路径下的hosts粘贴覆盖

127.0.0.1 ace-admin

127.0.0.1 ACE-ADMIN

3.6 修改配置

修改ace-admin/src/main/resources/application.yml、ace-auth/src/main/resources/application.yml这两个配置文件中连接数据库的一些信息:

同时注意Rabbit MQ链接配置检查一遍

修改项目里所有的defaultZone参数,他默认用的是docker,但是我们是这本地开发的,所以改成本地的

3.7 启动

1)启动ace-center,是注册发现服务他是所有服务的中心

2)启动ace-auth,是认证中心

3)启动ace-admin,他在ace-modules下面是指向ag_admin_v1数据库的基础数据服务

4)启动ace-gate,网关

5)启动前端项目,AG-Admin-v2.0

找到该目录下将base_api地址 修改为:http://localhost:8104

取消如图文件的注释保存

在cmd中进入项目目录:我的是E:\git\vue\AG-Admin-v2.0

输入:npm install --registry=https://registry.npm.taobao.org

如果已经安装了cnpm,则直接输入cnpm install

等待安装完成后输入npm run dev即可在浏览器打开:localhost:9527

如果是非H5浏览器请下载使用chrome浏览器然后把地址粘贴过来

使用postman登录

四 常见问题FAQ

4.1 ace-auth,或者ace-admin启动过程中控制台有异常输出,控制台输出非mysql连接错误。或者一些类找不到

这个应该是spring cloud版本问题,请将自己maven本地仓库下所有文件删除,C:\Users\Administrator\.m2

然后在ag-admin下面找到pom.xml随便修改一下内容,然后等到ideam提示导入修改,然后再次撤销刚才的修改,再次应用修改,这样做的目的是为了让maven再次下载spring cloud全部依赖,这个过程可能需要等待个10多分钟,等再次下载完成然后按照启动顺序启动。

4.2 提示数据库datasource异常

请检查各自项目下的application.yml文件中的mysql配置是否正确

4.3 提示mq连接异常

请检查application.yml文件中mq配置是否正确,可以通过http://localhost:15672/,guest,guest查看mq能否可以用

4.4 提示redies连接异常

请检查application.yml文件中redies配置是否正确,或者redies是否启动

4.5 登录过程中提示ace-admin相关连接超时

首先应检查ace-admin启动过程中控制台有无异常输出,如果异常输出请检查是否属于上面的问题,如果不是可以尝试修改application.yml里面的超时设置单位为微秒

4.6 ace-gate 部署后运行报找不到main类异常

这个是因为ace-gate的maven配置没有加入spring boot的缘故因此在pom.xml加入一下配置重新编译 部署。

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
    <kotlin.version>1.1.51</kotlin.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
       
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-webflux</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-gateway</artifactId>
    </dependency>
    <dependency>
        <groupId>org.isomorphism</groupId>
        <artifactId>token-bucket</artifactId>
        <version>1.7</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>io.projectreactor</groupId>
        <artifactId>reactor-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.assertj</groupId>
        <artifactId>assertj-core</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.jetbrains.kotlin</groupId>
        <artifactId>kotlin-stdlib</artifactId>
        <version>${kotlin.version}</version>
        <optional>true</optional>
    </dependency>
    <dependency>
        <groupId>org.jetbrains.kotlin</groupId>
        <artifactId>kotlin-reflect</artifactId>
        <version>${kotlin.version}</version>
        <optional>true</optional>
    </dependency>

<dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-openfeign</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
    </dependency>

<dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-sleuth-zipkin</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.amqp</groupId>
        <artifactId>spring-rabbit</artifactId>
    </dependency>

<dependency>
        <groupId>com.github.wxiaoqi</groupId>
        <artifactId>ace-interface</artifactId>
        <version>2.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>com.github.wxiaoqi</groupId>
        <artifactId>ace-auth-client</artifactId>
        <version>2.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>com.github.wxiaoqi</groupId>
        <artifactId>ace-common</artifactId>
        <version>2.0-SNAPSHOT</version>
    </dependency>
    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>fastjson</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>5.0.4.RELEASE</version>
    </dependency>
</dependencies>
<build>
    <finalName>ace-gate</finalName>
    <plugins>
        <!-- 此插件用来生成通用mapper的代码 -->
        <plugin>
            <groupId>org.mybatis.generator</groupId>
            <artifactId>mybatis-generator-maven-plugin</artifactId>
            <version>1.3.2</version>
            <configuration>
                <configurationFile>${basedir}/src/main/resources/builder/generatorConfig.xml</configurationFile>
                <overwrite>true</overwrite>
                <verbose>true</verbose>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>mysql</groupId>
                    <artifactId>mysql-connector-java</artifactId>
                    <version>5.1.30</version>
                    <scope>runtime</scope>
                </dependency>
                <dependency>
                    <groupId>tk.mybatis</groupId>
                    <artifactId>mapper</artifactId>
                    <version>${mapper.version}</version>
                </dependency>
            </dependencies>
        </plugin>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.8</source>
                <target>1.8</target>
            </configuration>
        </plugin>
    </plugins>
</build>

五 更多交流

 @qq群:一群: 837736451  二群 169824183

 

原文地址:https://www.cnblogs.com/rjjs/p/9390062.html

时间: 2024-07-30 03:51:07

AG-Admin微服务框架入门的相关文章

微服务框架学习收录链接(包括服务搭建中用到mybatis-plus等)

1.基于Spring Boot和Spring Cloud实现微服务架构学习(一)-Spring框架介绍 https://blog.csdn.net/zeb_perfect/article/details/51945350 2.Spring Cloud生态圈简介 https://blog.csdn.net/rickiyeat/article/details/59172258 3.标题:Spring Boot 快速搭建微服务框架详细教程 http://www.jb51.net/article/123

【干货】手动搭建一套可自动化构建的微服务框架

如何阅读 本文篇幅较长,我花了两天的时间完成,大约需要半小时阅读. 本文分为理论篇和实践篇,由于代码在手机端展示并不理想,建议大家收藏之后在PC端阅读.实践篇边动手边阅读更有助于理解. 在阅读的同时,也麻烦各位大佬多多分享! 本文你将学到什么? 本文将以原理+实战的方式,首先对"微服务"相关的概念进行知识点扫盲,然后开始手把手教你搭建这一整套的微服务系统. 这套微服务框架能干啥? 这套系统搭建完之后,那可就厉害了: 微服务架构你的整个应用程序将会被拆分成一个个功能独立的子系统,独立运行

go微服务框架go-micro深度学习-目录

go微服务框架go-micro深度学习(一) 整体架构介绍 go微服务框架go-micro深度学习(二) 入门例子 go微服务框架go-micro深度学习(三) Registry服务的注册和发现 go微服务框架go-micro深度学习(四) rpc方法调用过程详解 go微服务框架go-micro深度学习(五) stream 调用过程详解 代码在github上 原文地址:https://www.cnblogs.com/li-peng/p/10522084.html

基于spring-boot的rest微服务框架

周末在家研究spring-boot,参考github上的一些开源项目,整了一个rest微服务框架,取之于民,用之于民,在github上开源了,地址如下: https://github.com/yjmyzz/spring-boot-rest-framework 主要特性如下: ----------------- 数据访问 dao采用mybatis 3.3.0 + tk.mybatis通用Mapper3.1.3 , 支持事务回滚 数据库初始化脚本 见src/mybatis-generator/ddl

【GoLang】go 微服务框架 &amp;&amp; Web框架学习资料

参考资料: 通过beego快速创建一个Restful风格API项目及API文档自动化:  http://www.cnblogs.com/huligong1234/p/4707282.html Go 语言构建 RESTful Web 服务:  https://www.oschina.net/translate/hardcore-google-communicating-go Golang中使用 JWT认证来 保障Restful JSON API的安全(英文):   http://www.tuico

微服务框架Lagom介绍之一

背景 Lagom是JAVA系下响应式 微服务框架,在阅读本文之前请先阅读微服务架构设计,Lagom与其他微服务框架相比,与众不同的特性包括: 目前,大多数已有的微服务框架关注于简化单个微服务的构建--这是比较容易的一部分内容.Lagom将其扩展到了微服务所构成的系统,这是大型的系统--也是较为困难的一部分内容,因为在这里我们会面临到分布式系统的复杂性. 通信默认是异步的--基于消息和流--但是,如果需要的话,也考虑到了使用其他的方案,如同步的REST. 持久化默认是基于事件的--使用事件溯源Ev

(转)微服务框架落地实践之路

http://www.primeton.com/read.php?id=2276&his=1 一.微服务架构产生的背景 近十年中,互联网给我们生活带来了翻天覆地的变化,消费者的生活方式日益数字化,人们可以在任何时间.任何地点利用网络进行购物体验,运用社交媒体进行自我表达,企业也在运用多种技术手段,发挥数字化潜力,改善客户联系,促进企业业务模式的转型.在这种背景下,互联网也好,传统企业也罢,都面临一个共同的需求:面对快速变化的需求,面对业务模式的升级,如何构建出灵活的,可扩展,可重用的系统? 前几

基于.NET CORE微服务框架 -浅析如何使用surging

1.前言 surging受到大家这么强烈的关注,我感到非常意外,比如有同僚在公司的分享会上分享surging, 还有在博客拿其它的RPC框架,微服务做对比等等,这些举动都让我感觉压力很大,毕竟作为个人的开源项目,无法与成熟的开源社区的项目相比,也只有等到后面有许许多多志同道合的朋友加入一起研发完善surging,这样才能让surging 成为流行的微服务框架. 这篇文章介绍如何使用surging 开源地址:https://github.com/dotnetcore/surging 2.设计模式

.net 微服务框架

接触微服务框架已经很久了,很久之前就想写一个基于.net framework的微服务框架,奈何一直忙(LAN),最近终于抽出时间,实现了微服务通讯的主要功能,包括服务注册中心,微服务服务端以及微服务客户端.下面将逐一模块进行介绍SOA框架使用方式, 1 客户端主要类 1.1 ServicePool(服务池) 1.1.1 设置服务中心地址(SetServiceCenterInfo) 用于设置服务中心地址,设置服务中心地址后,可以自动收到服务中心推送的服务列表.而不需客户端一一订阅,并且当微服务集群