Skip to content

Commit

Permalink
Site updated: 2024-10-22 16:09:34
Browse files Browse the repository at this point in the history
  • Loading branch information
sam committed Oct 22, 2024
1 parent d6d84ce commit 0d3d6ca
Show file tree
Hide file tree
Showing 8 changed files with 188 additions and 176 deletions.
13 changes: 9 additions & 4 deletions 2016/11/18/web server/serverInit/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<meta property="og:description" content="主要内容 环境准备 用户管理 sshd管理 防暴力破解 主要以 Centos 7 为主。 更新历史 2017-8-29 增加 SELinux 内容 2020-3-30 add time synchronize ……">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2016-11-18T11:29:44.000Z">
<meta property="article:modified_time" content="2022-12-08T03:19:48.000Z">
<meta property="article:modified_time" content="2024-10-22T07:54:09.010Z">
<meta property="article:author" content="sam chen">
<meta property="article:tag" content="linux">
<meta property="article:tag" content="server">
Expand Down Expand Up @@ -233,7 +233,7 @@ <h1 class="post-title" itemprop="name headline">
<i class="far fa-calendar-check"></i>
</span>
<span class="post-meta-item-text">更新于</span>
<time title="修改时间:2022-12-08 11:19:48" itemprop="dateModified" datetime="2022-12-08T11:19:48+08:00">2022-12-08</time>
<time title="修改时间:2024-10-22 15:54:09" itemprop="dateModified" datetime="2024-10-22T15:54:09+08:00">2024-10-22</time>
</span>
<span class="post-meta-item">
<span class="post-meta-item-icon">
Expand Down Expand Up @@ -301,8 +301,13 @@ <h3 id="zsh"><a href="#zsh" class="headerlink" title="zsh"></a>zsh</h3><figure c

<h3 id="oh-my-zsh"><a href="#oh-my-zsh" class="headerlink" title="oh-my-zsh"></a>oh-my-zsh</h3><figure class="highlight plaintext"><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">sh -c &quot;$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)&quot;</span><br><span class="line"> </span><br><span class="line">#修改主题,非必须</span><br><span class="line">vim ~/.zshrc</span><br><span class="line">ZSH_THEME=&quot;bira&quot;</span><br><span class="line"></span><br><span class="line">#插件</span><br><span class="line">plugins=(git git-flow git-flow-completion )</span><br></pre></td></tr></table></figure>

<h3 id="服务器时间同步"><a href="#服务器时间同步" class="headerlink" title="服务器时间同步"></a>服务器时间同步</h3><figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">echo</span> <span class="string">&quot;*/20 * * * * root /usr/sbin/ntpdate pool.ntp.org&quot;</span> | sudo <span class="built_in">tee</span> -a /etc/crontab &gt; /dev/null</span><br></pre></td></tr></table></figure>

<h3 id="服务器时间同步"><a href="#服务器时间同步" class="headerlink" title="服务器时间同步"></a>服务器时间同步</h3><ul>
<li><p>CentOS 9</p>
<figure class="highlight sh"><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></pre></td><td class="code"><pre><span class="line"><span class="comment">#----------- CentOS 9 时间同步要使用chrony命令 , ntp命令没有了</span></span><br><span class="line">systemctl status chronyd</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="comment"># 增加 public servers</span></span><br><span class="line">vim /etc/chrony.conf</span><br><span class="line"><span class="comment"># public servers</span></span><br><span class="line">pool ntp1.aliyun.com iburst</span><br><span class="line">pool ntp2.aliyun.com iburst</span><br><span class="line">pool ntp3.aliyun.com iburst</span><br><span class="line"></span><br><span class="line"><span class="comment"># 重启生效</span></span><br><span class="line">systemctl restart chronyd</span><br><span class="line"></span><br><span class="line"><span class="comment"># 查看时区</span></span><br><span class="line">timedatectl</span><br><span class="line"><span class="comment"># 修改时区</span></span><br><span class="line">timedatectl set-timezone Asia/Shanghai</span><br></pre></td></tr></table></figure>
</li>
<li><p>CentOS 9之前</p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">echo</span> <span class="string">&quot;*/20 * * * * root /usr/sbin/ntpdate pool.ntp.org&quot;</span> | sudo <span class="built_in">tee</span> -a /etc/crontab &gt; /dev/null</span><br></pre></td></tr></table></figure></li>
</ul>
<h2 id="用户管理"><a href="#用户管理" class="headerlink" title="用户管理"></a>用户管理</h2><ul>
<li>增加一root组用户</li>
<li>禁止root登录</li>
Expand Down
9 changes: 5 additions & 4 deletions 2024/09/12/spring/springTransactions/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<meta property="og:description" content="主要内容 Spring transaction 事务传播机制大家都听说过,事务传播机制就是当一个事务方法被另一个事务方法调用时,事务是如何传递的。实际使用中,很容易出错,大家可提前学习下“Spring 事务失效7大场景”,本文重点讨论同一类方法相互调用的情景。 本文以 spring boot 3.2.3、Mysql 8 版本为实验环境说明。 更新历史无">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2024-09-12T12:57:07.000Z">
<meta property="article:modified_time" content="2024-09-12T08:27:04.740Z">
<meta property="article:modified_time" content="2024-09-12T08:35:40.108Z">
<meta property="article:author" content="sam chen">
<meta property="article:tag" content="spring">
<meta property="article:tag" content="spring boot">
Expand Down Expand Up @@ -228,7 +228,7 @@ <h1 class="post-title" itemprop="name headline">
<span class="post-meta-item-text">发表于</span>


<time title="创建时间:2024-09-12 20:57:07 / 修改时间:16:27:04" itemprop="dateCreated datePublished" datetime="2024-09-12T20:57:07+08:00">2024-09-12</time>
<time title="创建时间:2024-09-12 20:57:07 / 修改时间:16:35:40" itemprop="dateCreated datePublished" datetime="2024-09-12T20:57:07+08:00">2024-09-12</time>
</span>
<span class="post-meta-item">
<span class="post-meta-item-icon">
Expand Down Expand Up @@ -256,7 +256,8 @@ <h1 class="post-title" itemprop="name headline">
<hr>
<span id="more"></span>

<p>mysql 事务隔离级别为可重复读(Repeatable Read), 数据库中有一User 表,现存36条数据(至于为什么是36,大概是天罡数),主要字段为id(主键)、type; 初始状态id&#x3D;1的数据type&#x3D;0。</p>


<h2 id="预备知识"><a href="#预备知识" class="headerlink" title="预备知识"></a>预备知识</h2><h3 id="MySQL四个事务隔离级别"><a href="#MySQL四个事务隔离级别" class="headerlink" title="MySQL四个事务隔离级别"></a>MySQL四个事务隔离级别</h3><ul>
<li>读未提交(Read Uncommitted)<br>特点:事务中的修改操作(INSERT、UPDATE、DELETE)立即生效,无需等待事务提交;事务读取数据时可以读取其他事务未提交的数据。<br>应用场景:对于一些对数据一致性要求不高的场景,读取未提交的数据,也被称之为脏读(Dirty Read)</li>
<li>读已提交(Read Committed)<br>特点:事务中的修改操作需要等待事务提交后才生效;事务读取数据时只能读取其他事务已提交的数据。<br>应用场景:适用于大部分常规业务场景,能够保证读取的数据具有较高的一致性。但不可重复读,因为同一事务的其他实例在该实例处理其间可能会有新的commit,所以同一select可能返回不同结果。他</li>
Expand Down Expand Up @@ -307,7 +308,7 @@ <h3 id="Spring-事务传播机制"><a href="#Spring-事务传播机制" class="h
<td align="left">表示当前方法已经存在一个事务,那么该方法将会在嵌套事务中运行,嵌套的事务可以独立与当前事务进行单独地提交或者回滚,如果当前事务不存在,那么其行为与Propagation_Required一样。</td>
</tr>
</tbody></table>
<h2 id="实验场景"><a href="#实验场景" class="headerlink" title="实验场景"></a>实验场景</h2><p>实验时分为this对象调用和Spring Context对象调用2种,Spring transaction 事务主要是通过AOP实现的,因此这2种调用方式存在差异。</p>
<h2 id="实验场景"><a href="#实验场景" class="headerlink" title="实验场景"></a>实验场景</h2><p>实验时分为this对象调用和Spring Context对象调用2种,Spring transaction 事务主要是通过AOP实现的,因此这2种调用方式存在差异。<br>mysql 事务隔离级别为可重复读(Repeatable Read), 数据库中有一User 表,现存36条数据(至于为什么是36,大概是天罡数),主要字段为id(主键)、type; 初始状态id&#x3D;1的数据type&#x3D;0。</p>
<h3 id="this对象调用"><a href="#this对象调用" class="headerlink" title="this对象调用"></a>this对象调用</h3><h4 id="Propagation-REQUIRES-NEW"><a href="#Propagation-REQUIRES-NEW" class="headerlink" title="Propagation.REQUIRES_NEW"></a>Propagation.REQUIRES_NEW</h4><h5 id="代码"><a href="#代码" class="headerlink" title="代码"></a>代码</h5><figure class="highlight java"><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></pre></td><td class="code"><pre><span class="line"><span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 测试主入口</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"><span class="meta">@Test</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">transcationTest</span><span class="params">()</span> &#123;</span><br><span class="line"></span><br><span class="line"> <span class="keyword">try</span> &#123;</span><br><span class="line"> userService.testTransaction();</span><br><span class="line"> &#125; <span class="keyword">catch</span> (Exception e)&#123;</span><br><span class="line"> e.printStackTrace();</span><br><span class="line"> &#125;</span><br><span class="line"></span><br><span class="line"> userService.testTransaction4();</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight java"><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><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Service</span></span><br><span class="line"><span class="meta">@Transactional</span></span><br><span class="line"><span class="keyword">public</span> <span class="keyword">class</span> <span class="title class_">UrUserService</span> &#123;</span><br><span class="line"> <span class="comment">/**</span></span><br><span class="line"><span class="comment"> * 功能主入口</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">testTransaction</span><span class="params">()</span> &#123;</span><br><span class="line"> testTransaction1();</span><br><span class="line"><span class="comment">// SpringContext.getBean(UrUserService.class).testTransaction2();</span></span><br><span class="line"> testTransaction2();</span><br><span class="line"> testTransaction3();</span><br><span class="line"> &#125;</span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">testTransaction1</span><span class="params">()</span> &#123;</span><br><span class="line"> <span class="type">UrUserEntity</span> <span class="variable">user</span> <span class="operator">=</span> userRepository.getById(<span class="number">1l</span>);</span><br><span class="line"> user.setType(<span class="number">1</span>);</span><br><span class="line"> userRepository.save(user);</span><br><span class="line"> System.out.println(<span class="string">&quot;testTransaction111111111111 id=&quot;</span> + user.getId() + <span class="string">&quot; user type=&quot;</span> + user.getType() + <span class="string">&quot; count=&quot;</span> + userRepository.count() );</span><br><span class="line"> &#125;</span><br><span class="line"> <span class="meta">@Transactional(propagation = Propagation.REQUIRES_NEW)</span></span><br><span class="line"> <span class="comment">// @Transactional(propagation = Propagation.NESTED)</span></span><br><span class="line"><span class="comment">// @Transactional(propagation = Propagation.MANDATORY)</span></span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">testTransaction2</span><span class="params">()</span> &#123;</span><br><span class="line"> <span class="type">UrUserEntity</span> <span class="variable">user</span> <span class="operator">=</span> <span class="keyword">new</span> <span class="title class_">UrUserEntity</span>(<span class="literal">null</span>, <span class="string">&quot;us&quot;</span>, <span class="number">1</span>, <span class="string">&quot;realname&quot;</span>, <span class="literal">null</span>, <span class="string">&quot;199123&quot;</span>, <span class="literal">null</span>, <span class="string">&quot;hah&quot;</span>, <span class="literal">null</span>);</span><br><span class="line"> user.setType(<span class="number">2</span>);</span><br><span class="line"> save(user);</span><br><span class="line"></span><br><span class="line"> <span class="type">UrUserEntity</span> <span class="variable">user1</span> <span class="operator">=</span> userRepository.getReferenceById(<span class="number">1l</span>);</span><br><span class="line"> System.out.println(<span class="string">&quot;testTransaction22222222222222 REQUIRES_NEW id=&quot;</span> + user1.getId() + <span class="string">&quot; user type=&quot;</span> + user1.getType() + <span class="string">&quot; count=&quot;</span> + userRepository.count() );</span><br><span class="line"><span class="comment">// throw new RuntimeException(&quot;test2&quot;);</span></span><br><span class="line"> &#125;</span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">testTransaction3</span><span class="params">()</span> &#123;</span><br><span class="line"> <span class="type">UrUserEntity</span> <span class="variable">user1</span> <span class="operator">=</span> userRepository.getReferenceById(<span class="number">1l</span>);</span><br><span class="line"> System.out.println(<span class="string">&quot;testTransaction33333333333 id=&quot;</span> + user1.getId() + <span class="string">&quot; user type=&quot;</span> + user1.getType() + <span class="string">&quot; count=&quot;</span> + userRepository.count() );</span><br><span class="line"> <span class="keyword">throw</span> <span class="keyword">new</span> <span class="title class_">RuntimeException</span>(<span class="string">&quot;test3&quot;</span>);</span><br><span class="line"> &#125;</span><br><span class="line"> <span class="keyword">public</span> <span class="keyword">void</span> <span class="title function_">testTransaction4</span><span class="params">()</span> &#123;</span><br><span class="line"></span><br><span class="line"> <span class="type">UrUserEntity</span> <span class="variable">user1</span> <span class="operator">=</span> userRepository.getReferenceById(<span class="number">1l</span>);</span><br><span class="line"> System.out.println(<span class="string">&quot;testTransaction4444444444444 id=&quot;</span> + user1.getId() + <span class="string">&quot; user type=&quot;</span> + user1.getType() + <span class="string">&quot; count=&quot;</span> + userRepository.count() );</span><br><span class="line"> &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h5 id="Junit-Test-执行结果如下"><a href="#Junit-Test-执行结果如下" class="headerlink" title="Junit Test 执行结果如下"></a>Junit Test 执行结果如下</h5><figure class="highlight java"><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></pre></td><td class="code"><pre><span class="line">testTransaction111111111111 id=<span class="number">1</span> user type=<span class="number">1</span> count=<span class="number">36</span></span><br><span class="line">testTransaction22222222222222 REQUIRES_NEW id=<span class="number">1</span> user type=<span class="number">1</span> count=<span class="number">37</span></span><br><span class="line">testTransaction33333333333 id=<span class="number">1</span> user type=<span class="number">1</span> count=<span class="number">37</span></span><br><span class="line">java.lang.RuntimeException: test3</span><br><span class="line"> ......</span><br><span class="line">testTransaction4444444444444 id=<span class="number">1</span> user type=<span class="number">0</span> count=<span class="number">36</span></span><br></pre></td></tr></table></figure>
Expand Down
6 changes: 3 additions & 3 deletions atom.xml

Large diffs are not rendered by default.

Loading

0 comments on commit 0d3d6ca

Please sign in to comment.