|
|
<!DOCTYPE html>
|
|
|
<html lang="zh-Hans">
|
|
|
<head>
|
|
|
<meta charset="UTF-8">
|
|
|
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
|
|
|
<meta name="theme-color" content="#222">
|
|
|
<meta name="generator" content="Hexo 4.2.0">
|
|
|
<link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
|
|
|
<link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
|
|
|
<link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
|
|
|
<link rel="mask-icon" href="/images/logo.svg" color="#222">
|
|
|
<meta name="google-site-verification" content="2X6S9P7CAjXjVvw8YyQR8pCu-B0oEu7O9quLgxXuWyA">
|
|
|
<meta name="baidu-site-verification" content="dV8JGNzi0c">
|
|
|
<meta name="chinaz-site-verification" content="500A176AA29CFB31">
|
|
|
|
|
|
<script data-ad-client="ca-pub-7480618470784058" async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
|
|
|
|
|
|
<link rel="stylesheet" href="/css/main.css">
|
|
|
|
|
|
<link rel="stylesheet" href="//fonts.loli.net/css?family=Lato:300,300italic,400,400italic,700,700italic|M+ 2p:300,300italic,400,400italic,700,700italic&display=swap&subset=latin,latin-ext">
|
|
|
<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">
|
|
|
<link rel="stylesheet" href="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.css">
|
|
|
|
|
|
<script id="hexo-configurations">
|
|
|
var NexT = window.NexT || {};
|
|
|
var CONFIG = {"hostname":"nicksxs.me","root":"/","scheme":"Pisces","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":true,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":true,"mediumzoom":false,"lazyload":true,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}};
|
|
|
</script>
|
|
|
|
|
|
<meta name="description" content="learn from zero,技术博客,Nicksxs,史学森">
|
|
|
<meta property="og:type" content="website">
|
|
|
<meta property="og:title" content="Nicksxs's Blog">
|
|
|
<meta property="og:url" content="https://nicksxs.me/page/14/index.html">
|
|
|
<meta property="og:site_name" content="Nicksxs's Blog">
|
|
|
<meta property="og:description" content="learn from zero,技术博客,Nicksxs,史学森">
|
|
|
<meta property="article:author" content="Nicksxs">
|
|
|
<meta property="article:tag" content="Nicksxs">
|
|
|
<meta property="article:tag" content="史学森">
|
|
|
<meta property="article:tag" content="米方方">
|
|
|
<meta property="article:tag" content="米方方的男朋友">
|
|
|
<meta property="article:tag" content="森哥">
|
|
|
<meta name="twitter:card" content="summary">
|
|
|
|
|
|
<link rel="canonical" href="https://nicksxs.me/page/14/">
|
|
|
|
|
|
|
|
|
<script id="page-configurations">
|
|
|
// https://hexo.io/docs/variables.html
|
|
|
CONFIG.page = {
|
|
|
sidebar: "",
|
|
|
isHome : true,
|
|
|
isPost : false,
|
|
|
lang : 'zh-Hans'
|
|
|
};
|
|
|
</script>
|
|
|
|
|
|
<title>Nicksxs's Blog</title>
|
|
|
|
|
|
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-61358619-1"></script>
|
|
|
<script>
|
|
|
if (CONFIG.hostname === location.hostname) {
|
|
|
window.dataLayer = window.dataLayer || [];
|
|
|
function gtag(){dataLayer.push(arguments);}
|
|
|
gtag('js', new Date());
|
|
|
gtag('config', 'UA-61358619-1');
|
|
|
}
|
|
|
</script>
|
|
|
|
|
|
|
|
|
<script>
|
|
|
var _hmt = _hmt || [];
|
|
|
(function() {
|
|
|
var hm = document.createElement("script");
|
|
|
hm.src = "https://hm.baidu.com/hm.js?20f33b3c0c0eff9b1522999c0015646d";
|
|
|
var s = document.getElementsByTagName("script")[0];
|
|
|
s.parentNode.insertBefore(hm, s);
|
|
|
})();
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<noscript>
|
|
|
<style>
|
|
|
.use-motion .brand,
|
|
|
.use-motion .menu-item,
|
|
|
.sidebar-inner,
|
|
|
.use-motion .post-block,
|
|
|
.use-motion .pagination,
|
|
|
.use-motion .comments,
|
|
|
.use-motion .post-header,
|
|
|
.use-motion .post-body,
|
|
|
.use-motion .collection-header { opacity: initial; }
|
|
|
|
|
|
.use-motion .site-title,
|
|
|
.use-motion .site-subtitle {
|
|
|
opacity: initial;
|
|
|
top: initial;
|
|
|
}
|
|
|
|
|
|
.use-motion .logo-line-before i { left: initial; }
|
|
|
.use-motion .logo-line-after i { right: initial; }
|
|
|
</style>
|
|
|
</noscript>
|
|
|
|
|
|
<link rel="alternate" href="/atom.xml" title="Nicksxs's Blog" type="application/atom+xml">
|
|
|
</head>
|
|
|
|
|
|
<body itemscope itemtype="http://schema.org/WebPage">
|
|
|
<div class="container use-motion">
|
|
|
<div class="headband"></div>
|
|
|
|
|
|
<header class="header" itemscope itemtype="http://schema.org/WPHeader">
|
|
|
<div class="header-inner"><div class="site-brand-container">
|
|
|
<div class="site-nav-toggle">
|
|
|
<div class="toggle" aria-label="Toggle navigation bar">
|
|
|
<span class="toggle-line toggle-line-first"></span>
|
|
|
<span class="toggle-line toggle-line-middle"></span>
|
|
|
<span class="toggle-line toggle-line-last"></span>
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
<div class="site-meta">
|
|
|
|
|
|
<a href="/" class="brand" rel="start">
|
|
|
<span class="logo-line-before"><i></i></span>
|
|
|
<h1 class="site-title">Nicksxs's Blog</h1>
|
|
|
<span class="logo-line-after"><i></i></span>
|
|
|
</a>
|
|
|
<p class="site-subtitle" itemprop="description">What hurts more, the pain of hard work or the pain of regret?</p>
|
|
|
</div>
|
|
|
|
|
|
<div class="site-nav-right">
|
|
|
<div class="toggle popup-trigger">
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<nav class="site-nav">
|
|
|
<ul id="menu" class="main-menu menu">
|
|
|
<li class="menu-item menu-item-home">
|
|
|
|
|
|
<a href="/" rel="section"><i class="home fa-fw"></i>Home</a>
|
|
|
|
|
|
</li>
|
|
|
<li class="menu-item menu-item-about">
|
|
|
|
|
|
<a href="/about/" rel="section"><i class="about fa-fw"></i>About</a>
|
|
|
|
|
|
</li>
|
|
|
<li class="menu-item menu-item-tags">
|
|
|
|
|
|
<a href="/tags/" rel="section"><i class="tags fa-fw"></i>Tags</a>
|
|
|
|
|
|
</li>
|
|
|
<li class="menu-item menu-item-categories">
|
|
|
|
|
|
<a href="/categories/" rel="section"><i class="categories fa-fw"></i>Categories</a>
|
|
|
|
|
|
</li>
|
|
|
<li class="menu-item menu-item-archives">
|
|
|
|
|
|
<a href="/archives/" rel="section"><i class="archives fa-fw"></i>Archives</a>
|
|
|
|
|
|
</li>
|
|
|
<li class="menu-item menu-item-sitemap">
|
|
|
|
|
|
<a href="/sitemap.xml" rel="section"><i class="sitemap fa-fw"></i>Sitemap</a>
|
|
|
|
|
|
</li>
|
|
|
<li class="menu-item menu-item-commonweal">
|
|
|
|
|
|
<a href="/404/" rel="section"><i class="heartbeat fa-fw"></i>Commonweal 404</a>
|
|
|
|
|
|
</li>
|
|
|
</ul>
|
|
|
</nav>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
</header>
|
|
|
|
|
|
|
|
|
<div class="back-to-top">
|
|
|
<i class="fa fa-arrow-up"></i>
|
|
|
<span>0%</span>
|
|
|
</div>
|
|
|
|
|
|
<a href="https://github.com/nicksxs" class="github-corner" title="Follow me on GitHub" aria-label="Follow me on GitHub" rel="noopener" target="_blank"><svg width="80" height="80" viewBox="0 0 250 250" aria-hidden="true"><path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a>
|
|
|
|
|
|
|
|
|
<main class="main">
|
|
|
<div class="main-inner">
|
|
|
<div class="content-wrap">
|
|
|
|
|
|
|
|
|
<div class="content index posts-expand">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-Hans">
|
|
|
<link itemprop="mainEntityOfPage" href="https://nicksxs.me/2019/06/18/openresty/">
|
|
|
|
|
|
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
|
|
|
<meta itemprop="image" content="/uploads/avatar.jpg">
|
|
|
<meta itemprop="name" content="Nicksxs">
|
|
|
<meta itemprop="description" content="learn from zero,技术博客,Nicksxs,史学森">
|
|
|
</span>
|
|
|
|
|
|
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
|
|
|
<meta itemprop="name" content="Nicksxs's Blog">
|
|
|
</span>
|
|
|
<header class="post-header">
|
|
|
<h2 class="post-title" itemprop="name headline">
|
|
|
|
|
|
<a href="/2019/06/18/openresty/" class="post-title-link" itemprop="url">openresty</a>
|
|
|
</h2>
|
|
|
|
|
|
<div class="post-meta">
|
|
|
<span class="post-meta-item">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="far fa-calendar"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Posted on</span>
|
|
|
|
|
|
<time title="Created: 2019-06-18 19:03:05" itemprop="dateCreated datePublished" datetime="2019-06-18T19:03:05+08:00">2019-06-18</time>
|
|
|
</span>
|
|
|
<span class="post-meta-item">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="far fa-calendar-check"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Edited on</span>
|
|
|
<time title="Modified: 2020-01-12 21:08:27" itemprop="dateModified" datetime="2020-01-12T21:08:27+08:00">2020-01-12</time>
|
|
|
</span>
|
|
|
<span class="post-meta-item">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="far fa-folder"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">In</span>
|
|
|
<span itemprop="about" itemscope itemtype="http://schema.org/Thing">
|
|
|
<a href="/categories/nginx/" itemprop="url" rel="index"><span itemprop="name">nginx</span></a>
|
|
|
</span>
|
|
|
</span>
|
|
|
|
|
|
|
|
|
<span id="/2019/06/18/openresty/" class="post-meta-item leancloud_visitors" data-flag-title="openresty" title="Views">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-eye"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Views: </span>
|
|
|
<span class="leancloud-visitors-count"></span>
|
|
|
</span>
|
|
|
|
|
|
<span class="post-meta-item">
|
|
|
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="far fa-comment"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Disqus: </span>
|
|
|
|
|
|
<a title="disqus" href="/2019/06/18/openresty/#disqus_thread" itemprop="discussionUrl">
|
|
|
<span class="post-comments-count disqus-comment-count" data-disqus-identifier="2019/06/18/openresty/" itemprop="commentCount"></span>
|
|
|
</a>
|
|
|
</span>
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
</header>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class="post-body" itemprop="articleBody">
|
|
|
|
|
|
|
|
|
<p>目前公司要对一些新的产品功能做灰度测试,因为在后端业务代码层面添加判断比较麻烦,所以想在nginx上做点手脚,就想到了openresty<br>前后也踩了不少坑,这边先写一点</p>
|
|
|
<p>首先是日志<br><code>error_log logs/error.log debug;</code><br>需要nginx开启日志的debug才能看到日志</p>
|
|
|
<p>使用 <code>lua_code_cache off</code>即可, 另外注意只有使用 <code>content_by_lua_file</code> 才会生效</p>
|
|
|
<figure class="highlight lua"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">http {</span><br><span class="line"> lua_code_cache off;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line">location ~* /(\d+-.*)/api/orgunits/load_all(.*) {</span><br><span class="line"> default_type <span class="string">'application/json;charset=utf-8'</span>;</span><br><span class="line"> content_by_lua_file /data/projects/xxx/current/lua/controller/load_data.lua;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
|
|
|
|
|
|
<p>使用lua给nginx请求response头添加内容可以用这个</p>
|
|
|
<figure class="highlight lua"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">ngx.header[<span class="string">'response'</span>] = <span class="string">'header'</span></span><br></pre></td></tr></table></figure>
|
|
|
|
|
|
|
|
|
<p><a href="http://cyukang.com/2017/05/22/try-on-openresty.html" target="_blank" rel="noopener">使用总结</a></p>
|
|
|
<p>后续:</p>
|
|
|
<ol>
|
|
|
<li>一开始在本地环境的时候使用content_by_lua_file只关注了头,后来发到测试环境发现请求内容都没代理转发到后端服务上<br>网上查了下发现content_by_lua_file是将请求的所有内容包括response都用这里面的lua脚本生成了,content这个词就表示是请求内容<br>后来改成了access_by_lua_file就正常了,只是要去获取请求内容和修改响应头,并不是要完整的接管请求</li>
|
|
|
</ol>
|
|
|
<ol start="2">
|
|
|
<li><p>后来又碰到了一个坑是nginx有个client_body_buffer_size的配置参数,nginx在32位和64位系统里有8K和16K两个默认值,当请求内容大于这两个值的时候,会把请求内容放到临时文件里,这个时候openresty里的ngx.req.get_post_args()就会报“failed to get post args: requesty body in temp file not supported”这个错误,将client_body_buffer_size这个参数配置调大一点就好了</p>
|
|
|
</li>
|
|
|
<li><p>还有就是lua的异常捕获,网上看一般是用pcall和xpcall来进行保护调用,因为问题主要出在cjson的decode,这里有两个解决方案,一个就是将cjson.decode使用pcall封装,</p>
|
|
|
<figure class="highlight lua"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">local</span> decode = <span class="built_in">require</span>(<span class="string">"cjson"</span>).decode</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">json_decode</span><span class="params">( str )</span></span></span><br><span class="line"> <span class="keyword">local</span> ok, t = <span class="built_in">pcall</span>(decode, str)</span><br><span class="line"> <span class="keyword">if</span> <span class="keyword">not</span> ok <span class="keyword">then</span></span><br><span class="line"> <span class="keyword">return</span> <span class="literal">nil</span></span><br><span class="line"> <span class="keyword">end</span></span><br><span class="line"></span><br><span class="line"> <span class="keyword">return</span> t</span><br><span class="line"><span class="keyword">end</span></span><br></pre></td></tr></table></figure>
|
|
|
<p> 这个是使用了pcall,称为保护调用,会在内部错误后返回两个参数,第一个是false,第二个是错误信息<br> 还有一种是使用cjson.safe包</p>
|
|
|
<figure class="highlight lua"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">local</span> json = <span class="built_in">require</span>(<span class="string">"cjson.safe"</span>)</span><br><span class="line"><span class="keyword">local</span> str = <span class="string">[[ {"key:"value"} ]]</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">local</span> t = json.decode(str)</span><br><span class="line"><span class="keyword">if</span> t <span class="keyword">then</span></span><br><span class="line"> ngx.say(<span class="string">" --> "</span>, <span class="built_in">type</span>(t))</span><br><span class="line"><span class="keyword">end</span></span><br></pre></td></tr></table></figure>
|
|
|
<p> cjson.safe包会在解析失败的时候返回nil</p>
|
|
|
</li>
|
|
|
<li><p>还有一个是redis链接时如果host使用的是域名的话会提示“failed to connect: no resolver defined to resolve “redis.xxxxxx.com””,这里需要使用nginx的resolver指令,<br><code>resolver 8.8.8.8 valid=3600s;</code></p>
|
|
|
</li>
|
|
|
<li><p>还有一点补充下<br>就是业务在使用redis的时候使用了db的特性,所以在lua访问redis的时候也需要执行db,这里lua的redis库也支持了这个特性,可以使用instance:select(config:get(‘db’))来切换db</p>
|
|
|
</li>
|
|
|
<li><p>性能优化tips<br><a href="https://juejin.im/entry/5b0e8fcef265da09210072a3#openresty" target="_blank" rel="noopener">建议是尽量少使用阶段钩子,例如content_by_lua_file,*_by_lua</a></p>
|
|
|
</li>
|
|
|
<li><p>发现一个不错的openresty站点<br><a href="http://orhub.org/" target="_blank" rel="noopener">地址</a></p>
|
|
|
</li>
|
|
|
</ol>
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<footer class="post-footer">
|
|
|
<div class="post-eof"></div>
|
|
|
</footer>
|
|
|
</article>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-Hans">
|
|
|
<link itemprop="mainEntityOfPage" href="https://nicksxs.me/2017/05/09/ambari-summary/">
|
|
|
|
|
|
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
|
|
|
<meta itemprop="image" content="/uploads/avatar.jpg">
|
|
|
<meta itemprop="name" content="Nicksxs">
|
|
|
<meta itemprop="description" content="learn from zero,技术博客,Nicksxs,史学森">
|
|
|
</span>
|
|
|
|
|
|
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
|
|
|
<meta itemprop="name" content="Nicksxs's Blog">
|
|
|
</span>
|
|
|
<header class="post-header">
|
|
|
<h2 class="post-title" itemprop="name headline">
|
|
|
|
|
|
<a href="/2017/05/09/ambari-summary/" class="post-title-link" itemprop="url">ambari-summary</a>
|
|
|
</h2>
|
|
|
|
|
|
<div class="post-meta">
|
|
|
<span class="post-meta-item">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="far fa-calendar"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Posted on</span>
|
|
|
|
|
|
<time title="Created: 2017-05-09 23:53:05" itemprop="dateCreated datePublished" datetime="2017-05-09T23:53:05+08:00">2017-05-09</time>
|
|
|
</span>
|
|
|
<span class="post-meta-item">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="far fa-calendar-check"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Edited on</span>
|
|
|
<time title="Modified: 2020-01-12 21:08:27" itemprop="dateModified" datetime="2020-01-12T21:08:27+08:00">2020-01-12</time>
|
|
|
</span>
|
|
|
<span class="post-meta-item">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="far fa-folder"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">In</span>
|
|
|
<span itemprop="about" itemscope itemtype="http://schema.org/Thing">
|
|
|
<a href="/categories/data-analysis/" itemprop="url" rel="index"><span itemprop="name">data analysis</span></a>
|
|
|
</span>
|
|
|
</span>
|
|
|
|
|
|
|
|
|
<span id="/2017/05/09/ambari-summary/" class="post-meta-item leancloud_visitors" data-flag-title="ambari-summary" title="Views">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-eye"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Views: </span>
|
|
|
<span class="leancloud-visitors-count"></span>
|
|
|
</span>
|
|
|
|
|
|
<span class="post-meta-item">
|
|
|
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="far fa-comment"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Disqus: </span>
|
|
|
|
|
|
<a title="disqus" href="/2017/05/09/ambari-summary/#disqus_thread" itemprop="discussionUrl">
|
|
|
<span class="post-comments-count disqus-comment-count" data-disqus-identifier="2017/05/09/ambari-summary/" itemprop="commentCount"></span>
|
|
|
</a>
|
|
|
</span>
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
</header>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class="post-body" itemprop="articleBody">
|
|
|
|
|
|
|
|
|
<h2 id="初识ambari"><a href="#初识ambari" class="headerlink" title="初识ambari"></a>初识ambari</h2><p><a href="http://ambari.apache.org/" target="_blank" rel="noopener">ambari</a>是一个大数据平台的管理工具,包含了<code>hadoop</code>, <code>yarn</code>, <code>hive</code>, <code>hbase</code>, <code>spark</code>等大数据的基础架构和工具,简化了数据平台的搭建,之前只是在同事搭建好平台后的一些使用,这次有机会从头开始用<code>ambari</code>来搭建一个测试的数据平台,过程中也踩到不少坑,简单记录下。</p>
|
|
|
<h2 id="简单过程"><a href="#简单过程" class="headerlink" title="简单过程"></a>简单过程</h2><ul>
|
|
|
<li>第一个坑<br>在刚开始是按照官网的指南,用maven构建,因为GFW的原因,导致反复失败等待,也就是这个<a href="https://cwiki.apache.org/confluence/display/AMBARI/Installation+Guide+for+Ambari+2.5.0" target="_blank" rel="noopener">guide</a>,因为对maven不熟悉导致有些按图索骥,浪费了很多时间,之后才知道可以直接加repo用yum安装,然而用yum安装马上就出现了第二个坑。</li>
|
|
|
<li>第二个坑<br>因为在线的repo还是因为网络原因很慢很慢,用proxychains勉强把ambari-server本身安装好了,<a href="http://public-repo-1.hortonworks.com/ambari/centos7/2.x/updates/2.5.0.3/ambari.repo" target="_blank" rel="noopener">ambari.repo</a>将这个放进<code>/etc/yum.repos.d/</code>路径下,然后<code>yum update && yum install ambari-server</code>安装即可,如果有条件就用proxychains走下代理。</li>
|
|
|
<li>第三步<br>安装好ambari-server后先执行<code>ambari-server setup</code>做一些初始化设置,其中包含了JDK路径的设置,数据库设置,设置好就OK了,然后执行<code>ambari-server start</code>启动服务,这里有个小插曲,因为<code>ambari-server</code>涉及到这么多服务,所以管理控制监控之类的模块是必不可少的,这部分可以在<code>ambari-server</code>的web ui界面安装,也可以命令行提前安装,这部分被称为<code>HDF Management Pack</code>,运行```ambari-server install-mpack \</li>
|
|
|
<li>-mpack=<a href="http://public-repo-1.hortonworks.com/HDF/centos7/2.x/updates/2.1.4.0/tars/hdf_ambari_mp/hdf-ambari-mpack-2.1.4.0-5.tar.gz" target="_blank" rel="noopener">http://public-repo-1.hortonworks.com/HDF/centos7/2.x/updates/2.1.4.0/tars/hdf_ambari_mp/hdf-ambari-mpack-2.1.4.0-5.tar.gz</a> \</li>
|
|
|
<li>-purge \</li>
|
|
|
<li>-verbose```<br>安装,当然这个压缩包可以下载之后指到本地路径安装,然后就可以重启<code>ambari-server</code></li>
|
|
|
</ul>
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<footer class="post-footer">
|
|
|
<div class="post-eof"></div>
|
|
|
</footer>
|
|
|
</article>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-Hans">
|
|
|
<link itemprop="mainEntityOfPage" href="https://nicksxs.me/2017/04/25/rabbitmq-tips/">
|
|
|
|
|
|
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
|
|
|
<meta itemprop="image" content="/uploads/avatar.jpg">
|
|
|
<meta itemprop="name" content="Nicksxs">
|
|
|
<meta itemprop="description" content="learn from zero,技术博客,Nicksxs,史学森">
|
|
|
</span>
|
|
|
|
|
|
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
|
|
|
<meta itemprop="name" content="Nicksxs's Blog">
|
|
|
</span>
|
|
|
<header class="post-header">
|
|
|
<h2 class="post-title" itemprop="name headline">
|
|
|
|
|
|
<a href="/2017/04/25/rabbitmq-tips/" class="post-title-link" itemprop="url">rabbitmq-tips</a>
|
|
|
</h2>
|
|
|
|
|
|
<div class="post-meta">
|
|
|
<span class="post-meta-item">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="far fa-calendar"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Posted on</span>
|
|
|
|
|
|
<time title="Created: 2017-04-25 21:46:55" itemprop="dateCreated datePublished" datetime="2017-04-25T21:46:55+08:00">2017-04-25</time>
|
|
|
</span>
|
|
|
<span class="post-meta-item">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="far fa-calendar-check"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Edited on</span>
|
|
|
<time title="Modified: 2020-01-12 21:08:26" itemprop="dateModified" datetime="2020-01-12T21:08:26+08:00">2020-01-12</time>
|
|
|
</span>
|
|
|
<span class="post-meta-item">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="far fa-folder"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">In</span>
|
|
|
<span itemprop="about" itemscope itemtype="http://schema.org/Thing">
|
|
|
<a href="/categories/php/" itemprop="url" rel="index"><span itemprop="name">php</span></a>
|
|
|
</span>
|
|
|
</span>
|
|
|
|
|
|
|
|
|
<span id="/2017/04/25/rabbitmq-tips/" class="post-meta-item leancloud_visitors" data-flag-title="rabbitmq-tips" title="Views">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-eye"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Views: </span>
|
|
|
<span class="leancloud-visitors-count"></span>
|
|
|
</span>
|
|
|
|
|
|
<span class="post-meta-item">
|
|
|
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="far fa-comment"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Disqus: </span>
|
|
|
|
|
|
<a title="disqus" href="/2017/04/25/rabbitmq-tips/#disqus_thread" itemprop="discussionUrl">
|
|
|
<span class="post-comments-count disqus-comment-count" data-disqus-identifier="2017/04/25/rabbitmq-tips/" itemprop="commentCount"></span>
|
|
|
</a>
|
|
|
</span>
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
</header>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class="post-body" itemprop="articleBody">
|
|
|
|
|
|
|
|
|
<h2 id="rabbitmq-介绍"><a href="#rabbitmq-介绍" class="headerlink" title="rabbitmq 介绍"></a>rabbitmq 介绍</h2><p>接触了一下rabbitmq,原来在选型的时候是在rabbitmq跟kafka之间做选择,网上搜了一下之后发现kafka的优势在于吞吐量,而rabbitmq相对注重可靠性,因为应用在im上,需要保证消息不能丢失所以就暂时选定rabbitmq,<br>Message Queue的需求由来已久,80年代最早在金融交易中,高盛等公司采用Teknekron公司的产品,当时的Message queuing软件叫做:the information bus(TIB)。 TIB被电信和通讯公司采用,路透社收购了Teknekron公司。之后,IBM开发了MQSeries,微软开发了Microsoft Message Queue(MSMQ)。这些商业MQ供应商的问题是厂商锁定,价格高昂。2001年,Java Message queuing试图解决锁定和交互性的问题,但对应用来说反而更加麻烦了。<br>RabbitMQ采用Erlang语言开发。Erlang语言由Ericson设计,专门为开发concurrent和distribution系统的一种语言,在电信领域使用广泛。OTP(Open Telecom Platform)作为Erlang语言的一部分,包含了很多基于Erlang开发的中间件/库/工具,如mnesia/SASL,极大方便了Erlang应用的开发。OTP就类似于Python语言中众多的module,用户借助这些module可以很方便的开发应用。<br>于是2004年,摩根大通和iMatrix开始着手<a href="https://en.wikipedia.org/wiki/Advanced_Message_Queuing_Protocol" target="_blank" rel="noopener">Advanced Message Queuing Protocol (AMQP)</a>开放标准的开发。2006年,AMQP规范发布。2007年,Rabbit技术公司基于AMQP标准开发的RabbitMQ 1.0 发布。所有主要的编程语言均有与代理接口通讯的客户端库。</p>
|
|
|
<h2 id="简单的使用经验"><a href="#简单的使用经验" class="headerlink" title="简单的使用经验"></a>简单的使用经验</h2><h3 id="通俗的理解"><a href="#通俗的理解" class="headerlink" title="通俗的理解"></a>通俗的理解</h3><p>这里介绍下其中的一些概念,connection表示和队列服务器的连接,一般情况下是tcp连接, channel表示通道,可以在一个连接上建立多个通道,这里主要是节省了tcp连接握手的成本,exchange可以理解成一个路由器,将消息推送给对应的队列queue,其实是像一个订阅的模式。</p>
|
|
|
<h3 id="集群经验"><a href="#集群经验" class="headerlink" title="集群经验"></a>集群经验</h3><p><code>rabbitmqctl stop</code>这个是关闭rabbitmq,在搭建集群时候先关闭服务,然后使用<code>rabbitmq-server -detached</code>静默启动,这时候使用<code>rabbitmqctl cluster_status</code>查看集群状态,因为还没将节点加入集群,所以只能看到类似</p>
|
|
|
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">Cluster status of node rabbit@rabbit1 ...</span><br><span class="line">[{nodes,[{disc,[rabbit@rabbit1,rabbit@rabbit2,rabbit@rabbit3]}]},</span><br><span class="line"> {running_nodes,[rabbit@rabbit2,rabbit@rabbit1]}]</span><br><span class="line">...done.</span><br></pre></td></tr></table></figure>
|
|
|
<p>然后就可以把当前节点加入集群,</p>
|
|
|
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">rabbit2$</span><span class="bash"> rabbitmqctl stop_app <span class="comment">#这个stop_app与stop的区别是前者停的是rabbitmq应用,保留erlang节点,</span></span></span><br><span class="line"> #后者是停止了rabbitmq和erlang节点</span><br><span class="line">Stopping node rabbit@rabbit2 ...done.</span><br><span class="line"><span class="meta">rabbit2$</span><span class="bash"> rabbitmqctl join_cluster rabbit@rabbit1 <span class="comment">#这里可以用--ram指定将当前节点作为内存节点加入集群</span></span></span><br><span class="line">Clustering node rabbit@rabbit2 with [rabbit@rabbit1] ...done.</span><br><span class="line"><span class="meta">rabbit2$</span><span class="bash"> rabbitmqctl start_app</span></span><br><span class="line">Starting node rabbit@rabbit2 ...done.</span><br></pre></td></tr></table></figure>
|
|
|
<p>其他可以参考<a href="http://www.rabbitmq.com/clustering.html" target="_blank" rel="noopener">官方文档</a></p>
|
|
|
<h2 id="一些坑"><a href="#一些坑" class="headerlink" title="一些坑"></a>一些坑</h2><h3 id="消息丢失"><a href="#消息丢失" class="headerlink" title="消息丢失"></a>消息丢失</h3><p>这里碰到过一个坑,对于使用exchange来做消息路由的,会有一个情况,就是在routing_key没被订阅的时候,会将该条找不到路由对应的queue的消息丢掉<code>What happens if we break our contract and send a message with one or four words, like "orange" or "quick.orange.male.rabbit"? Well, these messages won't match any bindings and will be lost.</code><a href="http://www.rabbitmq.com/tutorials/tutorial-five-python.html" target="_blank" rel="noopener">对应链接</a>,而当使用空的exchange时,会保留消息,当出现消费者的时候就可以将收到之前生产者所推送的消息<a href="http://www.rabbitmq.com/tutorials/tutorial-two-python.html" target="_blank" rel="noopener">对应链接</a>,这里就是用了空的exchange。</p>
|
|
|
<h3 id="集群搭建"><a href="#集群搭建" class="headerlink" title="集群搭建"></a>集群搭建</h3><p>集群搭建的时候有个erlang vm生成的random cookie,这个是用来做集群之间认证的,相同的cookie才能连接,但是如果通过vim打开复制后在其他几点新建文件写入会多一个换行,导致集群建立是报错,所以这里最好使用scp等传输命令直接传输cookie文件,同时要注意下cookie的文件权限。<br>另外在集群搭建的时候如果更改过hostname,那么要把rabbitmq的数据库删除,否则启动后会马上挂掉</p>
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<footer class="post-footer">
|
|
|
<div class="post-eof"></div>
|
|
|
</footer>
|
|
|
</article>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-Hans">
|
|
|
<link itemprop="mainEntityOfPage" href="https://nicksxs.me/2017/03/28/spark-little-tips/">
|
|
|
|
|
|
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
|
|
|
<meta itemprop="image" content="/uploads/avatar.jpg">
|
|
|
<meta itemprop="name" content="Nicksxs">
|
|
|
<meta itemprop="description" content="learn from zero,技术博客,Nicksxs,史学森">
|
|
|
</span>
|
|
|
|
|
|
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
|
|
|
<meta itemprop="name" content="Nicksxs's Blog">
|
|
|
</span>
|
|
|
<header class="post-header">
|
|
|
<h2 class="post-title" itemprop="name headline">
|
|
|
|
|
|
<a href="/2017/03/28/spark-little-tips/" class="post-title-link" itemprop="url">spark-little-tips</a>
|
|
|
</h2>
|
|
|
|
|
|
<div class="post-meta">
|
|
|
<span class="post-meta-item">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="far fa-calendar"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Posted on</span>
|
|
|
|
|
|
<time title="Created: 2017-03-28 19:20:56" itemprop="dateCreated datePublished" datetime="2017-03-28T19:20:56+08:00">2017-03-28</time>
|
|
|
</span>
|
|
|
<span class="post-meta-item">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="far fa-calendar-check"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Edited on</span>
|
|
|
<time title="Modified: 2020-01-12 21:08:26" itemprop="dateModified" datetime="2020-01-12T21:08:26+08:00">2020-01-12</time>
|
|
|
</span>
|
|
|
<span class="post-meta-item">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="far fa-folder"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">In</span>
|
|
|
<span itemprop="about" itemscope itemtype="http://schema.org/Thing">
|
|
|
<a href="/categories/data-analysis/" itemprop="url" rel="index"><span itemprop="name">data analysis</span></a>
|
|
|
</span>
|
|
|
</span>
|
|
|
|
|
|
|
|
|
<span id="/2017/03/28/spark-little-tips/" class="post-meta-item leancloud_visitors" data-flag-title="spark-little-tips" title="Views">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-eye"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Views: </span>
|
|
|
<span class="leancloud-visitors-count"></span>
|
|
|
</span>
|
|
|
|
|
|
<span class="post-meta-item">
|
|
|
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="far fa-comment"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Disqus: </span>
|
|
|
|
|
|
<a title="disqus" href="/2017/03/28/spark-little-tips/#disqus_thread" itemprop="discussionUrl">
|
|
|
<span class="post-comments-count disqus-comment-count" data-disqus-identifier="2017/03/28/spark-little-tips/" itemprop="commentCount"></span>
|
|
|
</a>
|
|
|
</span>
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
</header>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class="post-body" itemprop="articleBody">
|
|
|
|
|
|
|
|
|
<h2 id="spark-的一些粗浅使用经验"><a href="#spark-的一些粗浅使用经验" class="headerlink" title="spark 的一些粗浅使用经验"></a>spark 的一些粗浅使用经验</h2><p>工作中学习使用了一下Spark做数据分析,主要是用spark的python接口,首先是<code>pyspark.SparkContext(appName=xxx)</code>,这是初始化一个Spark应用实例或者说会话,不能重复,<br>返回的实例句柄就可以调用<code>textFile(path)</code>读取文本文件,这里的文本文件可以是HDFS上的文本文件,也可以普通文本文件,但是需要在Spark的所有集群上都存在,否则会<br>读取失败,<code>parallelize</code>则可以将python生成的集合数据读取后转换成rdd(A Resilient Distributed Dataset (RDD),一种spark下的基本抽象数据集),基于这个RDD就可以做<br>数据的流式计算,例如<code>map reduce</code>,在Spark中可以非常方便地实现 </p>
|
|
|
<h3 id="简单的mapreduce-word-count示例"><a href="#简单的mapreduce-word-count示例" class="headerlink" title="简单的mapreduce word count示例"></a>简单的mapreduce word count示例</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">textFile = sc.parallelize([(<span class="number">1</span>,<span class="number">1</span>), (<span class="number">2</span>,<span class="number">1</span>), (<span class="number">3</span>,<span class="number">1</span>), (<span class="number">4</span>,<span class="number">1</span>), (<span class="number">5</span>,<span class="number">1</span>),(<span class="number">1</span>,<span class="number">1</span>), (<span class="number">2</span>,<span class="number">1</span>), (<span class="number">3</span>,<span class="number">1</span>), (<span class="number">4</span>,<span class="number">1</span>), (<span class="number">5</span>,<span class="number">1</span>)])</span><br><span class="line">data = textFile.reduceByKey(<span class="keyword">lambda</span> x, y: x + y).collect()</span><br><span class="line"><span class="keyword">for</span> _ <span class="keyword">in</span> data:</span><br><span class="line"> print(_)</span><br></pre></td></tr></table></figure>
|
|
|
|
|
|
|
|
|
<h3 id="结果"><a href="#结果" class="headerlink" title="结果"></a>结果</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">(3, 2)</span><br><span class="line">(1, 2)</span><br><span class="line">(4, 2)</span><br><span class="line">(2, 2)</span><br><span class="line">(5, 2)</span><br></pre></td></tr></table></figure>
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<footer class="post-footer">
|
|
|
<div class="post-eof"></div>
|
|
|
</footer>
|
|
|
</article>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-Hans">
|
|
|
<link itemprop="mainEntityOfPage" href="https://nicksxs.me/2016/11/10/php-abstract-class-and-interface/">
|
|
|
|
|
|
<span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
|
|
|
<meta itemprop="image" content="/uploads/avatar.jpg">
|
|
|
<meta itemprop="name" content="Nicksxs">
|
|
|
<meta itemprop="description" content="learn from zero,技术博客,Nicksxs,史学森">
|
|
|
</span>
|
|
|
|
|
|
<span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
|
|
|
<meta itemprop="name" content="Nicksxs's Blog">
|
|
|
</span>
|
|
|
<header class="post-header">
|
|
|
<h2 class="post-title" itemprop="name headline">
|
|
|
|
|
|
<a href="/2016/11/10/php-abstract-class-and-interface/" class="post-title-link" itemprop="url">php-abstract-class-and-interface</a>
|
|
|
</h2>
|
|
|
|
|
|
<div class="post-meta">
|
|
|
<span class="post-meta-item">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="far fa-calendar"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Posted on</span>
|
|
|
|
|
|
<time title="Created: 2016-11-10 10:42:35" itemprop="dateCreated datePublished" datetime="2016-11-10T10:42:35+08:00">2016-11-10</time>
|
|
|
</span>
|
|
|
<span class="post-meta-item">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="far fa-calendar-check"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Edited on</span>
|
|
|
<time title="Modified: 2020-01-12 21:08:27" itemprop="dateModified" datetime="2020-01-12T21:08:27+08:00">2020-01-12</time>
|
|
|
</span>
|
|
|
<span class="post-meta-item">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="far fa-folder"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">In</span>
|
|
|
<span itemprop="about" itemscope itemtype="http://schema.org/Thing">
|
|
|
<a href="/categories/php/" itemprop="url" rel="index"><span itemprop="name">php</span></a>
|
|
|
</span>
|
|
|
</span>
|
|
|
|
|
|
|
|
|
<span id="/2016/11/10/php-abstract-class-and-interface/" class="post-meta-item leancloud_visitors" data-flag-title="php-abstract-class-and-interface" title="Views">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-eye"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Views: </span>
|
|
|
<span class="leancloud-visitors-count"></span>
|
|
|
</span>
|
|
|
|
|
|
<span class="post-meta-item">
|
|
|
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="far fa-comment"></i>
|
|
|
</span>
|
|
|
<span class="post-meta-item-text">Disqus: </span>
|
|
|
|
|
|
<a title="disqus" href="/2016/11/10/php-abstract-class-and-interface/#disqus_thread" itemprop="discussionUrl">
|
|
|
<span class="post-comments-count disqus-comment-count" data-disqus-identifier="2016/11/10/php-abstract-class-and-interface/" itemprop="commentCount"></span>
|
|
|
</a>
|
|
|
</span>
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
</header>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class="post-body" itemprop="articleBody">
|
|
|
|
|
|
|
|
|
<h2 id="PHP抽象类和接口"><a href="#PHP抽象类和接口" class="headerlink" title="PHP抽象类和接口"></a>PHP抽象类和接口</h2><ul>
|
|
|
<li>抽象类与接口</li>
|
|
|
<li>抽象类内可以包含非抽象函数,即可实现函数</li>
|
|
|
<li>抽象类内必须包含至少一个抽象方法,抽象类和接口均不能实例化</li>
|
|
|
<li>抽象类可以设置访问级别,接口默认都是public</li>
|
|
|
<li>类可以实现多个接口但不能继承多个抽象类</li>
|
|
|
<li>类必须实现抽象类和接口里的抽象方法,不一定要实现抽象类的非抽象方法</li>
|
|
|
<li>接口内不能定义变量,但是可以定义常量</li>
|
|
|
</ul>
|
|
|
<h2 id="示例代码"><a href="#示例代码" class="headerlink" title="示例代码"></a>示例代码</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"><?php</span><br><span class="line">interface int1{</span><br><span class="line"> const INTER1 = 111;</span><br><span class="line"> function inter1();</span><br><span class="line">}</span><br><span class="line">interface int2{</span><br><span class="line"> const INTER1 = 222;</span><br><span class="line"> function inter2();</span><br><span class="line">}</span><br><span class="line">abstract class abst1{</span><br><span class="line"> public function abstr1(){</span><br><span class="line"> echo 1111;</span><br><span class="line"> }</span><br><span class="line"> abstract function abstra1(){</span><br><span class="line"> echo 'ahahahha';</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line">abstract class abst2{</span><br><span class="line"> public function abstr2(){</span><br><span class="line"> echo 1111;</span><br><span class="line"> }</span><br><span class="line"> abstract function abstra2();</span><br><span class="line">}</span><br><span class="line">class normal1 extends abst1{</span><br><span class="line"> protected function abstr2(){</span><br><span class="line"> echo 222;</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure>
|
|
|
|
|
|
<h2 id="result"><a href="#result" class="headerlink" title="result"></a>result</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">PHP Fatal error: Abstract function abst1::abstra1() cannot contain body in new.php on line 17</span><br><span class="line"></span><br><span class="line">Fatal error: Abstract function abst1::abstra1() cannot contain body in php on line 17</span><br></pre></td></tr></table></figure>
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<footer class="post-footer">
|
|
|
<div class="post-eof"></div>
|
|
|
</footer>
|
|
|
</article>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<nav class="pagination">
|
|
|
<a class="extend prev" rel="prev" href="/page/13/"><i class="fa fa-angle-left" aria-label="Previous page"></i></a><a class="page-number" href="/">1</a><span class="space">…</span><a class="page-number" href="/page/13/">13</a><span class="page-number current">14</span><a class="page-number" href="/page/15/">15</a><span class="space">…</span><a class="page-number" href="/page/18/">18</a><a class="extend next" rel="next" href="/page/15/"><i class="fa fa-angle-right" aria-label="Next page"></i></a>
|
|
|
</nav>
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
<script>
|
|
|
window.addEventListener('tabs:register', () => {
|
|
|
let { activeClass } = CONFIG.comments;
|
|
|
if (CONFIG.comments.storage) {
|
|
|
activeClass = localStorage.getItem('comments_active') || activeClass;
|
|
|
}
|
|
|
if (activeClass) {
|
|
|
let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
|
|
|
if (activeTab) {
|
|
|
activeTab.click();
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
if (CONFIG.comments.storage) {
|
|
|
window.addEventListener('tabs:click', event => {
|
|
|
if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
|
|
|
let commentClass = event.target.classList[1];
|
|
|
localStorage.setItem('comments_active', commentClass);
|
|
|
});
|
|
|
}
|
|
|
</script>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
<div class="toggle sidebar-toggle">
|
|
|
<span class="toggle-line toggle-line-first"></span>
|
|
|
<span class="toggle-line toggle-line-middle"></span>
|
|
|
<span class="toggle-line toggle-line-last"></span>
|
|
|
</div>
|
|
|
|
|
|
<aside class="sidebar">
|
|
|
<div class="sidebar-inner">
|
|
|
|
|
|
<ul class="sidebar-nav motion-element">
|
|
|
<li class="sidebar-nav-toc">
|
|
|
Table of Contents
|
|
|
</li>
|
|
|
<li class="sidebar-nav-overview">
|
|
|
Overview
|
|
|
</li>
|
|
|
</ul>
|
|
|
|
|
|
<!--noindex-->
|
|
|
<div class="post-toc-wrap sidebar-panel">
|
|
|
</div>
|
|
|
<!--/noindex-->
|
|
|
|
|
|
<div class="site-overview-wrap sidebar-panel">
|
|
|
<div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
|
|
|
<img class="site-author-image" itemprop="image" alt="Nicksxs"
|
|
|
src="/uploads/avatar.jpg">
|
|
|
<p class="site-author-name" itemprop="name">Nicksxs</p>
|
|
|
<div class="site-description" itemprop="description">learn from zero,技术博客,Nicksxs,史学森</div>
|
|
|
</div>
|
|
|
<div class="site-state-wrap motion-element">
|
|
|
<nav class="site-state">
|
|
|
<div class="site-state-item site-state-posts">
|
|
|
<a href="/archives/">
|
|
|
|
|
|
<span class="site-state-item-count">88</span>
|
|
|
<span class="site-state-item-name">posts</span>
|
|
|
</a>
|
|
|
</div>
|
|
|
<div class="site-state-item site-state-categories">
|
|
|
<a href="/categories/">
|
|
|
|
|
|
<span class="site-state-item-count">109</span>
|
|
|
<span class="site-state-item-name">categories</span></a>
|
|
|
</div>
|
|
|
<div class="site-state-item site-state-tags">
|
|
|
<a href="/tags/">
|
|
|
|
|
|
<span class="site-state-item-count">156</span>
|
|
|
<span class="site-state-item-name">tags</span></a>
|
|
|
</div>
|
|
|
</nav>
|
|
|
</div>
|
|
|
<div class="links-of-author motion-element">
|
|
|
<span class="links-of-author-item">
|
|
|
<a href="https://github.com/nicksxs" title="GitHub → https://github.com/nicksxs" rel="noopener" target="_blank"><i class="github fa-fw"></i>GitHub</a>
|
|
|
</span>
|
|
|
<span class="links-of-author-item">
|
|
|
<a href="mailto:nicksxs1202@gmail.com" title="E-Mail → mailto:nicksxs1202@gmail.com" rel="noopener" target="_blank"><i class="envelope fa-fw"></i>E-Mail</a>
|
|
|
</span>
|
|
|
<span class="links-of-author-item">
|
|
|
<a href="/atom.xml" title="RSS → /atom.xml"><i class="rss fa-fw"></i>RSS</a>
|
|
|
</span>
|
|
|
</div>
|
|
|
<div class="cc-license motion-element" itemprop="license">
|
|
|
<a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" class="cc-opacity" rel="noopener" target="_blank"><img src="/images/cc-by-nc-sa.svg" alt="Creative Commons"></a>
|
|
|
</div>
|
|
|
|
|
|
<script type="text/javascript" charset="utf-8" src="/js/tagcloud.js"></script>
|
|
|
<script type="text/javascript" charset="utf-8" src="/js/tagcanvas.js"></script>
|
|
|
<div class="widget-wrap">
|
|
|
<div id="myCanvasContainer" class="widget tagcloud">
|
|
|
<canvas width="250" height="250" id="resCanvas" style="width=100%">
|
|
|
<ul class="tag-list" itemprop="keywords"><li class="tag-list-item"><a class="tag-list-link" href="/tags/2019/" rel="tag">2019</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/2020/" rel="tag">2020</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/2PC/" rel="tag">2PC</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/3PC/" rel="tag">3PC</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/AOP/" rel="tag">AOP</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Adaptive/" rel="tag">Adaptive</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Apollo/" rel="tag">Apollo</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Binary-Tree/" rel="tag">Binary Tree</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Broker/" rel="tag">Broker</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/C/" rel="tag">C</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/C/" rel="tag">C++</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Comparator/" rel="tag">Comparator</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/DFS/" rel="tag">DFS</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/DefaultMQPushConsumer/" rel="tag">DefaultMQPushConsumer</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Design-Patterns/" rel="tag">Design Patterns</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Distributed-Lock/" rel="tag">Distributed Lock</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Docker/" rel="tag">Docker</a><span class="tag-list-count">4</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Dockerfile/" rel="tag">Dockerfile</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Dubbo/" rel="tag">Dubbo</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Filter/" rel="tag">Filter</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/G1/" rel="tag">G1</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/GC/" rel="tag">GC</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Garbage-First-Collector/" rel="tag">Garbage-First Collector</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Gogs/" rel="tag">Gogs</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Homebrew/" rel="tag">Homebrew</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Inorder-Traversal/" rel="tag">Inorder Traversal</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Interceptor/" rel="tag">Interceptor</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/JMap/" rel="tag">JMap</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/JPS/" rel="tag">JPS</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/JStack/" rel="tag">JStack</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/JVM/" rel="tag">JVM</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Java/" rel="tag">Java</a><span class="tag-list-count">13</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Linked-List/" rel="tag">Linked List</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/MQ/" rel="tag">MQ</a><span class="tag-list-count">4</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Mac/" rel="tag">Mac</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Maven/" rel="tag">Maven</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Mybatis/" rel="tag">Mybatis</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Mysql/" rel="tag">Mysql</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/NameServer/" rel="tag">NameServer</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/PHP/" rel="tag">PHP</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Preorder-Traversal/" rel="tag">Preorder Traversal</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/RPC/" rel="tag">RPC</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Redis/" rel="tag">Redis</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/RocketMQ/" rel="tag">RocketMQ</a><span class="tag-list-count">4</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/SPI/" rel="tag">SPI</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Servlet/" rel="tag">Servlet</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Singleton/" rel="tag">Singleton</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Spring/" rel="tag">Spring</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Sql%E6%B3%A8%E5%85%A5/" rel="tag">Sql注入</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Stream/" rel="tag">Stream</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Thread-dump/" rel="tag">Thread dump</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Tomcat/" rel="tag">Tomcat</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Web/" rel="tag">Web</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Webhook/" rel="tag">Webhook</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/aqs/" rel="tag">aqs</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/bloom-filter/" rel="tag">bloom filter</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/c/" rel="tag">c++</a><span class="tag-list-count">14</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/cgroup/" rel="tag">cgroup</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/cluster/" rel="tag">cluster</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/docker/" rel="tag">docker</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/echo/" rel="tag">echo</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/environment/" rel="tag">environment</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/gap-lock/" rel="tag">gap lock</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/grep/" rel="tag">grep</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/hadoop/" rel="tag">hadoop</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/icu4c/" rel="tag">icu4c</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/im/" rel="tag">im</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/is-not-null/" rel="tag">is not null</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/is-null/" rel="tag">is null</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/java/" rel="tag">java</a><span class="tag-list-count">9</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/leetcode/" rel="tag">leetcode</a><span class="tag-list-count">21</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/leetcode-155/" rel="tag">leetcode 155</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/linked-list/" rel="tag">linked list</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/linux/" rel="tag">linux</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mfc/" rel="tag">mfc</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/min-stack/" rel="tag">min stack</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mq/" rel="tag">mq</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mvcc/" rel="tag">mvcc</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/mysql/" rel="tag">mysql</a><span class="tag-list-count">5</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/namespace/" rel="tag">namespace</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/next-key-lock/" rel="tag">next-key lock</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/nginx/" rel="tag">nginx</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/nullsfirst/" rel="tag">nullsfirst</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/openresty/" rel="tag">openresty</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/php/" rel="tag">php</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/procedure/" rel="tag">procedure</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/python/" rel="tag">python</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/read-view/" rel="tag">read view</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/redis/" rel="tag">redis</a><span class="tag-list-count">8</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/sort/" rel="tag">sort</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/spark/" rel="tag">spark</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/stack/" rel="tag">stack</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/string/" rel="tag">string</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/swoole/" rel="tag">swoole</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/uname/" rel="tag">uname</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/value/" rel="tag">value</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/websocket/" rel="tag">websocket</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/zsh/" rel="tag">zsh</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E4%B8%89%E9%98%B6%E6%AE%B5%E6%8F%90%E4%BA%A4/" rel="tag">三阶段提交</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E4%B8%A4%E9%98%B6%E6%AE%B5%E6%8F%90%E4%BA%A4/" rel="tag">两阶段提交</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E4%B8%AD%E5%BA%8F/" rel="tag">中序</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E4%B8%AD%E9%97%B4%E4%BB%B6/" rel="tag">中间件</a><span class="tag-list-count">4</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E4%BA%8C%E5%8F%89%E6%A0%91/" rel="tag">二叉树</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E4%BA%92%E6%96%A5%E9%94%81/" rel="tag">互斥锁</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%85%AC%E4%BA%A4%E8%BD%A6/" rel="tag">公交车</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%87%8F%E8%82%A5/" rel="tag">减肥</a><span class="tag-list-count">6</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%88%86%E5%B8%83%E5%BC%8F%E4%BA%8B%E5%8A%A1/" rel="tag">分布式事务</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%88%86%E5%B8%83%E5%BC%8F%E9%94%81/" rel="tag">分布式锁</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%89%8A%E5%B3%B0%E5%A1%AB%E8%B0%B7/" rel="tag">削峰填谷</a><span class="tag-list-count">4</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%89%8D%E5%BA%8F/" rel="tag">前序</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%8A%A0%E5%A1%9E/" rel="tag">加塞</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%8D%95%E4%BE%8B/" rel="tag">单例</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%8D%9A%E5%AE%A2%EF%BC%8C%E6%96%87%E7%AB%A0/" rel="tag">博客,文章</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%8F%91%E8%A1%8C%E7%89%88/" rel="tag">发行版</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%8F%A3%E7%BD%A9/" rel="tag">口罩</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%90%90%E6%A7%BD/" rel="tag">吐槽</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%AE%B9%E9%94%99%E6%9C%BA%E5%88%B6/" rel="tag">容错机制</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%AF%84%E7%94%9F%E8%99%AB/" rel="tag">寄生虫</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%B0%8F%E6%8A%80%E5%B7%A7/" rel="tag">小技巧</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%B8%83%E9%9A%86%E8%BF%87%E6%BB%A4%E5%99%A8/" rel="tag">布隆过滤器</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%B9%B2%E6%B4%BB/" rel="tag">干活</a><span class="tag-list-count">5</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%B9%B4%E4%B8%AD%E6%80%BB%E7%BB%93/" rel="tag">年中总结</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%B9%B4%E7%BB%88%E6%80%BB%E7%BB%93/" rel="tag">年终总结</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%B9%B8%E7%A6%8F%E4%BA%86%E5%90%97/" rel="tag">幸福了吗</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%B9%BB%E8%AF%BB/" rel="tag">幻读</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%BC%80%E8%BD%A6/" rel="tag">开车</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E5%BD%B1%E8%AF%84/" rel="tag">影评</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E6%89%93%E5%8D%A1/" rel="tag">打卡</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E6%8E%92%E5%BA%8F/" rel="tag">排序</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84/" rel="tag">数据结构</a><span class="tag-list-count">11</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E6%9C%80%E5%B0%8F%E6%A0%88/" rel="tag">最小栈</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E6%9D%80%E4%BA%BA%E8%AF%9B%E5%BF%83/" rel="tag">杀人诛心</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E6%B3%A8%E8%A7%A3/" rel="tag">注解</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E6%B6%88%E6%81%AF%E9%98%9F%E5%88%97/" rel="tag">消息队列</a><span class="tag-list-count">4</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E6%BA%90%E7%A0%81/" rel="tag">源码</a><span class="tag-list-count">11</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E6%BA%90%E7%A0%81%E8%A7%A3%E6%9E%90/" rel="tag">源码解析</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E7%94%9F%E6%B4%BB/" rel="tag">生活</a><span class="tag-list-count">12</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E7%96%AB%E6%83%85/" rel="tag">疫情</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E7%B3%9F%E5%BF%83%E4%BA%8B/" rel="tag">糟心事</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E7%B4%A2%E5%BC%95/" rel="tag">索引</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E7%BC%93%E5%AD%98/" rel="tag">缓存</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E7%BC%93%E5%AD%98%E5%87%BB%E7%A9%BF/" rel="tag">缓存击穿</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E7%BC%93%E5%AD%98%E7%A9%BF%E9%80%8F/" rel="tag">缓存穿透</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E7%BC%93%E5%AD%98%E9%9B%AA%E5%B4%A9/" rel="tag">缓存雪崩</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E7%BE%8E%E5%9B%BD/" rel="tag">美国</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E8%87%AA%E9%80%82%E5%BA%94%E6%8B%93%E5%B1%95/" rel="tag">自适应拓展</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E8%A7%84%E5%88%99/" rel="tag">规则</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E8%AE%BE%E8%AE%A1%E6%A8%A1%E5%BC%8F/" rel="tag">设计模式</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E8%AF%BB%E4%B9%A6/" rel="tag">读书</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E8%AF%BB%E5%90%8E%E6%84%9F/" rel="tag">读后感</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E8%B6%B3%E7%90%83/" rel="tag">足球</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E8%B7%91%E6%AD%A5/" rel="tag">跑步</a><span class="tag-list-count">6</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E8%BD%AC%E4%B9%89/" rel="tag">转义</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E8%BF%90%E5%8A%A8/" rel="tag">运动</a><span class="tag-list-count">6</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E9%80%92%E5%BD%92/" rel="tag">递归</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/%E9%A2%98%E8%A7%A3/" rel="tag">题解</a><span class="tag-list-count">8</span></li></ul>
|
|
|
</canvas>
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div class="links-of-blogroll motion-element">
|
|
|
<div class="links-of-blogroll-title"><i class="fa fa-link fa-fw"></i>
|
|
|
Links
|
|
|
</div>
|
|
|
<ul class="links-of-blogroll-list">
|
|
|
<li class="links-of-blogroll-item">
|
|
|
<a href="https://covermusic.cn/" title="https://covermusic.cn" rel="noopener" target="_blank">69伙伴</a>
|
|
|
</li>
|
|
|
</ul>
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
</aside>
|
|
|
<div id="sidebar-dimmer"></div>
|
|
|
|
|
|
|
|
|
</div>
|
|
|
</main>
|
|
|
|
|
|
<footer class="footer">
|
|
|
<div class="footer-inner">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class="copyright">
|
|
|
|
|
|
©
|
|
|
<span itemprop="copyrightYear">2021</span>
|
|
|
<span class="with-love">
|
|
|
<i class="fa fa-heart"></i>
|
|
|
</span>
|
|
|
<span class="author" itemprop="copyrightHolder">Nicksxs</span>
|
|
|
</div>
|
|
|
<div class="powered-by">Powered by <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://pisces.theme-next.org/" class="theme-link" rel="noopener" target="_blank">NexT.Pisces</a>
|
|
|
</div>
|
|
|
|
|
|
|
|
|
<div class="busuanzi-count">
|
|
|
<script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
|
|
|
<span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-user"></i>
|
|
|
</span>
|
|
|
<span class="site-uv" title="Total Visitors">
|
|
|
<span id="busuanzi_value_site_uv"></span>
|
|
|
</span>
|
|
|
</span>
|
|
|
<span class="post-meta-divider">|</span>
|
|
|
<span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
|
|
|
<span class="post-meta-item-icon">
|
|
|
<i class="fa fa-eye"></i>
|
|
|
</span>
|
|
|
<span class="site-pv" title="Total Views">
|
|
|
<span id="busuanzi_value_site_pv"></span>
|
|
|
</span>
|
|
|
</span>
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
(function() {
|
|
|
function leancloudSelector(url) {
|
|
|
url = encodeURI(url);
|
|
|
return document.getElementById(url).querySelector('.leancloud-visitors-count');
|
|
|
}
|
|
|
|
|
|
function addCount(Counter) {
|
|
|
var visitors = document.querySelector('.leancloud_visitors');
|
|
|
var url = decodeURI(visitors.id);
|
|
|
var title = visitors.dataset.flagTitle;
|
|
|
|
|
|
Counter('get', '/classes/Counter?where=' + encodeURIComponent(JSON.stringify({ url })))
|
|
|
.then(response => response.json())
|
|
|
.then(({ results }) => {
|
|
|
if (results.length > 0) {
|
|
|
var counter = results[0];
|
|
|
leancloudSelector(url).innerText = counter.time + 1;
|
|
|
Counter('put', '/classes/Counter/' + counter.objectId, { time: { '__op': 'Increment', 'amount': 1 } })
|
|
|
.catch(error => {
|
|
|
console.error('Failed to save visitor count', error);
|
|
|
});
|
|
|
} else {
|
|
|
leancloudSelector(url).innerText = 'Counter not initialized! More info at console err msg.';
|
|
|
console.error('ATTENTION! LeanCloud counter has security bug, see how to solve it here: https://github.com/theme-next/hexo-leancloud-counter-security. \n However, you can still use LeanCloud without security, by setting `security` option to `false`.');
|
|
|
|
|
|
}
|
|
|
})
|
|
|
.catch(error => {
|
|
|
console.error('LeanCloud Counter Error', error);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
function showTime(Counter) {
|
|
|
var visitors = document.querySelectorAll('.leancloud_visitors');
|
|
|
var entries = [...visitors].map(element => {
|
|
|
return decodeURI(element.id);
|
|
|
});
|
|
|
|
|
|
Counter('get', '/classes/Counter?where=' + encodeURIComponent(JSON.stringify({ url: { '$in': entries } })))
|
|
|
.then(response => response.json())
|
|
|
.then(({ results }) => {
|
|
|
for (let url of entries) {
|
|
|
let target = results.find(item => item.url === url);
|
|
|
leancloudSelector(url).innerText = target ? target.time : 0;
|
|
|
}
|
|
|
})
|
|
|
.catch(error => {
|
|
|
console.error('LeanCloud Counter Error', error);
|
|
|
});
|
|
|
}
|
|
|
|
|
|
let { app_id, app_key, server_url } = {"enable":true,"app_id":"ysza182Vghlqjdt7QiwGLLJy-gzGzoHsz","app_key":"s9GDqbn7gnGGkusf66YRVccw","server_url":"https://leancloud.cn","security":true};
|
|
|
function fetchData(api_server) {
|
|
|
var Counter = (method, url, data) => {
|
|
|
return fetch(`${api_server}/1.1${url}`, {
|
|
|
method,
|
|
|
headers: {
|
|
|
'X-LC-Id' : app_id,
|
|
|
'X-LC-Key' : app_key,
|
|
|
'Content-Type': 'application/json',
|
|
|
},
|
|
|
body: JSON.stringify(data)
|
|
|
});
|
|
|
};
|
|
|
if (CONFIG.page.isPost) {
|
|
|
if (CONFIG.hostname !== location.hostname) return;
|
|
|
addCount(Counter);
|
|
|
} else if (document.querySelectorAll('.post-title-link').length >= 1) {
|
|
|
showTime(Counter);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
let api_server = app_id.slice(-9) !== '-MdYXbMMI' ? server_url : `https://${app_id.slice(0, 8).toLowerCase()}.api.lncldglobal.com`;
|
|
|
|
|
|
if (api_server) {
|
|
|
fetchData(api_server);
|
|
|
} else {
|
|
|
fetch('https://app-router.leancloud.cn/2/route?appId=' + app_id)
|
|
|
.then(response => response.json())
|
|
|
.then(({ api_server }) => {
|
|
|
fetchData('https://' + api_server);
|
|
|
});
|
|
|
}
|
|
|
})();
|
|
|
</script>
|
|
|
|
|
|
|
|
|
</div>
|
|
|
</footer>
|
|
|
</div>
|
|
|
|
|
|
|
|
|
<script src="/lib/anime.min.js"></script>
|
|
|
<script src="//cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js"></script>
|
|
|
<script src="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.js"></script>
|
|
|
<script src="//cdn.jsdelivr.net/npm/lozad@1/dist/lozad.min.js"></script>
|
|
|
<script src="/lib/velocity/velocity.min.js"></script>
|
|
|
<script src="/lib/velocity/velocity.ui.min.js"></script>
|
|
|
|
|
|
<script src="/js/utils.js"></script>
|
|
|
|
|
|
<script src="/js/motion.js"></script>
|
|
|
|
|
|
|
|
|
<script src="/js/schemes/pisces.js"></script>
|
|
|
|
|
|
|
|
|
<script src="/js/next-boot.js"></script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
(function(){
|
|
|
var canonicalURL, curProtocol;
|
|
|
//Get the <link> tag
|
|
|
var x=document.getElementsByTagName("link");
|
|
|
//Find the last canonical URL
|
|
|
if(x.length > 0){
|
|
|
for (i=0;i<x.length;i++){
|
|
|
if(x[i].rel.toLowerCase() == 'canonical' && x[i].href){
|
|
|
canonicalURL=x[i].href;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
//Get protocol
|
|
|
if (!canonicalURL){
|
|
|
curProtocol = window.location.protocol.split(':')[0];
|
|
|
}
|
|
|
else{
|
|
|
curProtocol = canonicalURL.split(':')[0];
|
|
|
}
|
|
|
//Get current URL if the canonical URL does not exist
|
|
|
if (!canonicalURL) canonicalURL = window.location.href;
|
|
|
//Assign script content. Replace current URL with the canonical URL
|
|
|
!function(){var e=/([http|https]:\/\/[a-zA-Z0-9\_\.]+\.baidu\.com)/gi,r=canonicalURL,t=document.referrer;if(!e.test(r)){var n=(String(curProtocol).toLowerCase() === 'https')?"https://sp0.baidu.com/9_Q4simg2RQJ8t7jm9iCKT-xh_/s.gif":"//api.share.baidu.com/s.gif";t?(n+="?r="+encodeURIComponent(document.referrer),r&&(n+="&l="+r)):r&&(n+="?l="+r);var i=new Image;i.src=n}}(window);})();
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
function loadCount() {
|
|
|
var d = document, s = d.createElement('script');
|
|
|
s.src = 'https://nicksxs.disqus.com/count.js';
|
|
|
s.id = 'dsq-count-scr';
|
|
|
(d.head || d.body).appendChild(s);
|
|
|
}
|
|
|
// defer loading until the whole page loading is completed
|
|
|
window.addEventListener('load', loadCount, false);
|
|
|
</script>
|
|
|
|
|
|
</body>
|
|
|
</html>
|