Nginx学习笔记1 基本配置

This guide gives a basic introduction to nginx and describes some simple tasks that can be done with it. It is supposed that nginx is already installed on the reader’s machine. If it is not, see the Installing nginx page. This guide describes how to start and stop nginx, and reload its configuration, explains the structure of the configuration file and describes how to set up nginx to serve out static content, how to configure nginx as a proxy server, and how to connect it with a FastCGI application.

nginx has one master process and several worker processes. The main purpose of the master process is to read and evaluate configuration, and maintain worker processes. Worker processes do actual processing of requests. nginx employs event-based model and OS-dependent mechanisms to efficiently distribute requests among worker processes. The number of worker processes is defined in the configuration file and may be fixed for a given configuration or automatically adjusted to the number of available CPU cores (see worker_processes).

The way nginx and its modules work is determined in the configuration file. By default, the configuration file is named nginx.conf and placed in the directory /usr/local/nginx/conf, /etc/nginx, or /usr/local/etc/nginx.

Starting, Stopping, and Reloading Configuration
To start nginx, run the executable file. Once nginx is started, it can be controlled by invoking the executable with the -s parameter. Use the following syntax:

1
nginx -s signal

Where signal may be one of the following:

  • stop — fast shutdown
  • quit — graceful shutdown
  • reload — reloading the configuration file
  • reopen — reopening the log files

Read More

邻接矩阵和出度入度

图的邻接矩阵(Adjacency Matrix)存储方式是用两个数组来表示图。一个一维的数组存储图中顶点信息,一个二维数组(称为邻接矩阵)存储图中的边或弧的信息。

设图G有n个顶点,则邻接矩阵是一个n*n的方阵,定义为:

Read More

软件工程师常用电话号码

阿里云 95187
阿里云 售前 95187-1
阿里云 售后 95187-2
腾讯云 4009-100-100
招商银行信用卡 人工客服 4008205555->输入身份证信息->输入查询密码->9->6
苹果(APPLE)客服电话 400-666-8800
平安证券客服电话 95511转8

优雅解决Java Jar包冲突问题

前言

当我们开发的Spark Application变得越来越复杂,依赖的jar包越来越多时,难免会碰到jar包冲突的问题。

举个例子:

我们的业务代码用到了一个第三方库,好比:guava(虽然好用,但是版本间的兼容性差的一坨翔)
Spark本身也依赖了guava,但是和业务代码中依赖的guava版本不同
这种情况下,把我们的Spark Application提交到集群里执行,很有可能因为版本问题导致运行出错。

大家都知道,JVM的ClassLoader加载类的时候,同一个ClassLoader加载的类,如果出现重复,只有第一个会被加载,后面重复的类会被忽略掉。

就我们的例子来说,整个Spark Application会优先加载Spark jars目录下的guava包,那么我们的业务代码自然很有可能受到影响了。

Read More

LogBack入门实践

一、简介

LogBack是一个日志框架,它是Log4j作者Ceki的又一个日志组件。

LogBack,Slf4j,Log4j之间的关系

slf4j是The Simple Logging Facade for Java的简称,是一个简单日志门面抽象框架,它本身只提供了日志Facade API和一个简单的日志类实现,一般常配合Log4jLogBackjava.util.logging使用。Slf4j作为应用层的Log接入时,程序可以根据实际应用场景动态调整底层的日志实现框架(Log4j/LogBack/JdkLog…);

LogBack和Log4j都是开源日记工具库,LogBack是Log4j的改良版本,比Log4j拥有更多的特性,同时也带来很大性能提升。

LogBack官方建议配合Slf4j使用,这样可以灵活地替换底层日志框架。

Read More

Nginx语法小记

least_conn 负载均衡的算法

我们知道轮询算法是把请求平均的转发给各个后端,使它们的负载大致相同。

这有个前提,就是每个请求所占用的后端时间要差不多,如果有些请求占用的时间很长,会导致其所在的后端负载较高。在这种场景下,把请求转发给连接数较少的后端,能够达到更好的负载均衡效果,这就是least_conn算法。

least_conn算法很简单,首选遍历后端集群,比较每个后端conns/weight,选取该值最小的后端。

如果有多个后端的conns/weight值同为最小的,那么对它们采用加权轮询算法。

如果有least_conn指令,表示使用least connected负载均衡算法。

log_format 日志格式设定

log_format指令用来设置日志的记录格式,它的语法如下:

1
2
3
4
5
6
7
8

log_format name format {format ...}
其中name表示定义的格式名称,format表示定义的格式样式。

log_format有一个默认的、无须设置的combined日志格式设置,相当于Apache的combined日志格式,其具体参数如下:
log_format combined '$remote_addr-$remote_user [$time_local]'
"$request"$status $body_bytes_sent
"$http_referer" "$http_user_agent"

access_log 用来指定日志文件的存放路径、格式(把定义的log_format 跟在后面)和缓存大小;如果不想启用日志则access_log off ;

location 用来匹配来访的url https://segmentfault.com/a/1190000013267839
proxy_redirect https://blog.csdn.net/u010391029/article/details/50395680
X-Real-IP 这个X-real-ip是一个自定义的变量名,名字可以随意取,这样做完之后,用户的真实ip就被放在X-real-ip这个变量里了,然后,在web端可以这样获取:
request.getAttribute(“X-real-ip”)
http://gong1208.iteye.com/blog/1559835

root 需要本地文件 https://www.jianshu.com/p/4be0d5882ec5

String对象的内存分析

Java中内存分析:

  栈(Stack) :存放基本类型的变量数据和对象的引用,但对象本身不存放在栈中,而是存放在堆(new 出来的对象)或者常量池中(字符串常量对象存放在常量池中)。

  堆(heap):存放所有new出来的对象。

  常量池(constant pool):在堆中分配出来的一块存储区域,存储显式的String常量和基本类型常量(float、int等)。另外,可以存储不经常改变的东西(public static final)。常量池中的数据可以共享。

  静态存储:存放静态成员(static定义的)。

  

1)

1
2
  String a = "abc";①  
  String b = "abc";②

  分析:
  ①代码执行后在常量池(constant pool)中创建了一个值为abc的String对象,②执行时,因为常量池中存在”abc”所以就不再创建新的String对象了。

2)

1
2
  String   c   =   new   String("xyz");①  
  String d = new String("xyz");②

  分析:①Class被加载时,”xyz”被作为常量读入,在常量池(constant pool)里创建了一个共享的值为”xyz”的String对象;然后当调用到new String(“xyz”)的时候,会在堆(heap)里创建这个new String(“xyz”)对象;②由于常量池(constant pool)中存在”xyz”所以不再创建”xyz”,然后创建新的new String(“xyz”)。
3)

1
2
3
4
5
  String   s1   =   new   String("xyz");     //创建二个对象(常量池和堆中),一个引用   
  String s2 = new String("xyz"); //创建一个对象(堆中),并且以后每执行一次创建一个对象,一个引用

  String s3 = "xyz"; //创建一个对象(常量池中),一个引用
  String s4 = "xyz"; //不创建对象(共享上次常量池中的数据),只是创建一个新的引用

4)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
public class TestStr {   
public static void main(String\[\] args) {
// 以下两条语句创建了1个对象。"凤山"存储在字符串常量池中
String str1 = "凤山";
String str2 = "凤山";
System.out.println(str1==str2);//true
//以下两条语句创建了3个对象。"天峨",存储在字符串常量池中,两个new String()对象存储在堆内存中
String str3 = new String("天峨");
String str4 = new String("天峨");
System.out.println(str3==str4);//false
//以下两条语句创建了1个对象。9是存储在栈内存中
int i = 9;
int j = 9;
System.out.println(i==j);//true
//由于没有了装箱,以下两条语句创建了2个对象。两个1对象存储在堆内存中
Integer l1 = new Integer(1);
Integer k1 = new Integer(1);
System.out.println(l1==k1);//false

  //以下两条语句创建了1个对象。1对象存储在栈内存中。自动装箱时对于值从1到127之间的值,使用一个实例。
Integer l = 20;//装箱
Integer k = 20;//装箱
System.out.println(l==k);//true

//以下两条语句创建了2个对象。i1,i2变量存储在栈内存中,两个256对象存储在堆内存中
Integer i1 = 256;
Integer i2 = 256;
System.out.println(i1==i2);//false
}
}

参考 https://www.cnblogs.com/devinzhang/archive/2012/01/25/2329463.html

数据仓库——事实表、维度表、聚合表

事实表

在多维数据仓库中,保存度量值的详细值或事实的表称为“事实表”。一个按照州、产品和月份划分的销售量和销售额存储的事实表有5个列,概念上与下面的示例类似。

Sate Product Mouth Units Dollars
WA Mountain-100 January 3 7.95
WA CableLock January 4 7.32
OR Mountain-100 January 3 7.95
OR CableLock January 4 7.32
WA Mountain-100 February 16 42.40

在这些事实表的示例数据行中,前3个列——州、产品和月份——为键值列。剩下的两个列——销售额和销售量——为度量值。事实表中的每个列通常要么是键值列,要么是度量值列,但也可能包含其他参考目的的列——例如采购订单号或者发票号。

Read More

Markdown常用语法规则

基础书写格式

段落

在 Markdown 中,连续的一行或多行就是一个段落。用空行来进行切段。

  1. 这是第一个段落
  2. 我跟上面是同一个段落

  3. 这是第二个段落

大纲

Markdown 中,使用 # 来定义大纲标题,有多少个 #,就表示是几级的大纲。比如:

  1. # 这是一级标题(会生成<h1>标签)

  2. 这里是段落内容

  3. ## 这里是二级标题(会生成<h2>标签)

  4. 这里是段落内容

  5. ...

  6. ###### 这里是六级标题

这种书写方式非常直观自然。

Read More