XNginx - nginx 集群可视化管理工具

Nginx:NginxConfig可视化配置工具安装 Nginx Config 支持以下功能的可视化配置:HTTPS、HTTP/2、IPv6、certbot、HSTS、安全请求头、SSL 配置、OCSP 解析器、缓存、gzip、brotli、回退路由、反向代理、www/non-www 重定向、CDN、PHP(TCP/socket、 WordPress、Drupal、Magento、Joomla)、Node.js、Python (Django) 服务器等。注意:如果安装卡顿,确认一下是否是node版本不对。可以使用yarn来确认是否是版本问题。 阅读详情

之前团队的nginx管理,都是运维同学每次去修改配置文件,然后重启,非常不方便,一直想找一个可以方便管理nginx集群的工具,翻遍web,未寻到可用之物,于是自己设计开发了一个。

效果预览

如果想学习Java工程化、高性能及分布式、深入浅出。微服务、Spring,MyBatis,Netty源码分析的朋友可以加我的Java高级交流:854630135,群里有阿里大牛直播讲解技术,以及Java大型互联网技术的视频免费分享给大家。

  1. 集群group管理界面

 

XNginx - nginx 集群可视化管理工具

 

 

可以管理group的节点,配置文件,修改后可以一键重启所有节点,且配置文件出错时会提示错误,不会影响线上服务。

2.集群Node节点管理

XNginx - nginx 集群可视化管理工具

 

 

3 .集群Node节点日志查看

XNginx - nginx 集群可视化管理工具

 

 

  1. 生成的配置文件预览

 

XNginx - nginx 集群可视化管理工具

 

 

  1. vhost管理

 

XNginx - nginx 集群可视化管理工具

 

 

设计思路

数据结构:

一个nginxGroup,拥有多个NginxNode,共享同一份配置文件。

分布式架构:Manager节点+agent节点+web管理

每个nginx机器部署一个agent,agent启动后自动注册到manager,通过web可以设置agent所属group,以及管理group的配置文件。

配置文件变更后,manager生成配置文件,分发给存活的agent,检验OK后,控制agent重启nginx。

关键技术点

分布式管理

一般分布式可以借助zookeeper等注册中心来实现,作为java项目,其实使用EurekaServer就可以了:

manager加入eureka依赖:

 <dependency>
 <groupId>org.springframework.cloud</groupId>
 <artifactId>spring-cloud-starter</artifactId>
 </dependency>
 <dependency>
 <groupId>org.springframework.cloud</groupId>
 <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
 </dependency>

然后在入口程序添加 @EnableEurekaServer

agent 添加注册配置:

eureka:
 instance:
 prefer-ip-address: true
 client:
 service-url:
 defaultZone: http://admin:admin@ip:3002/eureka/

manager 节点获取存活的agent,可以通过EurekaServerContextHolder来获取注册的agent,同时可以通过定时任务自动发现新节点。

public class NginxNodeDiscover {
 private static final String AGENT_NAME = "XNGINXAGENT";
 private PeerAwareInstanceRegistry getRegistry() {
 return getServerContext().getRegistry();
 }
 private EurekaServerContext getServerContext() {
 return EurekaServerContextHolder.getInstance().getServerContext();
 }
 @Autowired
 NginxNodeRepository nginxNodeRepository;
 @Scheduled(fixedRate = 60000)
 public void discoverNginxNode() {
 List<String> nodes = getAliveAgents();
 nodes.stream().forEach(node->{
 if(!nginxNodeRepository.findByAgent(node).isPresent()){
 NginxNode nginxNode = new NginxNode();
 nginxNode.setAgent(node);
 nginxNode.setName(node);
 nginxNodeRepository.save(nginxNode);
 }
 });
 }
 public List<String> getAliveAgents() {
 List<String> instances = new ArrayList<>();
 List<Application> sortedApplications = getRegistry().getSortedApplications();
 Optional<Application> targetApp = sortedApplications.stream().filter(a->a.getName().equals(AGENT_NAME)).findFirst();
 if(targetApp.isPresent()){
 Application app = targetApp.get();
 for (InstanceInfo info : app.getInstances()) {
 instances.add(info.getHomePageUrl());
 }
 }
 return instances;
 }
}

RPC调用

manager 需要控制agent,按最简单的方案,agent提供rest服务,从Eureka获取地址后直接调用就可以了,另外可以借助feign来方便调用。

如果想学习Java工程化、高性能及分布式、深入浅出。微服务、Spring,MyBatis,Netty源码分析的朋友可以加我的Java高级交流:854630135,群里有阿里大牛直播讲解技术,以及Java大型互联网技术的视频免费分享给大家。

定义接口:

public interface NginxAgentManager {
 @RequestLine("GET /nginx/start")
 RuntimeBuilder.RuntimeResult start() ;
 @RequestLine("GET /nginx/status")
 RuntimeBuilder.RuntimeResult status() ;
 @RequestLine("GET /nginx/reload")
 RuntimeBuilder.RuntimeResult reload() ;
 @RequestLine("GET /nginx/stop")
 RuntimeBuilder.RuntimeResult stop();
 @RequestLine("GET /nginx/testConfiguration")
 RuntimeBuilder.RuntimeResult testConfiguration();
 @RequestLine("GET /nginx/kill")
 RuntimeBuilder.RuntimeResult kill() ;
 @RequestLine("GET /nginx/restart")
 RuntimeBuilder.RuntimeResult restart() ;
 @RequestLine("GET /nginx/info")
 NginxInfo info();
 @RequestLine("GET /nginx/os")
 OperationalSystemInfo os() ;
 @RequestLine("GET /nginx/accesslogs/{lines}")
 List<NginxLoggerVM> getAccesslogs(@Param("lines") int lines);
 @RequestLine("GET /nginx/errorlogs/{lines}")
 List<NginxLoggerVM> getErrorLogs(@Param("lines") int lines);
}

agent 实现功能:

@RestController
@RequestMapping("/nginx")
public class NginxResource {
 ...
 @PostMapping("/update")
 @Timed
 public String update(@RequestBody NginxConf conf){
 if(conf.getSslDirectives()!=null){
 for(SslDirective sslDirective : conf.getSslDirectives()){
 nginxControl.conf(sslDirective.getCommonName(),sslDirective.getContent());
 }
 }
 return updateConfig(conf.getConf());
 }
 @GetMapping("/accesslogs/{lines}")
 @Timed
 public List<NginxLoggerVM> getAccesslogs(@PathVariable Integer lines) {
 return nginxControl.getAccessLogs(lines);
 }
}

manager 调用;

先生成一个Proxy实例,其中nodeurl是agent节点的url地址

 public NginxAgentManager getAgentManager(String nodeUrl){
 return Feign.builder()
 .options(new Request.Options(1000, 3500))
 .retryer(new Retryer.Default(5000, 5000, 3))
 .requestInterceptor(new HeaderRequestInterceptor())
 .encoder(new GsonEncoder())
 .decoder(new GsonDecoder())
 .target(NginxAgentManager.class, nodeUrl);
 }

然后调用就简单了,比如要启动group:

public void start(String groupId){
 operateGroup(groupId,((conf, node) -> {
 NginxAgentManager manager = getAgentManager(node.getAgent());
 String result = manager.update(conf);
 if(!result.equals("success")){
 throw new XNginxException("node "+ node.getAgent()+" update config file failed!");
 }
 RuntimeBuilder.RuntimeResult runtimeResult = manager.start();
 if(!runtimeResult.isSuccess()){
 throw new XNginxException("node "+ node.getAgent()+" start failed,"+runtimeResult.getOutput());
 }
 }));
 }
 public void operateGroup(String groupId,BiConsumer<NginxConf,NginxNode> action){
 List<String> alivedNodes = nodeDiscover.getAliveAgents();
 if(alivedNodes.size() == 0){
 throw new XNginxException("no alived agent!");
 }
 List<NginxNode> nginxNodes = nodeRepository.findAllByGroupId(groupId);
 if(nginxNodes.size() ==0){
 throw new XNginxException("the group has no nginx Nodes!");
 }
 NginxConf conf = nginxConfigService.genConfig(groupId);
 for(NginxNode node : nginxNodes){
 if(!alivedNodes.contains(node.getAgent())){
 continue;
 }
 action.accept(conf, node);
 }
 }

Nginx 配置管理

nginx的核心是各种Directive(指令),最核心的是vhost和Location。

我们先来定义VHOST:

public class VirtualHostDirective implements Directive {
 private Integer port = 80;
 private String aliases;
 private boolean enableSSL;
 private SslDirective sslCertificate;
 private SslDirective sslCertificateKey;
 private List<LocationDirective> locations;
 private String root;
 private String index;
 private String access_log;
}

其中核心的LocationDirective,设计思路是passAddress存储location的目标地址,可以是url,也可以是upstream,通过type来区分,同时如果有upstream,则通过proxy来设置负载信息。

public class LocationDirective {
 public static final String PROXY = "PROXY";
 public static final String UWSGI = "UWSGI";
 public static final String FASTCGI = "FASTCGI";
 public static final String COMMON = "STATIC";
 private String path;
 private String type = COMMON;
 private ProxyDirective proxy;
 private List<String> rewrites;
 
 private String advanced;
 private String passAddress;
 
 }

再来看ProxyDirective,通过balance来区分是普通的url还是upstream,如果是upstream,servers存储负载的服务器。

public class ProxyDirective implements Directive {
 public static final String BALANCE_UPSTREAM = "upstream";
 public static final String BALANCE_URL = "url";
 private String name;
 private String strategy;
 /**
 * Upstream balance type : upsteam,url
 */
 private String balance = BALANCE_UPSTREAM;
 private List<UpstreamDirectiveServer> servers;
 
 }

历史数据导入

已经有了配置信息,可以通过解析导入系统,解析就是常规的文本解析,这里不再赘述。

核心思想就是通过匹配大括号,将配置文件分成block,然后通过正则等提取信息,比如下面的代码拆分出server{...}

private List<String> blocks() {
 List<String> blocks = new ArrayList<>();
 List<String> lines = Arrays.asList(fileContent.split("
"));
 AtomicInteger atomicInteger = new AtomicInteger(0);
 AtomicInteger currentLine = new AtomicInteger(1);
 Integer indexStart = 0;
 Integer serverStartIndex = 0;
 for (String line : lines) {
 if (line.contains("{")) {
 atomicInteger.getAndIncrement();
 if (line.contains("server")) {
 indexStart = currentLine.get() - 1;
 serverStartIndex = atomicInteger.get() - 1;
 }
 } else if (line.contains("}")) {
 atomicInteger.getAndDecrement();
 if (atomicInteger.get() == serverStartIndex) {
 if (lines.get(indexStart).trim().startsWith("server")) {
 blocks.add(StringUtils.join(lines.subList(indexStart, currentLine.get()), "
"));
 }
 }
 }
 currentLine.getAndIncrement();
 }
 return blocks;
 }

配置文件生成

配置文件生成,一般是通过模板引擎,这里也不例外,使用了Velocity库。

 public static StringWriter mergeFileTemplate(String pTemplatePath, Map<String, Object> pDto) {
 if (StringUtils.isEmpty(pTemplatePath)) {
 throw new NullPointerException("????????????");
 }
 StringWriter writer = new StringWriter();
 Template template;
 try {
 template = ve.getTemplate(pTemplatePath);
 } catch (Exception e) {
 throw new RuntimeException("????????", e);
 }
 VelocityContext context = VelocityHelper.convertDto2VelocityContext(pDto);
 try {
 template.merge(context, writer);
 } catch (Exception e) {
 throw new RuntimeException("????????", e);
 }
 return writer;
 }

定义模板:

#if(${config.user})user ${config.user};#end
#if(${config.workerProcesses}== 0 )
worker_processes auto;
#else
worker_processes ${config.workerProcesses};
#end
pid /opt/xnginx/settings/nginx.pid;
events {
 multi_accept off;
 worker_connections ${config.workerConnections};
}
...

生成配置文件;

 public static StringWriter buildNginxConfString(ServerConfig serverConfig, List<VirtualHostDirective> hostDirectiveList, List<ProxyDirective> proxyDirectiveList) {
 Map<String,Object> map = new HashMap<>();
 map.put("config",serverConfig);
 map.put("upstreams", proxyDirectiveList);
 map.put("hosts",hostDirectiveList);
 return VelocityHelper.mergeFileTemplate(NGINX_CONF_VM, map);
 }

欢迎工作一到八年的Java工程师朋友们加入Java高级交流:854630135

本群提供免费的学习指导 架构资料 以及免费的解答

不懂得问题都可以在本群提出来 之后还会有直播平台和讲师直接交流噢

simulink求解器选择的小tip 给出了simulink选择求解器的一种tip,与积分初值有关。 阅读详情

相关推荐

PMAC上位机通信原理(C#)

基础是引用 两个 ODT dll 原理是先注册到communication.AsyncDataAvailable事件中去 if (bSuccess1) { communication.AsyncDataAvailable += communication_AsyncDataAvailable; } bool bSuccess2 = communication1.GPAsciiConnect(strIP, iPort, strName, strPassword); i

weixin_45507349的博客 1087

Nginx配置管理平台

软件环境 centos7 python2.7.6 etcd3.2.18 confd 0.16 nginx1.12.1 效果演示 拓扑图 涉及软件 软件部署 1)安装 etcd(这里安装的单机,集群环境根据自己的需求选取)  # yum install etcd -y  # sed -i  's/localhost/0.0.0.0/g'  /etc/etcd/etcd.c...

菲宇运维 1万+

混合编程实战:C#集成C++ PCL点云处理库,打造跨语言动态链接库

本文详细介绍了C#与C++混合编程实战,重点讲解如何通过动态链接库(DLL)集成C++ PCL点云处理库,实现跨语言协作。内容涵盖环境配置、PCL功能封装、C#调用DLL的完整方案,以及性能优化和错误处理等进阶技巧,帮助开发者高效处理大规模点云数据,提升工业软件开发效率。

weixin_42620913的博客 383

基于nginx的高可用web集群

nginx是十分轻量级的HTTP服务器。是一个高性能的HTTP和反向代理服务器,同时也是一个代理服务器。了解nginx的基本操作nginx一键安装脚本(去掉http模块)stream {#负载均衡器的定义web} #负载均衡器的定义dns# 使用的tcp} }四层负载均衡和七层负载均衡四层速度快,支持的服务数量多(http、dns、ftp、mysql等):虚拟路由冗余协议路由器故障转移的基础vip —virtual ip(对外提供服务的ip )...

m0_59371732的博客 1706

win11 labelme 汉化菜单

【代码】win11 labelme 汉化菜单。

一直记录 1170

用python自动复制粘贴excel表里某一列的数据到另一个表中

昨天接到人事小姐姐求助减轻复制粘贴的重复工作量,分享一下代码 半路新手上路 耶 把 2.xlsx 表里的第二列 的数据复制粘贴到 test.xlsx的第一列 python3.6.2 from openpyxl import Workbook from openpyxl import load_workbook from openpyxl.writer.excel import Exc...

weixin_33854644的博客 2万+

超强大的 Nginx 可视化管理平台 Nginx-Proxy-Manager

Nginx-Proxy-Manager 是一个基于 Web 的 Nginx 服务器管理工具,它允许用户通过浏览器界面轻松地管理和监控 Nginx 服务器。:Nginx-Proxy-Manager 提供了一个直观的 Web 界面,用户可以通过浏览器轻松地查看和管理 Nginx 服务器。:用户可以在 Nginx-Proxy-Manager 中编辑 Nginx 的配置文件,支持语法高亮和自动补全功能。:Nginx-Proxy-Manager 可以查看和分析 Nginx 的访问日志、错误日志等,帮助用户诊断问题。

ljy413988585的博客 4844

CNN经典网络模型(二):AlexNet简介及代码实现(PyTorch超详细注释版)

CNN经典网络模型之一:AlexNet,本文包含其简介及代码,在PyTorch中实现,进行超详细注释,适合新生小白阅读学习~

qq_43307074的博客 2万+

【亲测免费】 Nginx Admin:一款开源的多平台 Nginx 管理工具

Nginx Admin:一款开源的多平台 Nginx 管理工具 Nginx Admin 是一个开源的多平台管理工具,旨在简化 Nginx 软件的日常管理工作。该项目主要使用 Java 编程语言开发,同时结合了 Shell、Smarty、PLSQL、Dockerfile、HTML 等技术栈。 项目核心功能 多平台管理:Nginx Admin 支持多种操作系统平台,用户可以在一个统一的管理界面下管理...

gitblog_00835的博客 628

从零理解域随机化:通过Isaac Lab的events.py掌握Sim-to-Real关键技术

本文深入解析域随机化技术如何通过Isaac Lab的events.py实现Sim-to-Real迁移,提升机器人策略在真实世界的鲁棒性。从刚体属性到环境条件的系统级随机化,详细介绍了工程实践中的关键参数配置与调试技巧,帮助开发者有效缩小仿真与现实的差距。

weixin_29062613的博客 261

浅析MOS管导通过程及RC吸收电路设计要点

RC吸收电路 米勒电容 MOS导通过程

liangbo1999的博客 2万+

nginx集群_XNginx - nginx 集群可视化管理工具

之前团队的nginx管理,都是运维同学每次去修改配置文件,然后重启,非常不方便,一直想找一个可以方便管理nginx集群的工具,翻遍web,未寻到可用之物,于是自己设计开发了一个。效果预览如果想学习Java工程化、高性能及分布式、深入浅出。微服务、Spring,MyBatis,Netty源码分析的朋友可以加我的Java高级交流:854630135,群里有阿里大牛直播讲解技术,以及Java大型互联网技...

weixin_40002009的博客 402

10步掌握!跨国企业在MySQL中实现数据主权的秘诀 vs. 传统方法,你选对了吗?

首先,我们要明确“数据主权”这一概念。简单来说,它指的是国家对其境内产生的所有类型的数据拥有绝对控制权。这意味着即使数据被存储在国外服务器上,只要该数据来源于某国,那么该国政府就有权对其进行监管。对于跨国公司来说,这就要求它们必须严格遵循不同国家关于数据保护的规定,如欧盟的GDPR、美国的《云法案》以及中国的《网络安全法》等。

java专栏 714

XNginx - nginx 集群可视化管理工具

之前团队的nginx管理,都是运维同学每次去修改配置文件,然后重启,非常不方便,一直想找一个可以方便管理nginx集群的工具,翻遍web,未寻到可用之物,于是自己设计开发了一个。 效果预览 集群group管理界面 可以管理group的节点,配置文件,修改后可以一键重启所有节点,且配置文件出错时会提示错误,不会影响线上服务。 2.集群Node节点管理 3 .集群Node节点日志查看...

weixin_30339457的博客 191

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

XNginx升级记录

之前的博文提到过,XNginx - nginx 集群可视化管理工具, 开发完成后一直稳定运行,直到前面因为一个站点的proxy站点配置问题,导致需要修改nginx 配置文件模板,因此借此机会对系统做了升级。 前端升级到最新版的ng-alain 事实证明,升级是痛苦的,前端项目真是一言难尽,能不动最好不动! 主要的变更是: - 之前的simple-table变成了st - desc也没了,...

weixin_38168198的博客 170

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

【亲测免费】 推荐一款强大的Nginx管理工具 - NginxGUI

推荐一款强大的Nginx管理工具 - NginxGUI 是一个基于Web的开源工具,旨在简化Nginx服务器的配置和管理任务。它提供了直观、用户友好的界面,让非程序员也能轻松进行Nginx服务的部署和调整。 技术解析 NginxGUI 的核心特点是其前端采用现代化的Web开发框架,可能是React或Vue.js,这使得界面响应迅速且易于交互。后端与Nginx服务器通信,可能利用了RESTful A...

gitblog_00043的博客 1053

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

Nginx 学习总结(17)—— 8 个免费开源 Nginx 管理系统,轻松管理 Nginx 站点配置

Nginx 是一个高效的 HTTP 服务器和反向代理,它擅长处理静态资源、负载均衡和网关代理等任务。Nginx 的设置主要通过一个主配置文件 “nginx.conf” 来完成,其中可以定义服务器配置块(server blocks)和位置匹配规则(location blocks)等。尽管 Nginx 的配置语法相当简洁,但在处理复杂的路由规则、反向代理设置或 SSL 配置时,配置文件可能会变得复杂。特别是当涉及到多层嵌套和特定条件判断时,稍有不慎就可能导致配置错误或冲突。

科技D人生 5259

1.8 万 Star!这款 Nginx 可视化配置工具太强了

NginxConfig简介Nginx Config 是一个强大的 Nginx 配置文件生成器,号称配置 Nginx 服务器所需的唯一工具。正因为 Nginx 功能强大,所以针对其各个功能的配置项会显得特别多,对于我们来说要记住那么多配置是一件十分头疼的事,甚至会经常出现符号书写错误的情况。而 Nginx Config 正是提供了简单配置 Nginx 的方法,通过可视化页面,针对 Nginx 的各个配置项提供了简洁明了的配置方法。

java_linux_dev的博客 3127

【Docker】搭建强大的Nginx可视化配置工具 - nginxWebUI

本教程基于绿联的NAS设备DX4600 Pro的docker功能进行搭建。NginxWebUI是一个基于Java的,专门用来管理Nginx的图形界面工具。它是开源的,使用相对简单且功能全面。使用NginxWebUI,用户可以在图形界面中完成Nginx的配置管理,不需要直接编辑配置文件。它提供了对Nginx的各项功能的可视化操作,包括服务器的启动、停止、重载配置、编辑配置文件等。

小小笔记大大用处 4640

Puppet批量管理Nginx服务器

开发环境和测试环境均是CentOS6.4 x86_64,ngxin的模板文件是在puppet模块下面templates目录中以”.erb”结尾的文件,puppet模板主要用于文件,例如各种服务的配置文件,相同的服务,不同的配置就可以考虑使用模板文件,例如Nginx和Apache的虚拟主机配置就可以考虑采用ERB模板,nginx的安装在这里建议用第三方yum源来安装,如果是用Nginx的官方源来安装...

weixin_34216107的博客 199

可视化代理神器,动动手指轻松配置Nginx

1.背景 对于想自己搭建网站的朋友,使用自己个性化域名的朋友,使用Nginx的不在少数,可能也会使用Apache来管理自己的网站,但Nginx轻量又好用,还支持正向/反向代理,谁不喜欢呢? 但喜欢是一回事,跟"爱"还是有一定区别的,Nginx的配置就是一大难点,对于才入门又想配置好一个自己的网站着实要花费很大的功夫,但是我们广大和程序员就是做着一件事的-把事情简单化!难的东西总有简单化的工具。 Nginx Proxy Manager就是一款让你能通过网页的一些设置,完成网站的代理配置,无需自己再手

zounan909的博客 1787

Nginx——Nginx实现服务端集群搭建

1、Nginx与Tomcat部署 我们知道Nginx在高并发场景和处理静态资源是非常高性能的,但是在实际项目中除了静态资源还有就是后台业务代码模块,一般后台业务代码模块都会被部署在Tomcat,weblogic或者是websphere等web服务器上,那么如何使用Nginx接收用户的请求并把请求转发到后台web服务器? 步骤分析: 准备Tomcat环境,并在Tomcat上部署一个web项目; 准备Nginx环境,使用Nginx接收请求,并把请求分发到Tomcat上。 upstream we

weixin_44623055的博客 5316

nginx-gui

我自己用iis发布的项目,不要使用80端口发布,80端口让给了nginx使用。又因为不是很懂代码操作,所以想用个图形化nginx控制面板控制就好了。文件内容,上面配置完成,nginx.conf 配置就自动完成了。我有一个阿里云windows服务器有多个项目,有多个项目绑定。子域名:minidata.zdemo.com。目前我注册了一个域名,解析成了4个子域名。子域名:mdtest.zdemo.com。子域名:index.zdemo.com。子域名:jm1.zdemo.com。域名:zdemo.com。

妹妹的秘密 2369
上一篇: 从构建分布式秒杀系统聊聊验证码
下一篇: Netty 100万级高并发服务器配置
javaQQ群 866865133
博客等级 码龄8年 59粉丝 309原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值