| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604 |
- <!DOCTYPE html>
- <html lang="zh-CN">
- <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 5.4.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/safari-pinned-tab.svg" color="#222">
- <meta name="google-site-verification" content="cCGIgodGvlMoVATcXs4p7kl8BVhmqW8u1kcPBZfD2qw">
- <link rel="stylesheet" href="/css/main.css">
- <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&display=swap&subset=latin,latin-ext">
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.15.2/css/all.min.css">
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/animate.css@3.1.1/animate.min.css">
- <script class="hexo-configurations">
- var NexT = window.NexT || {};
- var CONFIG = {"hostname":"blog.izhixing.icu","root":"/","images":"/images","scheme":"Gemini","version":"8.2.2","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":false,"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果:${query}","hits_time":"找到 ${hits} 个搜索结果(用时 ${time} 毫秒)","hits":"找到 ${hits} 个搜索结果"},"path":"/search.xml","localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false}};
- </script>
- <meta name="description" content="新装的Linux系统,ssh、nginx、tomcat等各种服务都安装好了,可是在外网却访问不了??这十有八九是防火墙的端口没有打开了。">
- <meta property="og:type" content="article">
- <meta property="og:title" content="Linux操作指南:02-配置防火墙端口">
- <meta property="og:url" content="https://blog.izhixing.icu/posts/c62f803c.html">
- <meta property="og:site_name" content="知行">
- <meta property="og:description" content="新装的Linux系统,ssh、nginx、tomcat等各种服务都安装好了,可是在外网却访问不了??这十有八九是防火墙的端口没有打开了。">
- <meta property="og:locale" content="zh_CN">
- <meta property="article:published_time" content="2021-03-27T13:10:14.000Z">
- <meta property="article:modified_time" content="2021-04-06T14:39:44.492Z">
- <meta property="article:author" content="知行">
- <meta property="article:tag" content="Linux">
- <meta name="twitter:card" content="summary">
- <link rel="canonical" href="https://blog.izhixing.icu/posts/c62f803c.html">
- <script class="page-configurations">
- // https://hexo.io/docs/variables.html
- CONFIG.page = {
- sidebar: "",
- isHome : false,
- isPost : true,
- lang : 'zh-CN'
- };
- </script>
- <title>Linux操作指南:02-配置防火墙端口 | 知行</title>
-
- <script async src="https://www.googletagmanager.com/gtag/js?id=UA-135887327-1"></script>
- <script>
- if (CONFIG.hostname === location.hostname) {
- window.dataLayer = window.dataLayer || [];
- function gtag(){dataLayer.push(arguments);}
- gtag('js', new Date());
- gtag('config', 'UA-135887327-1');
- }
- </script>
- <noscript>
- <style>
- body { margin-top: 2rem; }
- .use-motion .menu-item,
- .use-motion .sidebar,
- .use-motion .post-block,
- .use-motion .pagination,
- .use-motion .comments,
- .use-motion .post-header,
- .use-motion .post-body,
- .use-motion .collection-header {
- visibility: visible;
- }
- .use-motion .header,
- .use-motion .site-brand-container .toggle,
- .use-motion .footer { opacity: initial; }
- .use-motion .site-title,
- .use-motion .site-subtitle,
- .use-motion .custom-logo-image {
- opacity: initial;
- top: initial;
- }
- .use-motion .logo-line {
- transform: scaleX(1);
- }
- .search-pop-overlay, .sidebar-nav { display: none; }
- .sidebar-panel { display: block; }
- </style>
- </noscript>
- </head>
- <body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
- <div class="headband"></div>
- <main class="main">
- <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="切换导航栏" role="button">
- <span class="toggle-line"></span>
- <span class="toggle-line"></span>
- <span class="toggle-line"></span>
- </div>
- </div>
- <div class="site-meta">
- <a href="/" class="brand" rel="start">
- <i class="logo-line"></i>
- <h1 class="site-title">知行</h1>
- <i class="logo-line"></i>
- </a>
- </div>
- <div class="site-nav-right">
- <div class="toggle popup-trigger">
- <i class="fa fa-search fa-fw fa-lg"></i>
- </div>
- </div>
- </div>
- <nav class="site-nav">
- <ul class="main-menu menu">
- <li class="menu-item menu-item-home"><a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a></li>
- <li class="menu-item menu-item-tags"><a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a></li>
- <li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a></li>
- <li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="fa fa-archive fa-fw"></i>归档</a></li>
- <li class="menu-item menu-item-sitemap"><a href="/sitemap.xml" rel="section"><i class="fa fa-sitemap fa-fw"></i>站点地图</a></li>
- <li class="menu-item menu-item-search">
- <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
- </a>
- </li>
- </ul>
- </nav>
- <div class="search-pop-overlay">
- <div class="popup search-popup"><div class="search-header">
- <span class="search-icon">
- <i class="fa fa-search"></i>
- </span>
- <div class="search-input-container">
- <input autocomplete="off" autocapitalize="off" maxlength="80"
- placeholder="搜索..." spellcheck="false"
- type="search" class="search-input">
- </div>
- <span class="popup-btn-close" role="button">
- <i class="fa fa-times-circle"></i>
- </span>
- </div>
- <div class="search-result-container no-result">
- <div class="search-result-icon">
- <i class="fa fa-spinner fa-pulse fa-5x"></i>
- </div>
- </div>
- </div>
- </div>
- </div>
-
-
- <div class="toggle sidebar-toggle" role="button">
- <span class="toggle-line"></span>
- <span class="toggle-line"></span>
- <span class="toggle-line"></span>
- </div>
- <aside class="sidebar">
- <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
- <ul class="sidebar-nav">
- <li class="sidebar-nav-toc">
- 文章目录
- </li>
- <li class="sidebar-nav-overview">
- 站点概览
- </li>
- </ul>
- <div class="sidebar-panel-container">
- <!--noindex-->
- <div class="post-toc-wrap sidebar-panel">
- <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#%E7%8E%AF%E5%A2%83"><span class="nav-number">1.</span> <span class="nav-text">环境</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#firewall-cmd%E4%B8%8Eiptables"><span class="nav-number">2.</span> <span class="nav-text">firewall-cmd与iptables</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E7%AB%AF%E5%8F%A3%E5%BC%80%E5%8F%91%E7%9A%84%E4%B8%A4%E7%A7%8D%E6%96%B9%E5%BC%8F"><span class="nav-number">3.</span> <span class="nav-text">端口开发的两种方式</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#permanent%E5%8F%82%E6%95%B0%E5%92%8Czone%E5%8F%82%E6%95%B0"><span class="nav-number">4.</span> <span class="nav-text">permanent参数和zone参数</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#firewall-cmd%E5%B8%B8%E7%94%A8%E5%91%BD%E4%BB%A4"><span class="nav-number">5.</span> <span class="nav-text">firewall-cmd常用命令</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#%E6%80%BB%E7%BB%93"><span class="nav-number">6.</span> <span class="nav-text">总结</span></a></li></ol></div>
- </div>
- <!--/noindex-->
- <div class="site-overview-wrap sidebar-panel">
- <div class="site-author site-overview-item animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
- <img class="site-author-image" itemprop="image" alt="知行"
- src="/images/apple-touch-icon.png">
- <p class="site-author-name" itemprop="name">知行</p>
- <div class="site-description" itemprop="description">韭零后一枚,技术菜鸟,喜欢做白日梦,热爱修仙,任职于一小公司里撸代码。</div>
- </div>
- <div class="site-state-wrap site-overview-item animated">
- <nav class="site-state">
- <div class="site-state-item site-state-posts">
- <a href="/archives/">
-
- <span class="site-state-item-count">45</span>
- <span class="site-state-item-name">日志</span>
- </a>
- </div>
- <div class="site-state-item site-state-categories">
- <a href="/categories/">
-
- <span class="site-state-item-count">29</span>
- <span class="site-state-item-name">分类</span></a>
- </div>
- <div class="site-state-item site-state-tags">
- <a href="/tags/">
-
- <span class="site-state-item-count">27</span>
- <span class="site-state-item-name">标签</span></a>
- </div>
- </nav>
- </div>
- <div class="links-of-author site-overview-item animated">
- <span class="links-of-author-item">
- <a href="https://github.com/izhixing" title="GitHub → https://github.com/izhixing" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
- </span>
- <span class="links-of-author-item">
- <a href="mailto:3137650480@qq.com" title="E-Mail → mailto:3137650480@qq.com" rel="noopener" target="_blank"><i class="fa fa-envelope fa-fw"></i>E-Mail</a>
- </span>
- </div>
- </div>
- </div>
- </div>
- </aside>
- <div class="sidebar-dimmer"></div>
- </header>
-
- <div class="back-to-top" role="button">
- <i class="fa fa-arrow-up"></i>
- <span>0%</span>
- </div>
- <a href="https://github.com/izhixing" 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>
- <noscript>
- <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
- </noscript>
- <div class="main-inner post posts-expand">
-
- <div class="post-block">
-
-
- <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
- <link itemprop="mainEntityOfPage" href="https://blog.izhixing.icu/posts/c62f803c.html">
- <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
- <meta itemprop="image" content="/images/apple-touch-icon.png">
- <meta itemprop="name" content="知行">
- <meta itemprop="description" content="韭零后一枚,技术菜鸟,喜欢做白日梦,热爱修仙,任职于一小公司里撸代码。">
- </span>
- <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
- <meta itemprop="name" content="知行">
- </span>
- <header class="post-header">
- <h1 class="post-title" itemprop="name headline">
- Linux操作指南:02-配置防火墙端口
- </h1>
- <div class="post-meta-container">
- <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">发表于</span>
- <time title="创建时间:2021-03-27 21:10:14" itemprop="dateCreated datePublished" datetime="2021-03-27T21:10:14+08:00">2021-03-27</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">更新于</span>
- <time title="修改时间:2021-04-06 22:39:44" itemprop="dateModified" datetime="2021-04-06T22:39:44+08:00">2021-04-06</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">分类于</span>
- <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
- <a href="/categories/Linux/" itemprop="url" rel="index"><span itemprop="name">Linux</span></a>
- </span>
- </span>
-
- <span id="/posts/c62f803c.html" class="post-meta-item leancloud_visitors" data-flag-title="Linux操作指南:02-配置防火墙端口" title="阅读次数">
- <span class="post-meta-item-icon">
- <i class="far fa-eye"></i>
- </span>
- <span class="post-meta-item-text">阅读次数:</span>
- <span class="leancloud-visitors-count"></span>
- </span>
- </div>
- </div>
- </header>
-
-
-
- <div class="post-body" itemprop="articleBody">
- <p>新装的Linux系统,ssh、nginx、tomcat等各种服务都安装好了,可是在外网却访问不了??这十有八九是防火墙的端口没有打开了。</p>
- <span id="more"></span>
- <h1 id="环境"><a href="#环境" class="headerlink" title="环境"></a>环境</h1><p>系统:CentOS 7</p>
- <h1 id="firewall-cmd与iptables"><a href="#firewall-cmd与iptables" class="headerlink" title="firewall-cmd与iptables"></a>firewall-cmd与iptables</h1><p>到了CentOS 7,防火墙的操作命令由<em>iptables</em>改为了<em>firewall-cmd</em>了。以下是摘抄自<a target="_blank" rel="noopener" href="https://wangchujiang.com/linux-command/c/firewall-cmd.html">他人</a>的解释:</p>
- <blockquote>
- <p>firewall-cmd 是 firewalld的字符界面管理工具,firewalld是centos7的一大特性,最大的好处有两个:支持动态更新,不用重启服务;第二个就是加入了防火墙的“zone”概念。</p>
- <p>firewalld跟iptables比起来至少有两大好处:</p>
- <ol>
- <li>firewalld可以动态修改单条规则,而不需要像iptables那样,在修改了规则后必须得全部刷新才可以生效。</li>
- <li>firewalld在使用上要比iptables人性化很多,即使不明白“五张表五条链”而且对TCP/IP协议也不理解也可以实现大部分功能。</li>
- </ol>
- <p>firewalld自身并不具备防火墙的功能,而是和iptables一样需要通过内核的netfilter来实现,也就是说firewalld和 iptables一样,他们的作用都是用于维护规则,而真正使用规则干活的是内核的netfilter,只不过firewalld和iptables的结 构以及使用方法不一样罢了。</p>
- </blockquote>
- <p>总的来说这次变更带来的直观好处就是变的更方便更好用了。</p>
- <h1 id="端口开发的两种方式"><a href="#端口开发的两种方式" class="headerlink" title="端口开发的两种方式"></a>端口开发的两种方式</h1><p>开放端口有两种方式:指定端口和指定服务。</p>
- <p>指定端口很好理解,就是写上那个端口号就开放那个端口。</p>
- <p>指定服务可以理解为内置的一个端口映射,默认情况下:ssh服务端口是22、http服务端口是80、MySQL服务端口是3306、tomcat服务端口是8080,因此用服务名来代替直接指定端口,方便记忆和使用。</p>
- <p><strong>要注意的是:通过指定服务名开放的就要通过指定服务名关闭;通过指定端口号开放的就要通过指定端口号关闭,且指定端口的时候一定要指定是什么协议,tcp 还是 udp。</strong></p>
- <h1 id="permanent参数和zone参数"><a href="#permanent参数和zone参数" class="headerlink" title="permanent参数和zone参数"></a>permanent参数和zone参数</h1><p>配置端口的时候这两个参数是会经常使用到的。</p>
- <figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">firewall-cmd --permanent</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></pre></td><td class="code"><pre><span class="line">firewall-cmd --zone=public</span><br></pre></td></tr></table></figure>
- <p><strong>zone</strong>参数就难以理解一点,这个参数的作用是指定一套规则集合,依靠这些规则来判断是否放行数据。这里使用的规则集是<strong>public</strong>,即只放行已配置的服务(端口)。</p>
- <p>更详细的可以参考:<a target="_blank" rel="noopener" href="http://www.excelib.com/article/287/show/#g5vTC3">Firewalld的结构</a>,<a target="_blank" rel="noopener" href="https://www.cnblogs.com/excelib/p/5155951.html">用活Firewalld防火墙中的zone</a></p>
- <h1 id="firewall-cmd常用命令"><a href="#firewall-cmd常用命令" class="headerlink" title="firewall-cmd常用命令"></a>firewall-cmd常用命令</h1><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></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> 指定端口</span></span><br><span class="line">firewall-cmd --zone=public --add-port=80/tcp --permanent</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash"> 指定服务</span></span><br><span class="line">firewall-cmd --add-service=http --permanent</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></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash"> 指定端口</span></span><br><span class="line">firewall-cmd --permanent --remove-port=80/tcp</span><br><span class="line"></span><br><span class="line"><span class="meta">#</span><span class="bash"> 指定服务</span></span><br><span class="line">firewall-cmd --permanent --remove-service=http</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></pre></td><td class="code"><pre><span class="line">firewall-cmd --state</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></pre></td><td class="code"><pre><span class="line">firewall-cmd --list-ports</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></pre></td><td class="code"><pre><span class="line">firewall-cmd --list-service</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></pre></td><td class="code"><pre><span class="line">firewall-cmd --list-all</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></pre></td><td class="code"><pre><span class="line">firewall-cmd --reload</span><br></pre></td></tr></table></figure>
- <h1 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h1><p>这里只是列举了自己常用的一些命令,更具体的可以参考以下文章</p>
- <ul>
- <li><p><a target="_blank" rel="noopener" href="https://wangchujiang.com/linux-command/c/firewall-cmd.html">firewall-cmd详解</a></p>
- </li>
- <li><p><a target="_blank" rel="noopener" href="http://www.excelib.com/article/287/show/#g5vTC3">Firewalld的结构</a></p>
- </li>
- <li><p><a target="_blank" rel="noopener" href="https://www.cnblogs.com/excelib/p/5155951.html">用活Firewalld防火墙中的zone</a></p>
- </li>
- </ul>
- </div>
-
-
-
- <footer class="post-footer">
- <div class="post-tags">
- <a href="/tags/Linux/" rel="tag"># Linux</a>
- </div>
-
- <div class="post-nav">
- <div class="post-nav-item">
- <a href="/posts/bdb89eee.html" rel="prev" title="Gogs配置为服务开机自启动">
- <i class="fa fa-chevron-left"></i> Gogs配置为服务开机自启动
- </a>
- </div>
- <div class="post-nav-item">
- <a href="/posts/ef0b8374.html" rel="next" title="Linux配置IPV6地址">
- Linux配置IPV6地址 <i class="fa fa-chevron-right"></i>
- </a>
- </div>
- </div>
- </footer>
- </article>
- </div>
- <div class="comments gitalk-container"></div>
- <script>
- window.addEventListener('tabs:register', () => {
- let { activeClass } = CONFIG.comments;
- if (CONFIG.comments.storage) {
- activeClass = localStorage.getItem('comments_active') || activeClass;
- }
- if (activeClass) {
- const 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;
- const commentClass = event.target.classList[1];
- localStorage.setItem('comments_active', commentClass);
- });
- }
- </script>
- </div>
- </main>
- <footer class="footer">
- <div class="footer-inner">
- <div class="copyright">
- © 2018 –
- <span itemprop="copyrightYear">2021</span>
- <span class="with-love">
- <i class="fa fa-heart"></i>
- </span>
- <span class="author" itemprop="copyrightHolder">知行</span>
- </div>
- <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.js.org/" class="theme-link" rel="noopener" target="_blank">NexT.Gemini</a> 强力驱动
- </div>
- </div>
- </footer>
-
- <script src="https://cdn.jsdelivr.net/npm/animejs@3.2.1/lib/anime.min.js"></script>
- <script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script>
-
- <script src="/js/local-search.js"></script>
-
- <script>
- (function() {
- function leancloudSelector(url) {
- url = encodeURI(url);
- return document.getElementById(url).querySelector('.leancloud-visitors-count');
- }
- function addCount(Counter) {
- const visitors = document.querySelector('.leancloud_visitors');
- const url = decodeURI(visitors.id);
- const title = visitors.dataset.flagTitle;
- Counter('get', '/classes/Counter?where=' + encodeURIComponent(JSON.stringify({ url })))
- .then(response => response.json())
- .then(({ results }) => {
- if (results.length > 0) {
- const 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) {
- const visitors = document.querySelectorAll('.leancloud_visitors');
- const 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) {
- const target = results.find(item => item.url === url);
- leancloudSelector(url).innerText = target ? target.time : 0;
- }
- })
- .catch(error => {
- console.error('LeanCloud Counter Error', error);
- });
- }
- const { app_id, app_key, server_url } = {"enable":true,"app_id":"EVuNVQdwjVVETLVOGGdClySN-gzGzoHsz","app_key":"UBIufuTIEV1gHcdJIx6IOmyN","server_url":null,"security":true};
- function fetchData(api_server) {
- const 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);
- }
- }
- const api_server = app_id.slice(-9) === '-MdYXbMMI' ? `https://${app_id.slice(0, 8).toLowerCase()}.api.lncldglobal.com` : server_url;
- 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>
-
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/gitalk@1.7.0/dist/gitalk.css">
- <script>
- NexT.utils.loadComments('.gitalk-container', () => {
- NexT.utils.getScript('https://cdn.jsdelivr.net/npm/gitalk@1.7.0/dist/gitalk.min.js', () => {
- var gitalk = new Gitalk({
- clientID : '37644037ac52d12cdd8a',
- clientSecret: '09993925bc5a09337e2d13cc1225761ca099d39b',
- repo : 'izhixing.github.io',
- owner : 'izhixing',
- admin : ['izhixing'],
- id : '373545c72eaa426e2ef886294ab9a96f',
- proxy : 'https://cors-anywhere.herokuapp.com/https://github.com/login/oauth/access_token',
- language: '',
- distractionFreeMode: true
- });
- gitalk.render(document.querySelector('.gitalk-container'));
- }, window.Gitalk);
- });
- </script>
- </body>
- </html>
|