<?xml version="1.0" encoding="utf-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><title>lonely blog</title><link>http://www.zajiben.cn/</link><description>珍爱生命  远离网络</description><item><title>linux设置ssh登录失败N次后封锁该IP工具fail2ban</title><link>http://www.zajiben.cn/post/572.html</link><description>&lt;p style=&quot;text-wrap: wrap;&quot;&gt;&lt;span style=&quot;color: #212529; font-family: TC, SC, &amp;quot;CJK FALLBACK&amp;quot;, sans-serif; font-size: 16px; letter-spacing: 1px; text-align: justify; background-color: #FFFFFF;&quot;&gt;Fail2ban是一款用来阻挡使用暴力破解法登录服务器的工具，最常被应用在SSH服务器上。它会去检查服务器的日志(Log)，并将登录失败的IP地址记录下来，如果该IP在一段时间内错了超过规定的次数，就会自动添加规则至防火墙中，阻挡该IP一段时间的连入。&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-wrap: wrap;&quot;&gt;&lt;br/&gt;&lt;/p&gt;&lt;h3 style=&quot;text-wrap: wrap; box-sizing: border-box; margin: 1.9rem 0px 1.3rem; font-weight: 500; line-height: 1.2; color: rgb(33, 37, 41); font-size: 1.75rem; font-family: TC, SC, &amp;quot;CJK FALLBACK&amp;quot;, sans-serif; letter-spacing: 1px; text-align: justify; background-color: rgb(255, 255, 255);&quot;&gt;安装 Fail2ban&lt;/h3&gt;&lt;p style=&quot;margin-top: 1.3rem; margin-bottom: 1.3rem; text-wrap: wrap; box-sizing: border-box; color: rgb(33, 37, 41); font-family: TC, SC, &amp;quot;CJK FALLBACK&amp;quot;, sans-serif; font-size: 16px; letter-spacing: 1px; text-align: justify; background-color: rgb(255, 255, 255);&quot;&gt;基于Debian的Linux发行版可以使用以下指令来安装Fail2ban：&lt;/p&gt;&lt;div class=&quot;blockquote&quot; style=&quot;text-wrap: wrap; box-sizing: border-box; margin-bottom: 1rem; font-size: 16px; border: 0.0625rem solid rgb(204, 204, 204); padding: 1.6rem; color: rgb(33, 37, 41); font-family: TC, SC, &amp;quot;CJK FALLBACK&amp;quot;, sans-serif; letter-spacing: 1px; text-align: justify; background-color: rgb(255, 255, 255);&quot;&gt;sudo apt install fail2ban&lt;/div&gt;&lt;p style=&quot;margin-top: 1.3rem; margin-bottom: 1.3rem; text-wrap: wrap; box-sizing: border-box; color: rgb(33, 37, 41); font-family: TC, SC, &amp;quot;CJK FALLBACK&amp;quot;, sans-serif; font-size: 16px; letter-spacing: 1px; text-align: justify; background-color: rgb(255, 255, 255);&quot;&gt;红帽系的Linux发行版可以使用以下指令来安装Fail2ban：&lt;/p&gt;&lt;div class=&quot;blockquote&quot; style=&quot;text-wrap: wrap; box-sizing: border-box; margin-bottom: 1rem; font-size: 16px; border: 0.0625rem solid rgb(204, 204, 204); padding: 1.6rem; color: rgb(33, 37, 41); font-family: TC, SC, &amp;quot;CJK FALLBACK&amp;quot;, sans-serif; letter-spacing: 1px; text-align: justify; background-color: rgb(255, 255, 255);&quot;&gt;sudo dnf install fail2ban&lt;/div&gt;&lt;p style=&quot;margin-top: 1.3rem; margin-bottom: 1.3rem; text-wrap: wrap; box-sizing: border-box; color: rgb(33, 37, 41); font-family: TC, SC, &amp;quot;CJK FALLBACK&amp;quot;, sans-serif; font-size: 16px; letter-spacing: 1px; text-align: justify; background-color: rgb(255, 255, 255);&quot;&gt;运行以下指令在开机时自动启动Fail2ban服务：&lt;/p&gt;&lt;div class=&quot;blockquote&quot; style=&quot;text-wrap: wrap; box-sizing: border-box; margin-bottom: 1rem; font-size: 16px; border: 0.0625rem solid rgb(204, 204, 204); padding: 1.6rem; color: rgb(33, 37, 41); font-family: TC, SC, &amp;quot;CJK FALLBACK&amp;quot;, sans-serif; letter-spacing: 1px; text-align: justify; background-color: rgb(255, 255, 255);&quot;&gt;sudo systemctl enable fail2ban&lt;/div&gt;&lt;p style=&quot;margin-top: 1.3rem; margin-bottom: 1.3rem; text-wrap: wrap; box-sizing: border-box; color: rgb(33, 37, 41); font-family: TC, SC, &amp;quot;CJK FALLBACK&amp;quot;, sans-serif; font-size: 16px; letter-spacing: 1px; text-align: justify; background-color: rgb(255, 255, 255);&quot;&gt;运行以下指令立刻启动Fail2ban服务：&lt;/p&gt;&lt;div class=&quot;blockquote&quot; style=&quot;text-wrap: wrap; box-sizing: border-box; margin-bottom: 1rem; font-size: 16px; border: 0.0625rem solid rgb(204, 204, 204); padding: 1.6rem; color: rgb(33, 37, 41); font-family: TC, SC, &amp;quot;CJK FALLBACK&amp;quot;, sans-serif; letter-spacing: 1px; text-align: justify; background-color: rgb(255, 255, 255);&quot;&gt;sudo fail2ban-client start&lt;/div&gt;&lt;h3 style=&quot;text-wrap: wrap; box-sizing: border-box; margin: 1.9rem 0px 1.3rem; font-weight: 500; line-height: 1.2; color: rgb(33, 37, 41); font-size: 1.75rem; font-family: TC, SC, &amp;quot;CJK FALLBACK&amp;quot;, sans-serif; letter-spacing: 1px; text-align: justify; background-color: rgb(255, 255, 255);&quot;&gt;设置 Fail2ban&lt;/h3&gt;&lt;p style=&quot;margin-top: 1.3rem; margin-bottom: 1.3rem; text-wrap: wrap; box-sizing: border-box; color: rgb(33, 37, 41); font-family: TC, SC, &amp;quot;CJK FALLBACK&amp;quot;, sans-serif; font-size: 16px; letter-spacing: 1px; text-align: justify; background-color: rgb(255, 255, 255);&quot;&gt;如果您是使用基于Debian的Linux发行版，安装完&lt;code style=&quot;box-sizing: border-box; font-size: 1em; color: rgb(191, 97, 106); overflow-wrap: break-word; background-color: rgb(249, 249, 249); border-radius: 3px; padding: 0.1rem 0.5rem; font-family: &amp;quot;CJK MONO&amp;quot;, monospace !important;&quot;&gt;fail2ban&lt;/code&gt;套件后就已经激活&lt;code style=&quot;box-sizing: border-box; font-size: 1em; color: rgb(191, 97, 106); overflow-wrap: break-word; background-color: rgb(249, 249, 249); border-radius: 3px; padding: 0.1rem 0.5rem; font-family: &amp;quot;CJK MONO&amp;quot;, monospace !important;&quot;&gt;sshd&lt;/code&gt;的保护功能了。但还是可以参考这小节的说明来作设置。&lt;/p&gt;&lt;p style=&quot;margin-top: 1.3rem; margin-bottom: 1.3rem; text-wrap: wrap; box-sizing: border-box; color: rgb(33, 37, 41); font-family: TC, SC, &amp;quot;CJK FALLBACK&amp;quot;, sans-serif; font-size: 16px; letter-spacing: 1px; text-align: justify; background-color: rgb(255, 255, 255);&quot;&gt;Fail2ban的设置档位于&lt;code style=&quot;box-sizing: border-box; font-size: 1em; color: rgb(191, 97, 106); overflow-wrap: break-word; background-color: rgb(249, 249, 249); border-radius: 3px; padding: 0.1rem 0.5rem; font-family: &amp;quot;CJK MONO&amp;quot;, monospace !important;&quot;&gt;/etc/fail2ban&lt;/code&gt;目录，设置档支持的扩展名为&lt;code style=&quot;box-sizing: border-box; font-size: 1em; color: rgb(191, 97, 106); overflow-wrap: break-word; background-color: rgb(249, 249, 249); border-radius: 3px; padding: 0.1rem 0.5rem; font-family: &amp;quot;CJK MONO&amp;quot;, monospace !important;&quot;&gt;.conf&lt;/code&gt;和&lt;code style=&quot;box-sizing: border-box; font-size: 1em; color: rgb(191, 97, 106); overflow-wrap: break-word; background-color: rgb(249, 249, 249); border-radius: 3px; padding: 0.1rem 0.5rem; font-family: &amp;quot;CJK MONO&amp;quot;, monospace !important;&quot;&gt;.local&lt;/code&gt;。扩展名&lt;code style=&quot;box-sizing: border-box; font-size: 1em; color: rgb(191, 97, 106); overflow-wrap: break-word; background-color: rgb(249, 249, 249); border-radius: 3px; padding: 0.1rem 0.5rem; font-family: &amp;quot;CJK MONO&amp;quot;, monospace !important;&quot;&gt;.conf&lt;/code&gt;是缺省的设置档，扩展名&lt;code style=&quot;box-sizing: border-box; font-size: 1em; color: rgb(191, 97, 106); overflow-wrap: break-word; background-color: rgb(249, 249, 249); border-radius: 3px; padding: 0.1rem 0.5rem; font-family: &amp;quot;CJK MONO&amp;quot;, monospace !important;&quot;&gt;.local&lt;/code&gt;是我们要修改设置值时要自行添加的设置档。撰写在&lt;code style=&quot;box-sizing: border-box; font-size: 1em; color: rgb(191, 97, 106); overflow-wrap: break-word; background-color: rgb(249, 249, 249); border-radius: 3px; padding: 0.1rem 0.5rem; font-family: &amp;quot;CJK MONO&amp;quot;, monospace !important;&quot;&gt;.local&lt;/code&gt;设置档的设置会覆写掉&lt;code style=&quot;box-sizing: border-box; font-size: 1em; color: rgb(191, 97, 106); overflow-wrap: break-word; background-color: rgb(249, 249, 249); border-radius: 3px; padding: 0.1rem 0.5rem; font-family: &amp;quot;CJK MONO&amp;quot;, monospace !important;&quot;&gt;.conf&lt;/code&gt;设置档内原先的设置。&lt;/p&gt;&lt;p style=&quot;margin-top: 1.3rem; margin-bottom: 1.3rem; text-wrap: wrap; box-sizing: border-box; color: rgb(33, 37, 41); font-family: TC, SC, &amp;quot;CJK FALLBACK&amp;quot;, sans-serif; font-size: 16px; letter-spacing: 1px; text-align: justify; background-color: rgb(255, 255, 255);&quot;&gt;要设置&lt;code style=&quot;box-sizing: border-box; font-size: 1em; color: rgb(191, 97, 106); overflow-wrap: break-word; background-color: rgb(249, 249, 249); border-radius: 3px; padding: 0.1rem 0.5rem; font-family: &amp;quot;CJK MONO&amp;quot;, monospace !important;&quot;&gt;sshd&lt;/code&gt;的保护，可以添加一个文件，路径为&lt;code style=&quot;box-sizing: border-box; font-size: 1em; color: rgb(191, 97, 106); overflow-wrap: break-word; background-color: rgb(249, 249, 249); border-radius: 3px; padding: 0.1rem 0.5rem; font-family: &amp;quot;CJK MONO&amp;quot;, monospace !important;&quot;&gt;/etc/fail2ban/jail.d/sshd.local&lt;/code&gt;，文件内容如下：&lt;/p&gt;&lt;pre class=&quot;plaintext hljs language-plaintext&quot; data-highlighted=&quot;yes&quot; style=&quot;margin-top: 0px; margin-bottom: 1rem; padding: 0.5rem; letter-spacing: 0px; box-sizing: border-box; font-size: 16px; overflow: auto; color: rgb(36, 41, 46); tab-size: 4; text-align: justify; font-family: &amp;quot;CJK MONO&amp;quot;, monospace !important;&quot;&gt;&lt;table class=&quot;hljs-ln&quot; width=&quot;840&quot;&gt;&lt;tbody style=&quot;box-sizing: border-box; border-style: solid; border-width: 0px;&quot;&gt;&lt;tr class=&quot;firstRow&quot; style=&quot;box-sizing: border-box; border-style: solid; border-width: 0px;&quot;&gt;&lt;td class=&quot;hljs-ln-line hljs-ln-numbers&quot; data-line-number=&quot;1&quot; style=&quot;padding: 0px 5px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-top-color: inherit; border-right-color: rgb(204, 204, 204); border-bottom-color: inherit; border-left-color: inherit; box-sizing: border-box; color: rgb(204, 204, 204); text-align: center; vertical-align: top;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;hljs-ln-line hljs-ln-code&quot; data-line-number=&quot;1&quot; width=&quot;813&quot; style=&quot;padding-top: 0px; padding-right: 0px; padding-bottom: 0px; border-width: 0px; border-color: inherit; box-sizing: border-box;&quot;&gt;[sshd]&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;box-sizing: border-box; border-style: solid; border-width: 0px;&quot;&gt;&lt;td class=&quot;hljs-ln-line hljs-ln-numbers&quot; data-line-number=&quot;2&quot; style=&quot;padding: 0px 5px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-top-color: inherit; border-right-color: rgb(204, 204, 204); border-bottom-color: inherit; border-left-color: inherit; box-sizing: border-box; color: rgb(204, 204, 204); text-align: center; vertical-align: top;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;hljs-ln-line hljs-ln-code&quot; data-line-number=&quot;2&quot; width=&quot;813&quot; style=&quot;padding-top: 0px; padding-right: 0px; padding-bottom: 0px; border-width: 0px; border-color: inherit; box-sizing: border-box;&quot;&gt;enabled = true&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;box-sizing: border-box; border-style: solid; border-width: 0px;&quot;&gt;&lt;td class=&quot;hljs-ln-line hljs-ln-numbers&quot; data-line-number=&quot;3&quot; style=&quot;padding: 0px 5px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-top-color: inherit; border-right-color: rgb(204, 204, 204); border-bottom-color: inherit; border-left-color: inherit; box-sizing: border-box; color: rgb(204, 204, 204); text-align: center; vertical-align: top;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;hljs-ln-line hljs-ln-code&quot; data-line-number=&quot;3&quot; width=&quot;813&quot; style=&quot;padding-top: 0px; padding-right: 0px; padding-bottom: 0px; border-width: 0px; border-color: inherit; box-sizing: border-box;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;box-sizing: border-box; border-style: solid; border-width: 0px;&quot;&gt;&lt;td class=&quot;hljs-ln-line hljs-ln-numbers&quot; data-line-number=&quot;4&quot; style=&quot;padding: 0px 5px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-top-color: inherit; border-right-color: rgb(204, 204, 204); border-bottom-color: inherit; border-left-color: inherit; box-sizing: border-box; color: rgb(204, 204, 204); text-align: center; vertical-align: top;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;hljs-ln-line hljs-ln-code&quot; data-line-number=&quot;4&quot; width=&quot;813&quot; style=&quot;padding-top: 0px; padding-right: 0px; padding-bottom: 0px; border-width: 0px; border-color: inherit; box-sizing: border-box;&quot;&gt;bantime = 10m&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;box-sizing: border-box; border-style: solid; border-width: 0px;&quot;&gt;&lt;td class=&quot;hljs-ln-line hljs-ln-numbers&quot; data-line-number=&quot;5&quot; style=&quot;padding: 0px 5px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-top-color: inherit; border-right-color: rgb(204, 204, 204); border-bottom-color: inherit; border-left-color: inherit; box-sizing: border-box; color: rgb(204, 204, 204); text-align: center; vertical-align: top;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;hljs-ln-line hljs-ln-code&quot; data-line-number=&quot;5&quot; width=&quot;813&quot; style=&quot;padding-top: 0px; padding-right: 0px; padding-bottom: 0px; border-width: 0px; border-color: inherit; box-sizing: border-box;&quot;&gt;bantime.increment = true&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;box-sizing: border-box; border-style: solid; border-width: 0px;&quot;&gt;&lt;td class=&quot;hljs-ln-line hljs-ln-numbers&quot; data-line-number=&quot;6&quot; style=&quot;padding: 0px 5px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-top-color: inherit; border-right-color: rgb(204, 204, 204); border-bottom-color: inherit; border-left-color: inherit; box-sizing: border-box; color: rgb(204, 204, 204); text-align: center; vertical-align: top;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;hljs-ln-line hljs-ln-code&quot; data-line-number=&quot;6&quot; width=&quot;813&quot; style=&quot;padding-top: 0px; padding-right: 0px; padding-bottom: 0px; border-width: 0px; border-color: inherit; box-sizing: border-box;&quot;&gt;bantime.maxtime = 1d&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;box-sizing: border-box; border-style: solid; border-width: 0px;&quot;&gt;&lt;td class=&quot;hljs-ln-line hljs-ln-numbers&quot; data-line-number=&quot;7&quot; style=&quot;padding: 0px 5px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-top-color: inherit; border-right-color: rgb(204, 204, 204); border-bottom-color: inherit; border-left-color: inherit; box-sizing: border-box; color: rgb(204, 204, 204); text-align: center; vertical-align: top;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;hljs-ln-line hljs-ln-code&quot; data-line-number=&quot;7&quot; width=&quot;813&quot; style=&quot;padding-top: 0px; padding-right: 0px; padding-bottom: 0px; border-width: 0px; border-color: inherit; box-sizing: border-box;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;box-sizing: border-box; border-style: solid; border-width: 0px;&quot;&gt;&lt;td class=&quot;hljs-ln-line hljs-ln-numbers&quot; data-line-number=&quot;8&quot; style=&quot;padding: 0px 5px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-top-color: inherit; border-right-color: rgb(204, 204, 204); border-bottom-color: inherit; border-left-color: inherit; box-sizing: border-box; color: rgb(204, 204, 204); text-align: center; vertical-align: top;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;hljs-ln-line hljs-ln-code&quot; data-line-number=&quot;8&quot; width=&quot;813&quot; style=&quot;padding-top: 0px; padding-right: 0px; padding-bottom: 0px; border-width: 0px; border-color: inherit; box-sizing: border-box;&quot;&gt;findtime = 10m&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;box-sizing: border-box; border-style: solid; border-width: 0px;&quot;&gt;&lt;td class=&quot;hljs-ln-line hljs-ln-numbers&quot; data-line-number=&quot;9&quot; style=&quot;padding: 0px 5px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-top-color: inherit; border-right-color: rgb(204, 204, 204); border-bottom-color: inherit; border-left-color: inherit; box-sizing: border-box; color: rgb(204, 204, 204); text-align: center; vertical-align: top;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;hljs-ln-line hljs-ln-code&quot; data-line-number=&quot;9&quot; width=&quot;813&quot; style=&quot;padding-top: 0px; padding-right: 0px; padding-bottom: 0px; border-width: 0px; border-color: inherit; box-sizing: border-box;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;box-sizing: border-box; border-style: solid; border-width: 0px;&quot;&gt;&lt;td class=&quot;hljs-ln-line hljs-ln-numbers&quot; data-line-number=&quot;10&quot; style=&quot;padding: 0px 5px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-top-color: inherit; border-right-color: rgb(204, 204, 204); border-bottom-color: inherit; border-left-color: inherit; box-sizing: border-box; color: rgb(204, 204, 204); text-align: center; vertical-align: top;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;hljs-ln-line hljs-ln-code&quot; data-line-number=&quot;10&quot; width=&quot;813&quot; style=&quot;padding-top: 0px; padding-right: 0px; padding-bottom: 0px; border-width: 0px; border-color: inherit; box-sizing: border-box;&quot;&gt;maxretry = 5&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/pre&gt;&lt;p style=&quot;text-wrap: wrap;&quot;&gt;&lt;img class=&quot;ue-image&quot; src=&quot;http://www.zajiben.cn/zb_users/upload/2023/12/202312121702348858507108.png&quot; title=&quot;1.png&quot; alt=&quot;1.png&quot;/&gt;&lt;/p&gt;&lt;p style=&quot;margin-top: 1.3rem; margin-bottom: 1.3rem; text-wrap: wrap; box-sizing: border-box; color: rgb(33, 37, 41); font-family: TC, SC, &amp;quot;CJK FALLBACK&amp;quot;, sans-serif; font-size: 16px; letter-spacing: 1px; text-align: justify; background-color: rgb(255, 255, 255);&quot;&gt;以上设置档中，&lt;code style=&quot;box-sizing: border-box; font-size: 1em; color: rgb(191, 97, 106); overflow-wrap: break-word; background-color: rgb(249, 249, 249); border-radius: 3px; padding: 0.1rem 0.5rem; font-family: &amp;quot;CJK MONO&amp;quot;, monospace !important;&quot;&gt;[sshd]&lt;/code&gt;是指这个区块的字段是用来设置&lt;code style=&quot;box-sizing: border-box; font-size: 1em; color: rgb(191, 97, 106); overflow-wrap: break-word; background-color: rgb(249, 249, 249); border-radius: 3px; padding: 0.1rem 0.5rem; font-family: &amp;quot;CJK MONO&amp;quot;, monospace !important;&quot;&gt;sshd&lt;/code&gt;这个「jail」(一种称呼某种用来限制访问的机制的常用名称)。&lt;code style=&quot;box-sizing: border-box; font-size: 1em; color: rgb(191, 97, 106); overflow-wrap: break-word; background-color: rgb(249, 249, 249); border-radius: 3px; padding: 0.1rem 0.5rem; font-family: &amp;quot;CJK MONO&amp;quot;, monospace !important;&quot;&gt;enabled = true&lt;/code&gt;表示要激活这个jail。&lt;code style=&quot;box-sizing: border-box; font-size: 1em; color: rgb(191, 97, 106); overflow-wrap: break-word; background-color: rgb(249, 249, 249); border-radius: 3px; padding: 0.1rem 0.5rem; font-family: &amp;quot;CJK MONO&amp;quot;, monospace !important;&quot;&gt;bantime&lt;/code&gt;是每次要封锁的基本持续时间，&lt;code style=&quot;box-sizing: border-box; font-size: 1em; color: rgb(191, 97, 106); overflow-wrap: break-word; background-color: rgb(249, 249, 249); border-radius: 3px; padding: 0.1rem 0.5rem; font-family: &amp;quot;CJK MONO&amp;quot;, monospace !important;&quot;&gt;m&lt;/code&gt;表示分钟、&lt;code style=&quot;box-sizing: border-box; font-size: 1em; color: rgb(191, 97, 106); overflow-wrap: break-word; background-color: rgb(249, 249, 249); border-radius: 3px; padding: 0.1rem 0.5rem; font-family: &amp;quot;CJK MONO&amp;quot;, monospace !important;&quot;&gt;h&lt;/code&gt;表示小时、&lt;code style=&quot;box-sizing: border-box; font-size: 1em; color: rgb(191, 97, 106); overflow-wrap: break-word; background-color: rgb(249, 249, 249); border-radius: 3px; padding: 0.1rem 0.5rem; font-family: &amp;quot;CJK MONO&amp;quot;, monospace !important;&quot;&gt;d&lt;/code&gt;表示天，如果不写单位的话，单位会是秒。&lt;code style=&quot;box-sizing: border-box; font-size: 1em; color: rgb(191, 97, 106); overflow-wrap: break-word; background-color: rgb(249, 249, 249); border-radius: 3px; padding: 0.1rem 0.5rem; font-family: &amp;quot;CJK MONO&amp;quot;, monospace !important;&quot;&gt;bantime.increment = true&lt;/code&gt;是让先前被封锁过的IP再下一次被封锁的时候拉长它的封锁时间。&lt;code style=&quot;box-sizing: border-box; font-size: 1em; color: rgb(191, 97, 106); overflow-wrap: break-word; background-color: rgb(249, 249, 249); border-radius: 3px; padding: 0.1rem 0.5rem; font-family: &amp;quot;CJK MONO&amp;quot;, monospace !important;&quot;&gt;bantime.maxtime&lt;/code&gt;是设置最大的封锁时间。在&lt;code style=&quot;box-sizing: border-box; font-size: 1em; color: rgb(191, 97, 106); overflow-wrap: break-word; background-color: rgb(249, 249, 249); border-radius: 3px; padding: 0.1rem 0.5rem; font-family: &amp;quot;CJK MONO&amp;quot;, monospace !important;&quot;&gt;findtime&lt;/code&gt;的时间内，如果有同样的IP的错误尝试次数超过&lt;code style=&quot;box-sizing: border-box; font-size: 1em; color: rgb(191, 97, 106); overflow-wrap: break-word; background-color: rgb(249, 249, 249); border-radius: 3px; padding: 0.1rem 0.5rem; font-family: &amp;quot;CJK MONO&amp;quot;, monospace !important;&quot;&gt;maxretry&lt;/code&gt;所规定的次数，这个IP就会被封锁。&lt;/p&gt;&lt;p style=&quot;margin-top: 1.3rem; margin-bottom: 1.3rem; text-wrap: wrap; box-sizing: border-box; color: rgb(33, 37, 41); font-family: TC, SC, &amp;quot;CJK FALLBACK&amp;quot;, sans-serif; font-size: 16px; letter-spacing: 1px; text-align: justify; background-color: rgb(255, 255, 255);&quot;&gt;设置好后可以运行以下指令让Fail2ban重新加载设置档：&lt;/p&gt;&lt;div class=&quot;blockquote&quot; style=&quot;text-wrap: wrap; box-sizing: border-box; margin-bottom: 1rem; font-size: 16px; border: 0.0625rem solid rgb(204, 204, 204); padding: 1.6rem; color: rgb(33, 37, 41); font-family: TC, SC, &amp;quot;CJK FALLBACK&amp;quot;, sans-serif; letter-spacing: 1px; text-align: justify; background-color: rgb(255, 255, 255);&quot;&gt;sudo fail2ban-client reload&lt;/div&gt;&lt;p style=&quot;margin-top: 1.3rem; margin-bottom: 1.3rem; text-wrap: wrap; box-sizing: border-box; color: rgb(33, 37, 41); font-family: TC, SC, &amp;quot;CJK FALLBACK&amp;quot;, sans-serif; font-size: 16px; letter-spacing: 1px; text-align: justify; background-color: rgb(255, 255, 255);&quot;&gt;以下指令可以查看Fail2ban的状态：&lt;/p&gt;&lt;div class=&quot;blockquote&quot; style=&quot;text-wrap: wrap; box-sizing: border-box; margin-bottom: 1rem; font-size: 16px; border: 0.0625rem solid rgb(204, 204, 204); padding: 1.6rem; color: rgb(33, 37, 41); font-family: TC, SC, &amp;quot;CJK FALLBACK&amp;quot;, sans-serif; letter-spacing: 1px; text-align: justify; background-color: rgb(255, 255, 255);&quot;&gt;sudo fail2ban-client status&lt;/div&gt;&lt;p style=&quot;text-wrap: wrap;&quot;&gt;&lt;img class=&quot;ue-image&quot; src=&quot;http://www.zajiben.cn/zb_users/upload/2023/12/202312121702348869173612.png&quot; title=&quot;2.png&quot; alt=&quot;2.png&quot;/&gt;&lt;/p&gt;&lt;p style=&quot;margin-top: 1.3rem; margin-bottom: 1.3rem; text-wrap: wrap; box-sizing: border-box; color: rgb(33, 37, 41); font-family: TC, SC, &amp;quot;CJK FALLBACK&amp;quot;, sans-serif; font-size: 16px; letter-spacing: 1px; text-align: justify; background-color: rgb(255, 255, 255);&quot;&gt;如上图，可以看到&lt;code style=&quot;box-sizing: border-box; font-size: 1em; color: rgb(191, 97, 106); overflow-wrap: break-word; background-color: rgb(249, 249, 249); border-radius: 3px; padding: 0.1rem 0.5rem; font-family: &amp;quot;CJK MONO&amp;quot;, monospace !important;&quot;&gt;sshd&lt;/code&gt;这个jail被激活了。&lt;/p&gt;&lt;h3 style=&quot;text-wrap: wrap; box-sizing: border-box; margin: 1.9rem 0px 1.3rem; font-weight: 500; line-height: 1.2; color: rgb(33, 37, 41); font-size: 1.75rem; font-family: TC, SC, &amp;quot;CJK FALLBACK&amp;quot;, sans-serif; letter-spacing: 1px; text-align: justify; background-color: rgb(255, 255, 255);&quot;&gt;解封IP&lt;/h3&gt;&lt;p style=&quot;margin-top: 1.3rem; margin-bottom: 1.3rem; text-wrap: wrap; box-sizing: border-box; color: rgb(33, 37, 41); font-family: TC, SC, &amp;quot;CJK FALLBACK&amp;quot;, sans-serif; font-size: 16px; letter-spacing: 1px; text-align: justify; background-color: rgb(255, 255, 255);&quot;&gt;以下指令可以查看被关进&lt;code style=&quot;box-sizing: border-box; font-size: 1em; color: rgb(191, 97, 106); overflow-wrap: break-word; background-color: rgb(249, 249, 249); border-radius: 3px; padding: 0.1rem 0.5rem; font-family: &amp;quot;CJK MONO&amp;quot;, monospace !important;&quot;&gt;sshd&lt;/code&gt;这个jail的IP有哪些：&lt;/p&gt;&lt;div class=&quot;blockquote&quot; style=&quot;text-wrap: wrap; box-sizing: border-box; margin-bottom: 1rem; font-size: 16px; border: 0.0625rem solid rgb(204, 204, 204); padding: 1.6rem; color: rgb(33, 37, 41); font-family: TC, SC, &amp;quot;CJK FALLBACK&amp;quot;, sans-serif; letter-spacing: 1px; text-align: justify; background-color: rgb(255, 255, 255);&quot;&gt;sudo fail2ban-client status sshd&lt;/div&gt;&lt;p style=&quot;text-wrap: wrap;&quot;&gt;&lt;br/&gt;&lt;/p&gt;&lt;p style=&quot;text-wrap: wrap;&quot;&gt;&lt;img class=&quot;ue-image&quot; src=&quot;http://www.zajiben.cn/zb_users/upload/2023/12/202312121702348883553751.png&quot; title=&quot;3.png&quot; alt=&quot;3.png&quot;/&gt;&lt;/p&gt;&lt;p style=&quot;text-wrap: wrap;&quot;&gt;&lt;br/&gt;&lt;/p&gt;&lt;p style=&quot;text-wrap: wrap;&quot;&gt;&lt;span style=&quot;color: #212529; font-family: TC, SC, &amp;quot;CJK FALLBACK&amp;quot;, sans-serif; font-size: 16px; letter-spacing: 1px; text-align: justify; background-color: #FFFFFF;&quot;&gt;如上图，可以看到&lt;/span&gt;&lt;code style=&quot;box-sizing: border-box; font-size: 16px; color: rgb(191, 97, 106); overflow-wrap: break-word; background-color: rgb(249, 249, 249); border-radius: 3px; padding: 0.1rem 0.5rem; letter-spacing: 1px; text-align: justify; font-family: &amp;quot;CJK MONO&amp;quot;, monospace !important;&quot;&gt;192.168.56.1&lt;/code&gt;&lt;span style=&quot;color: #212529; font-family: TC, SC, &amp;quot;CJK FALLBACK&amp;quot;, sans-serif; font-size: 16px; letter-spacing: 1px; text-align: justify; background-color: #FFFFFF;&quot;&gt;这个IP被封锁了。如果要手动即时解封它，可以运行以下指令：&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;text-wrap: wrap;&quot;&gt;&lt;br/&gt;&lt;/p&gt;&lt;div class=&quot;blockquote&quot; style=&quot;text-wrap: wrap; box-sizing: border-box; margin-bottom: 1rem; font-size: 16px; border: 0.0625rem solid rgb(204, 204, 204); padding: 1.6rem; color: rgb(33, 37, 41); font-family: TC, SC, &amp;quot;CJK FALLBACK&amp;quot;, sans-serif; letter-spacing: 1px; text-align: justify; background-color: rgb(255, 255, 255);&quot;&gt;sudo fail2ban-client set sshd unbanip 192.168.56.1&lt;/div&gt;&lt;p style=&quot;margin-top: 1.3rem; margin-bottom: 1.3rem; text-wrap: wrap; box-sizing: border-box; color: rgb(33, 37, 41); font-family: TC, SC, &amp;quot;CJK FALLBACK&amp;quot;, sans-serif; font-size: 16px; letter-spacing: 1px; text-align: justify; background-color: rgb(255, 255, 255);&quot;&gt;或是用以下指令解封也可以，不过这个指令是把某个IP从所有jail中释放出来：&lt;/p&gt;&lt;div class=&quot;blockquote&quot; style=&quot;text-wrap: wrap; box-sizing: border-box; margin-bottom: 1rem; font-size: 16px; border: 0.0625rem solid rgb(204, 204, 204); padding: 1.6rem; color: rgb(33, 37, 41); font-family: TC, SC, &amp;quot;CJK FALLBACK&amp;quot;, sans-serif; letter-spacing: 1px; text-align: justify; background-color: rgb(255, 255, 255);&quot;&gt;sudo fail2ban-client unban 192.168.56.1&lt;/div&gt;&lt;p style=&quot;text-wrap: wrap;&quot;&gt;&lt;br/&gt;&lt;/p&gt;&lt;p style=&quot;text-wrap: wrap;&quot;&gt;&lt;img class=&quot;ue-image&quot; src=&quot;http://www.zajiben.cn/zb_users/upload/2023/12/202312121702348893364810.png&quot; title=&quot;4.png&quot; alt=&quot;4.png&quot;/&gt;&lt;/p&gt;&lt;p style=&quot;text-wrap: wrap;&quot;&gt;&lt;br/&gt;&lt;/p&gt;&lt;p style=&quot;margin-top: 1.3rem; margin-bottom: 1.3rem; text-wrap: wrap; box-sizing: border-box; color: rgb(33, 37, 41); font-family: TC, SC, &amp;quot;CJK FALLBACK&amp;quot;, sans-serif; font-size: 16px; letter-spacing: 1px; text-align: justify; background-color: rgb(255, 255, 255);&quot;&gt;以下指令可以查看所有被Fail2ban封锁的IP：&lt;/p&gt;&lt;div class=&quot;blockquote&quot; style=&quot;text-wrap: wrap; box-sizing: border-box; margin-bottom: 1rem; font-size: 16px; border: 0.0625rem solid rgb(204, 204, 204); padding: 1.6rem; color: rgb(33, 37, 41); font-family: TC, SC, &amp;quot;CJK FALLBACK&amp;quot;, sans-serif; letter-spacing: 1px; text-align: justify; background-color: rgb(255, 255, 255);&quot;&gt;sudo fail2ban-client banned&lt;/div&gt;&lt;p style=&quot;margin-top: 1.3rem; margin-bottom: 1.3rem; text-wrap: wrap; box-sizing: border-box; color: rgb(33, 37, 41); font-family: TC, SC, &amp;quot;CJK FALLBACK&amp;quot;, sans-serif; font-size: 16px; letter-spacing: 1px; text-align: justify; background-color: rgb(255, 255, 255);&quot;&gt;以下指令可以解封所有被Fail2ban封锁的IP：&lt;/p&gt;&lt;div class=&quot;blockquote&quot; style=&quot;text-wrap: wrap; box-sizing: border-box; margin-bottom: 1rem; font-size: 16px; border: 0.0625rem solid rgb(204, 204, 204); padding: 1.6rem; color: rgb(33, 37, 41); font-family: TC, SC, &amp;quot;CJK FALLBACK&amp;quot;, sans-serif; letter-spacing: 1px; text-align: justify; background-color: rgb(255, 255, 255);&quot;&gt;sudo fail2ban-client unban --all&lt;/div&gt;&lt;h3 style=&quot;text-wrap: wrap; box-sizing: border-box; margin: 1.9rem 0px 1.3rem; font-weight: 500; line-height: 1.2; color: rgb(33, 37, 41); font-size: 1.75rem; font-family: TC, SC, &amp;quot;CJK FALLBACK&amp;quot;, sans-serif; letter-spacing: 1px; text-align: justify; background-color: rgb(255, 255, 255);&quot;&gt;寄信通知&lt;/h3&gt;&lt;p style=&quot;margin-top: 1.3rem; margin-bottom: 1.3rem; text-wrap: wrap; box-sizing: border-box; color: rgb(33, 37, 41); font-family: TC, SC, &amp;quot;CJK FALLBACK&amp;quot;, sans-serif; font-size: 16px; letter-spacing: 1px; text-align: justify; background-color: rgb(255, 255, 255);&quot;&gt;当有IP被封锁的时候，Fail2ban可以主动发出电子邮件通知系统管理员，看要不要做什么后续的处理。&lt;/p&gt;&lt;p style=&quot;margin-top: 1.3rem; margin-bottom: 1.3rem; text-wrap: wrap; box-sizing: border-box; color: rgb(33, 37, 41); font-family: TC, SC, &amp;quot;CJK FALLBACK&amp;quot;, sans-serif; font-size: 16px; letter-spacing: 1px; text-align: justify; background-color: rgb(255, 255, 255);&quot;&gt;如果要启动寄信通知功能，可以编辑&lt;code style=&quot;box-sizing: border-box; font-size: 1em; color: rgb(191, 97, 106); overflow-wrap: break-word; background-color: rgb(249, 249, 249); border-radius: 3px; padding: 0.1rem 0.5rem; font-family: &amp;quot;CJK MONO&amp;quot;, monospace !important;&quot;&gt;/etc/fail2ban/jail.d/sshd.local&lt;/code&gt;，进行如下的修改：&lt;/p&gt;&lt;pre class=&quot;plaintext hljs language-plaintext&quot; data-highlighted=&quot;yes&quot; style=&quot;margin-top: 0px; margin-bottom: 1rem; padding: 0.5rem; letter-spacing: 0px; box-sizing: border-box; font-size: 16px; overflow: auto; color: rgb(36, 41, 46); tab-size: 4; text-align: justify; font-family: &amp;quot;CJK MONO&amp;quot;, monospace !important;&quot;&gt;&lt;table class=&quot;hljs-ln&quot; width=&quot;840&quot;&gt;&lt;tbody style=&quot;box-sizing: border-box; border-style: solid; border-width: 0px;&quot;&gt;&lt;tr class=&quot;firstRow&quot; style=&quot;box-sizing: border-box; border-style: solid; border-width: 0px;&quot;&gt;&lt;td class=&quot;hljs-ln-line hljs-ln-numbers&quot; data-line-number=&quot;1&quot; style=&quot;padding: 0px 5px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-top-color: inherit; border-right-color: rgb(204, 204, 204); border-bottom-color: inherit; border-left-color: inherit; box-sizing: border-box; color: rgb(204, 204, 204); text-align: center; vertical-align: top;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;hljs-ln-line hljs-ln-code&quot; data-line-number=&quot;1&quot; width=&quot;813&quot; style=&quot;padding-top: 0px; padding-right: 0px; padding-bottom: 0px; border-width: 0px; border-color: inherit; box-sizing: border-box;&quot;&gt;[sshd]&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;box-sizing: border-box; border-style: solid; border-width: 0px;&quot;&gt;&lt;td class=&quot;hljs-ln-line hljs-ln-numbers&quot; data-line-number=&quot;2&quot; style=&quot;padding: 0px 5px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-top-color: inherit; border-right-color: rgb(204, 204, 204); border-bottom-color: inherit; border-left-color: inherit; box-sizing: border-box; color: rgb(204, 204, 204); text-align: center; vertical-align: top;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;hljs-ln-line hljs-ln-code&quot; data-line-number=&quot;2&quot; width=&quot;813&quot; style=&quot;padding-top: 0px; padding-right: 0px; padding-bottom: 0px; border-width: 0px; border-color: inherit; box-sizing: border-box;&quot;&gt;enabled = true&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;box-sizing: border-box; border-style: solid; border-width: 0px;&quot;&gt;&lt;td class=&quot;hljs-ln-line hljs-ln-numbers&quot; data-line-number=&quot;3&quot; style=&quot;padding: 0px 5px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-top-color: inherit; border-right-color: rgb(204, 204, 204); border-bottom-color: inherit; border-left-color: inherit; box-sizing: border-box; color: rgb(204, 204, 204); text-align: center; vertical-align: top;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;hljs-ln-line hljs-ln-code&quot; data-line-number=&quot;3&quot; width=&quot;813&quot; style=&quot;padding-top: 0px; padding-right: 0px; padding-bottom: 0px; border-width: 0px; border-color: inherit; box-sizing: border-box;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;box-sizing: border-box; border-style: solid; border-width: 0px;&quot;&gt;&lt;td class=&quot;hljs-ln-line hljs-ln-numbers&quot; data-line-number=&quot;4&quot; style=&quot;padding: 0px 5px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-top-color: inherit; border-right-color: rgb(204, 204, 204); border-bottom-color: inherit; border-left-color: inherit; box-sizing: border-box; color: rgb(204, 204, 204); text-align: center; vertical-align: top;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;hljs-ln-line hljs-ln-code&quot; data-line-number=&quot;4&quot; width=&quot;813&quot; style=&quot;padding-top: 0px; padding-right: 0px; padding-bottom: 0px; border-width: 0px; border-color: inherit; box-sizing: border-box;&quot;&gt;bantime = 10m&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;box-sizing: border-box; border-style: solid; border-width: 0px;&quot;&gt;&lt;td class=&quot;hljs-ln-line hljs-ln-numbers&quot; data-line-number=&quot;5&quot; style=&quot;padding: 0px 5px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-top-color: inherit; border-right-color: rgb(204, 204, 204); border-bottom-color: inherit; border-left-color: inherit; box-sizing: border-box; color: rgb(204, 204, 204); text-align: center; vertical-align: top;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;hljs-ln-line hljs-ln-code&quot; data-line-number=&quot;5&quot; width=&quot;813&quot; style=&quot;padding-top: 0px; padding-right: 0px; padding-bottom: 0px; border-width: 0px; border-color: inherit; box-sizing: border-box;&quot;&gt;bantime.increment = true&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;box-sizing: border-box; border-style: solid; border-width: 0px;&quot;&gt;&lt;td class=&quot;hljs-ln-line hljs-ln-numbers&quot; data-line-number=&quot;6&quot; style=&quot;padding: 0px 5px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-top-color: inherit; border-right-color: rgb(204, 204, 204); border-bottom-color: inherit; border-left-color: inherit; box-sizing: border-box; color: rgb(204, 204, 204); text-align: center; vertical-align: top;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;hljs-ln-line hljs-ln-code&quot; data-line-number=&quot;6&quot; width=&quot;813&quot; style=&quot;padding-top: 0px; padding-right: 0px; padding-bottom: 0px; border-width: 0px; border-color: inherit; box-sizing: border-box;&quot;&gt;bantime.maxtime = 1d&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;box-sizing: border-box; border-style: solid; border-width: 0px;&quot;&gt;&lt;td class=&quot;hljs-ln-line hljs-ln-numbers&quot; data-line-number=&quot;7&quot; style=&quot;padding: 0px 5px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-top-color: inherit; border-right-color: rgb(204, 204, 204); border-bottom-color: inherit; border-left-color: inherit; box-sizing: border-box; color: rgb(204, 204, 204); text-align: center; vertical-align: top;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;hljs-ln-line hljs-ln-code&quot; data-line-number=&quot;7&quot; width=&quot;813&quot; style=&quot;padding-top: 0px; padding-right: 0px; padding-bottom: 0px; border-width: 0px; border-color: inherit; box-sizing: border-box;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;box-sizing: border-box; border-style: solid; border-width: 0px;&quot;&gt;&lt;td class=&quot;hljs-ln-line hljs-ln-numbers&quot; data-line-number=&quot;8&quot; style=&quot;padding: 0px 5px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-top-color: inherit; border-right-color: rgb(204, 204, 204); border-bottom-color: inherit; border-left-color: inherit; box-sizing: border-box; color: rgb(204, 204, 204); text-align: center; vertical-align: top;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;hljs-ln-line hljs-ln-code&quot; data-line-number=&quot;8&quot; width=&quot;813&quot; style=&quot;padding-top: 0px; padding-right: 0px; padding-bottom: 0px; border-width: 0px; border-color: inherit; box-sizing: border-box;&quot;&gt;findtime = 10m&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;box-sizing: border-box; border-style: solid; border-width: 0px;&quot;&gt;&lt;td class=&quot;hljs-ln-line hljs-ln-numbers&quot; data-line-number=&quot;9&quot; style=&quot;padding: 0px 5px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-top-color: inherit; border-right-color: rgb(204, 204, 204); border-bottom-color: inherit; border-left-color: inherit; box-sizing: border-box; color: rgb(204, 204, 204); text-align: center; vertical-align: top;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;hljs-ln-line hljs-ln-code&quot; data-line-number=&quot;9&quot; width=&quot;813&quot; style=&quot;padding-top: 0px; padding-right: 0px; padding-bottom: 0px; border-width: 0px; border-color: inherit; box-sizing: border-box;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;box-sizing: border-box; border-style: solid; border-width: 0px;&quot;&gt;&lt;td class=&quot;hljs-ln-line hljs-ln-numbers&quot; data-line-number=&quot;10&quot; style=&quot;padding: 0px 5px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-top-color: inherit; border-right-color: rgb(204, 204, 204); border-bottom-color: inherit; border-left-color: inherit; box-sizing: border-box; color: rgb(204, 204, 204); text-align: center; vertical-align: top;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;hljs-ln-line hljs-ln-code&quot; data-line-number=&quot;10&quot; width=&quot;813&quot; style=&quot;padding-top: 0px; padding-right: 0px; padding-bottom: 0px; border-width: 0px; border-color: inherit; box-sizing: border-box;&quot;&gt;maxretry = 7&lt;/td&gt;&lt;/tr&gt;&lt;tr style=&quot;box-sizing: border-box; border-style: solid; border-width: 0px;&quot;&gt;&lt;td class=&quot;hljs-ln-line hljs-ln-numbers&quot; data-line-number=&quot;11&quot; style=&quot;padding: 0px 5px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-top-color: inherit; border-right-color: rgb(204, 204, 204); border-bottom-color: inherit; border-left-color: inherit; box-sizing: border-box; color: rgb(204, 204, 204); text-align: center; vertical-align: top;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;hljs-ln-line hljs-ln-code&quot; data-line-number=&quot;11&quot; width=&quot;813&quot; style=&quot;padding-top: 0px; padding-right: 0px; padding-bottom: 0px; border-width: 0px; border-color: inherit; box-sizing: border-box;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr class=&quot;bg-highlight&quot; style=&quot;box-sizing: border-box; border-style: solid; border-width: 0px; background-color: rgb(255, 228, 146) !important;&quot;&gt;&lt;td class=&quot;hljs-ln-line hljs-ln-numbers text-danger&quot; data-line-number=&quot;12&quot; style=&quot;padding: 0px 5px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-top-color: inherit; border-right-color: rgb(204, 204, 204); border-bottom-color: inherit; border-left-color: inherit; box-sizing: border-box; --bs-text-opacity: 1; color: rgb(204, 204, 204); text-align: center; vertical-align: top;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;hljs-ln-line hljs-ln-code&quot; data-line-number=&quot;12&quot; width=&quot;813&quot; style=&quot;padding-top: 0px; padding-right: 0px; padding-bottom: 0px; border-width: 0px; border-color: inherit; box-sizing: border-box;&quot;&gt;destemail = yourname@example.com&lt;/td&gt;&lt;/tr&gt;&lt;tr class=&quot;bg-highlight&quot; style=&quot;box-sizing: border-box; border-style: solid; border-width: 0px; background-color: rgb(255, 228, 146) !important;&quot;&gt;&lt;td class=&quot;hljs-ln-line hljs-ln-numbers text-danger&quot; data-line-number=&quot;13&quot; style=&quot;padding: 0px 5px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-top-color: inherit; border-right-color: rgb(204, 204, 204); border-bottom-color: inherit; border-left-color: inherit; box-sizing: border-box; --bs-text-opacity: 1; color: rgb(204, 204, 204); text-align: center; vertical-align: top;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;hljs-ln-line hljs-ln-code&quot; data-line-number=&quot;13&quot; width=&quot;813&quot; style=&quot;padding-top: 0px; padding-right: 0px; padding-bottom: 0px; border-width: 0px; border-color: inherit; box-sizing: border-box;&quot;&gt;action = %(action_mwl)s&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;/pre&gt;&lt;p style=&quot;margin-top: 1.3rem; margin-bottom: 1.3rem; text-wrap: wrap; box-sizing: border-box; color: rgb(33, 37, 41); font-family: TC, SC, &amp;quot;CJK FALLBACK&amp;quot;, sans-serif; font-size: 16px; letter-spacing: 1px; text-align: justify; background-color: rgb(255, 255, 255);&quot;&gt;&lt;code style=&quot;box-sizing: border-box; font-size: 1em; color: rgb(191, 97, 106); overflow-wrap: break-word; background-color: rgb(249, 249, 249); border-radius: 3px; padding: 0.1rem 0.5rem; font-family: &amp;quot;CJK MONO&amp;quot;, monospace !important;&quot;&gt;destemail&lt;/code&gt;可以设置要寄到的电子邮件信箱。&lt;code style=&quot;box-sizing: border-box; font-size: 1em; color: rgb(191, 97, 106); overflow-wrap: break-word; background-color: rgb(249, 249, 249); border-radius: 3px; padding: 0.1rem 0.5rem; font-family: &amp;quot;CJK MONO&amp;quot;, monospace !important;&quot;&gt;action = %(action_mwl)s&lt;/code&gt;用来设置封锁之后寄信。&lt;/p&gt;&lt;p style=&quot;margin-top: 1.3rem; margin-bottom: 1.3rem; text-wrap: wrap; box-sizing: border-box; color: rgb(33, 37, 41); font-family: TC, SC, &amp;quot;CJK FALLBACK&amp;quot;, sans-serif; font-size: 16px; letter-spacing: 1px; text-align: justify; background-color: rgb(255, 255, 255);&quot;&gt;注意，您的Linux操作系统必须要有寄信的能力，才能让Fail2ban寄信。可以参考这篇文章来设置：&lt;/p&gt;&lt;div class=&quot;blockquote&quot; style=&quot;text-wrap: wrap; box-sizing: border-box; margin-bottom: 1rem; font-size: 16px; border: 0.0625rem solid rgb(204, 204, 204); padding: 1.6rem; color: rgb(33, 37, 41); font-family: TC, SC, &amp;quot;CJK FALLBACK&amp;quot;, sans-serif; letter-spacing: 1px; text-align: justify; background-color: rgb(255, 255, 255);&quot;&gt;&lt;a target=&quot;_blank&quot; href=&quot;https://magiclen.org/linux-sendmail&quot; rel=&quot;noopener&quot; style=&quot;box-sizing: border-box; text-decoration-line: none; margin-bottom: revert;&quot;&gt;https://magiclen.org/linux-sendmail&lt;/a&gt;&lt;/div&gt;&lt;p style=&quot;margin-top: 1.3rem; margin-bottom: 1.3rem; text-wrap: wrap; box-sizing: border-box; color: rgb(33, 37, 41); font-family: TC, SC, &amp;quot;CJK FALLBACK&amp;quot;, sans-serif; font-size: 16px; letter-spacing: 1px; text-align: justify; background-color: rgb(255, 255, 255);&quot;&gt;设置完成后，使用以下指令重启Fail2ban：&lt;/p&gt;&lt;div class=&quot;blockquote&quot; style=&quot;text-wrap: wrap; box-sizing: border-box; margin-bottom: 1rem; font-size: 16px; border: 0.0625rem solid rgb(204, 204, 204); padding: 1.6rem; color: rgb(33, 37, 41); font-family: TC, SC, &amp;quot;CJK FALLBACK&amp;quot;, sans-serif; letter-spacing: 1px; text-align: justify; background-color: rgb(255, 255, 255);&quot;&gt;sudo fail2ban-client restart&lt;/div&gt;&lt;p style=&quot;margin-top: 1.3rem; margin-bottom: 1.3rem; text-wrap: wrap; box-sizing: border-box; color: rgb(33, 37, 41); font-family: TC, SC, &amp;quot;CJK FALLBACK&amp;quot;, sans-serif; font-size: 16px; letter-spacing: 1px; text-align: justify; background-color: rgb(255, 255, 255);&quot;&gt;如果只是使用&lt;code style=&quot;box-sizing: border-box; font-size: 1em; color: rgb(191, 97, 106); overflow-wrap: break-word; background-color: rgb(249, 249, 249); border-radius: 3px; padding: 0.1rem 0.5rem; font-family: &amp;quot;CJK MONO&amp;quot;, monospace !important;&quot;&gt;fail2ban-client reload&lt;/code&gt;重新加载设置档，貌似对寄信的设置是无效的。重启Fail2ban后，如果Fail2ban能成功寄出信件，您应该会收到一封Fail2ban寄出的&lt;code style=&quot;box-sizing: border-box; font-size: 1em; color: rgb(191, 97, 106); overflow-wrap: break-word; background-color: rgb(249, 249, 249); border-radius: 3px; padding: 0.1rem 0.5rem; font-family: &amp;quot;CJK MONO&amp;quot;, monospace !important;&quot;&gt;sshd&lt;/code&gt;这个jail被启动的通知信，有收到的话表示Fail2ban的寄信通知功能可以正常使用。&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Tue, 12 Dec 2023 10:34:23 +0800</pubDate></item><item><title>mysql中把两列数据对调</title><link>http://www.zajiben.cn/post/571.html</link><description>&lt;h3&gt;方法一：使用临时变量&lt;/h3&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;第一步：创建临时变量&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;首先我们需要创建2个临时变量来保存2列数据的值。例如：&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-sql&quot;&gt;SET&amp;nbsp;@tmp1&amp;nbsp;=&amp;nbsp;(SELECT&amp;nbsp;col1&amp;nbsp;FROM&amp;nbsp;mytable&amp;nbsp;WHERE&amp;nbsp;somecondition);&amp;nbsp;
SET&amp;nbsp;@tmp2&amp;nbsp;=&amp;nbsp;(SELECT&amp;nbsp;col2&amp;nbsp;FROM&amp;nbsp;mytable&amp;nbsp;WHERE&amp;nbsp;somecondition);&lt;/pre&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;注意，这里 mytable 是你要操作的表名，col1 是你要操作的列名，somecondition 是一个可选的 WHERE 子句，用于限制操作的行。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;第二步：更新列的值&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;text-wrap: nowrap;&quot;&gt;接下来，我们可以使用 UPDATE 语句更新列的值为临时变量的值：&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-sql&quot;&gt;UPDATE&amp;nbsp;mytable&amp;nbsp;SET&amp;nbsp;col1&amp;nbsp;=&amp;nbsp;@tmp2&amp;nbsp;WHERE&amp;nbsp;somecondition;&amp;nbsp;
UPDATE&amp;nbsp;mytable&amp;nbsp;SET&amp;nbsp;col2&amp;nbsp;=&amp;nbsp;@tmp1&amp;nbsp;WHERE&amp;nbsp;somecondition;&lt;/pre&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;h3&gt;方法二：推荐&lt;br/&gt;&lt;/h3&gt;&lt;pre class=&quot;prism-highlight prism-language-sql&quot;&gt;update
	t_info&amp;nbsp;as&amp;nbsp;a,
	t_info&amp;nbsp;as&amp;nbsp;b
set
	a.create_date&amp;nbsp;=&amp;nbsp;b.creator,
	a.creator&amp;nbsp;=&amp;nbsp;b.create_date
where&amp;nbsp;a.id&amp;nbsp;=&amp;nbsp;b.id;&lt;/pre&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Wed, 15 Nov 2023 09:06:10 +0800</pubDate></item><item><title>conda常用基本命令</title><link>http://www.zajiben.cn/post/569.html</link><description>&lt;p&gt;1、查看所有虚拟环境&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-actionscript&quot;&gt;conda&amp;nbsp;env&amp;nbsp;list&lt;/pre&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;2、创建虚拟环境&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-actionscript&quot;&gt;conda&amp;nbsp;create&amp;nbsp;-n&amp;nbsp;python37&amp;nbsp;python=3.7.1&lt;/pre&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;3、激活指定虚拟环境&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-actionscript&quot;&gt;source&amp;nbsp;activate&amp;nbsp;python37
或
activate&amp;nbsp;python37&lt;/pre&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;4、安装相关包&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-actionscript&quot;&gt;conda&amp;nbsp;install&amp;nbsp;numpy&lt;/pre&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;5、退出当前虚拟环境&lt;br/&gt;&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-actionscript&quot;&gt;source&amp;nbsp;deactivate
或
deactivate&lt;/pre&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;6、删除某个虚拟环境&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-actionscript&quot;&gt;conda&amp;nbsp;remove&amp;nbsp;-n&amp;nbsp;python37&amp;nbsp;--all
或
conda&amp;nbsp;env&amp;nbsp;remove&amp;nbsp;-n&amp;nbsp;python37&lt;/pre&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;7、删除环境中某个包&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-actionscript&quot;&gt;conda&amp;nbsp;remove&amp;nbsp;--name&amp;nbsp;your_env_name&amp;nbsp;&amp;nbsp;package_name&amp;nbsp;&amp;nbsp;#&amp;nbsp;删除环境中的某个包&lt;/pre&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Fri, 14 Jul 2023 14:24:38 +0800</pubDate></item><item><title>conda 删除虚拟环境报错CondaEnvironmentError: cannot remove current environment</title><link>http://www.zajiben.cn/post/568.html</link><description>&lt;p&gt;conda 删除虚拟环境报错CondaEnvironmentError: cannot remove current environment. deactivate and run conda rem&lt;/p&gt;&lt;p&gt;1、尝试以下命令&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-actionscript&quot;&gt;conda&amp;nbsp;remove&amp;nbsp;-n&amp;nbsp;your_env_name(虚拟环境名称)&amp;nbsp;--all&amp;nbsp;&amp;nbsp;
&amp;nbsp;
conda&amp;nbsp;remove&amp;nbsp;--name&amp;nbsp;your_env_name&amp;nbsp;&amp;nbsp;package_name&amp;nbsp;&amp;nbsp;#&amp;nbsp;删除环境中的某个包&lt;/pre&gt;&lt;p&gt;2、尝试以下命令&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-actionscript&quot;&gt;conda&amp;nbsp;env&amp;nbsp;remove&amp;nbsp;-n&amp;nbsp;python_gpu(自己的虚拟环境名称)&lt;/pre&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Fri, 14 Jul 2023 14:20:32 +0800</pubDate></item><item><title>url参数转换|url转json|json转url|url转义|url解码 - 在线工具 www.plog.cn</title><link>http://www.zajiben.cn/post/567.html</link><description>&lt;p&gt;&lt;a href=&quot;https://www.plog.cn&quot; target=&quot;_blank&quot;&gt;www.plog.cn&lt;/a&gt; 是一个免费的url参数转换工具。&lt;/p&gt;&lt;p&gt;支持url参数、json、键值对之间相互转换，以及支持url解码、url转义、url编码等功能。&lt;/p&gt;&lt;p style=&quot;text-align: center;&quot;&gt;&lt;a href=&quot;https://www.plog.cn/&quot; target=&quot;_blank&quot; style=&quot;white-space: normal;&quot;&gt;www.plog.cn&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Thu, 05 Jan 2023 14:06:33 +0800</pubDate></item><item><title>SQLAlchemy中使用sqlacodegen自动同步数据库中表生成model</title><link>http://www.zajiben.cn/post/566.html</link><description>&lt;h1 style=&quot;white-space: normal; box-sizing: border-box; outline: 0px; margin: 8px 0px 16px; padding: 0px; font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, SimHei, Arial, SimSun; font-size: 24px; color: rgb(79, 79, 79); line-height: 32px; overflow-wrap: break-word; font-variant-ligatures: no-common-ligatures; background-color: rgb(255, 255, 255);&quot;&gt;前言&lt;/h1&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 16px; white-space: normal; box-sizing: border-box; outline: 0px; padding: 0px; font-size: 16px; color: rgb(77, 77, 77); line-height: 26px; overflow: auto hidden; overflow-wrap: break-word; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-variant-ligatures: no-common-ligatures; background-color: rgb(255, 255, 255);&quot;&gt;如果数据库中的表已经存在了，我们只想通过&amp;nbsp;SQLAlchemy&amp;nbsp;操作数据库表的数据，不需要建表。&lt;br style=&quot;box-sizing: border-box; outline: 0px; overflow-wrap: break-word;&quot;/&gt;这时可以不用一个个声明每个字段类型，可以用第三方包 sqlacodegen 自动生成&amp;nbsp;model&amp;nbsp;模型代码。&lt;/p&gt;&lt;h1 style=&quot;white-space: normal; box-sizing: border-box; outline: 0px; margin: 8px 0px 16px; padding: 0px; font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, SimHei, Arial, SimSun; font-size: 24px; color: rgb(79, 79, 79); line-height: 32px; overflow-wrap: break-word; font-variant-ligatures: no-common-ligatures; background-color: rgb(255, 255, 255);&quot;&gt;&lt;a name=&quot;t1&quot; style=&quot;box-sizing: border-box; outline: none; margin: 0px; padding: 0px; font-weight: normal; cursor: pointer; background-color: transparent; color: rgb(78, 161, 219); overflow-wrap: break-word;&quot;&gt;&lt;/a&gt;&lt;a id=&quot;sqlacodegen__5&quot; style=&quot;box-sizing: border-box; outline: none; margin: 0px; padding: 0px; font-weight: normal; cursor: pointer; background-color: transparent; color: rgb(78, 161, 219); overflow-wrap: break-word;&quot;&gt;&lt;/a&gt;sqlacodegen 安装&lt;/h1&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 16px; white-space: normal; box-sizing: border-box; outline: 0px; padding: 0px; font-size: 16px; color: rgb(77, 77, 77); line-height: 26px; overflow: auto hidden; overflow-wrap: break-word; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-variant-ligatures: no-common-ligatures; background-color: rgb(255, 255, 255);&quot;&gt;使用pip安装对应包&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-actionscript&quot;&gt;pip&amp;nbsp;install&amp;nbsp;sqlacodegen==2.3.0&lt;/pre&gt;&lt;p style=&quot;white-space: normal;&quot;&gt;&lt;span style=&quot;color: #4D4D4D; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: 16px; font-variant-ligatures: no-common-ligatures; background-color: #FFFFFF;&quot;&gt;mysql 指定导出表命令&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-actionscript&quot;&gt;#&amp;nbsp;指定表&amp;nbsp;导出&amp;nbsp;model
sqlacodegen&amp;nbsp;mysql+pymysql://user:password@127.0.0.1:3306/dbname&amp;nbsp;--outfile=models.py&lt;/pre&gt;&lt;p style=&quot;white-space: normal;&quot;&gt;&lt;span style=&quot;color: #4D4D4D; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: 16px; font-variant-ligatures: no-common-ligatures; background-color: #FFFFFF;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #4D4D4D; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: 16px; font-variant-ligatures: no-common-ligatures; background-color: #FFFFFF;&quot;&gt;连接sql server数据库&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-actionscript&quot;&gt;sqlacodegen&amp;nbsp;mssql+pymssql://user:password@host:port/dbname&amp;nbsp;--outfile=models.py&lt;/pre&gt;&lt;p style=&quot;white-space: normal;&quot;&gt;&lt;span style=&quot;color: #4D4D4D; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: 16px; font-variant-ligatures: no-common-ligatures; background-color: #FFFFFF;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #4D4D4D; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: 16px; font-variant-ligatures: no-common-ligatures; background-color: #FFFFFF;&quot;&gt;连接sqlite&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-actionscript&quot;&gt;#&amp;nbsp;将数据库中所有表导出为&amp;nbsp;model
sqlacodegen&amp;nbsp;sqlite:///testdb.db&amp;nbsp;--outfile=models.py&lt;/pre&gt;&lt;p style=&quot;white-space: normal;&quot;&gt;&lt;span style=&quot;color: #4D4D4D; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: 16px; font-variant-ligatures: no-common-ligatures; background-color: #FFFFFF;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #4D4D4D; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: 16px; font-variant-ligatures: no-common-ligatures; background-color: #FFFFFF;&quot;&gt;sqlacodegen 命令行参数-h查看&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-actionscript&quot;&gt;&amp;gt;sqlacodegen&amp;nbsp;-h
usage:&amp;nbsp;sqlacodegen&amp;nbsp;[-h]&amp;nbsp;[--version]&amp;nbsp;[--schema&amp;nbsp;SCHEMA]&amp;nbsp;[--tables&amp;nbsp;TABLES]&amp;nbsp;[--noviews]&amp;nbsp;[--noindexes]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[--noconstraints]&amp;nbsp;[--nojoined]&amp;nbsp;[--noinflect]&amp;nbsp;[--noclasses]&amp;nbsp;[--nocomments]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[--outfile&amp;nbsp;OUTFILE]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;[url]

Generates&amp;nbsp;SQLAlchemy&amp;nbsp;model&amp;nbsp;code&amp;nbsp;from&amp;nbsp;an&amp;nbsp;existing&amp;nbsp;database.

positional&amp;nbsp;arguments:
&amp;nbsp;&amp;nbsp;url&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;SQLAlchemy&amp;nbsp;url&amp;nbsp;to&amp;nbsp;the&amp;nbsp;database

optional&amp;nbsp;arguments:
&amp;nbsp;&amp;nbsp;-h,&amp;nbsp;--help&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;show&amp;nbsp;this&amp;nbsp;help&amp;nbsp;message&amp;nbsp;and&amp;nbsp;exit
&amp;nbsp;&amp;nbsp;--version&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;print&amp;nbsp;the&amp;nbsp;version&amp;nbsp;number&amp;nbsp;and&amp;nbsp;exit
&amp;nbsp;&amp;nbsp;--schema&amp;nbsp;SCHEMA&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;load&amp;nbsp;tables&amp;nbsp;from&amp;nbsp;an&amp;nbsp;alternate&amp;nbsp;schema
&amp;nbsp;&amp;nbsp;--tables&amp;nbsp;TABLES&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;tables&amp;nbsp;to&amp;nbsp;process&amp;nbsp;(comma-separated,&amp;nbsp;default:&amp;nbsp;all)
&amp;nbsp;&amp;nbsp;--noviews&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ignore&amp;nbsp;views
&amp;nbsp;&amp;nbsp;--noindexes&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ignore&amp;nbsp;indexes
&amp;nbsp;&amp;nbsp;--noconstraints&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;ignore&amp;nbsp;constraints
&amp;nbsp;&amp;nbsp;--nojoined&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;don&amp;#39;t&amp;nbsp;autodetect&amp;nbsp;joined&amp;nbsp;table&amp;nbsp;inheritance
&amp;nbsp;&amp;nbsp;--noinflect&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;don&amp;#39;t&amp;nbsp;try&amp;nbsp;to&amp;nbsp;convert&amp;nbsp;tables&amp;nbsp;names&amp;nbsp;to&amp;nbsp;singular&amp;nbsp;form
&amp;nbsp;&amp;nbsp;--noclasses&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;don&amp;#39;t&amp;nbsp;generate&amp;nbsp;classes,&amp;nbsp;only&amp;nbsp;tables
&amp;nbsp;&amp;nbsp;--nocomments&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;don&amp;#39;t&amp;nbsp;render&amp;nbsp;column&amp;nbsp;comments
&amp;nbsp;&amp;nbsp;--outfile&amp;nbsp;OUTFILE&amp;nbsp;&amp;nbsp;file&amp;nbsp;to&amp;nbsp;write&amp;nbsp;output&amp;nbsp;to&amp;nbsp;(default:&amp;nbsp;stdout)&lt;/pre&gt;&lt;p style=&quot;white-space: normal;&quot;&gt;&lt;span style=&quot;color: #4D4D4D; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: 16px; font-variant-ligatures: no-common-ligatures; background-color: #FFFFFF;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;h1 style=&quot;white-space: normal; box-sizing: border-box; outline: 0px; margin: 8px 0px 16px; padding: 0px; font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, SimHei, Arial, SimSun; font-size: 24px; color: rgb(79, 79, 79); line-height: 32px; overflow-wrap: break-word; font-variant-ligatures: no-common-ligatures; background-color: rgb(255, 255, 255);&quot;&gt;使用实例&lt;/h1&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 16px; white-space: normal; box-sizing: border-box; outline: 0px; padding: 0px; font-size: 16px; color: rgb(77, 77, 77); line-height: 26px; overflow: auto hidden; overflow-wrap: break-word; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-variant-ligatures: no-common-ligatures; background-color: rgb(255, 255, 255);&quot;&gt;比如我在mysql数据库中有一张表，结构如下&lt;/p&gt;&lt;p style=&quot;white-space: normal;&quot;&gt;&lt;span style=&quot;color: #4D4D4D; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: 16px; font-variant-ligatures: no-common-ligatures; background-color: #FFFFFF;&quot;&gt;数据库连接地址&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-actionscript&quot;&gt;#&amp;nbsp;拼接配置dialect&amp;nbsp;+&amp;nbsp;driver://username:passwor@host:port/database
DB_URI&amp;nbsp;=&amp;nbsp;&amp;#39;mysql+pymysql://root:123456@localhost:3306/web&amp;#39;&lt;/pre&gt;&lt;p style=&quot;white-space: normal;&quot;&gt;&lt;span style=&quot;color: #4D4D4D; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: 16px; font-variant-ligatures: no-common-ligatures; background-color: #FFFFFF;&quot;&gt;&lt;/span&gt;&lt;span style=&quot;color: #4D4D4D; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: 16px; font-variant-ligatures: no-common-ligatures; background-color: #FFFFFF;&quot;&gt;只想同步students 这张表的数据,执行命令&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-actionscript&quot;&gt;sqlacodegen&amp;nbsp;mysql+pymysql://root:123456@localhost:3306/web&amp;nbsp;--outfile=models.py&amp;nbsp;--tables&amp;nbsp;students&lt;/pre&gt;&lt;p style=&quot;white-space: normal;&quot;&gt;&lt;span style=&quot;color: #4D4D4D; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: 16px; font-variant-ligatures: no-common-ligatures; background-color: #FFFFFF;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 16px; white-space: normal; box-sizing: border-box; outline: 0px; padding: 0px; font-size: 16px; color: rgb(77, 77, 77); line-height: 26px; overflow: auto hidden; overflow-wrap: break-word; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-variant-ligatures: no-common-ligatures; background-color: rgb(255, 255, 255);&quot;&gt;相关参数说明：&lt;br style=&quot;box-sizing: border-box; outline: 0px; overflow-wrap: break-word;&quot;/&gt;–outfile 指定导出模块名称models.py&lt;br style=&quot;box-sizing: border-box; outline: 0px; overflow-wrap: break-word;&quot;/&gt;–tables 指定导出的表名称，多个表用逗号隔开，不指定导出全部表&lt;/p&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 16px; white-space: normal; box-sizing: border-box; outline: 0px; padding: 0px; font-size: 16px; color: rgb(77, 77, 77); line-height: 26px; overflow: auto hidden; overflow-wrap: break-word; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-variant-ligatures: no-common-ligatures; background-color: rgb(255, 255, 255);&quot;&gt;执行后得到models.py，内容如下&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-actionscript&quot;&gt;#&amp;nbsp;coding:&amp;nbsp;utf-8
from&amp;nbsp;sqlalchemy&amp;nbsp;import&amp;nbsp;Column,&amp;nbsp;String
from&amp;nbsp;sqlalchemy.dialects.mysql&amp;nbsp;import&amp;nbsp;INTEGER
from&amp;nbsp;sqlalchemy.ext.declarative&amp;nbsp;import&amp;nbsp;declarative_base

Base&amp;nbsp;=&amp;nbsp;declarative_base()
metadata&amp;nbsp;=&amp;nbsp;Base.metadata


class&amp;nbsp;Student(Base):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;__tablename__&amp;nbsp;=&amp;nbsp;&amp;#39;students&amp;#39;

&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;id&amp;nbsp;=&amp;nbsp;Column(INTEGER(11),&amp;nbsp;primary_key=True)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;name&amp;nbsp;=&amp;nbsp;Column(String(20))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;fullname&amp;nbsp;=&amp;nbsp;Column(String(30))
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;nickname&amp;nbsp;=&amp;nbsp;Column(String(30))&lt;/pre&gt;&lt;p style=&quot;white-space: normal;&quot;&gt;&lt;span style=&quot;color: #4D4D4D; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: 16px; font-variant-ligatures: no-common-ligatures; background-color: #FFFFFF;&quot;&gt;如果命令不带&lt;/span&gt;&lt;code style=&quot;box-sizing: border-box; outline: 0px; font-family: &amp;quot;Source Code Pro&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, &amp;quot;Anonymous Pro&amp;quot;, &amp;quot;Droid Sans Mono&amp;quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, sans-serif; line-height: 22px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); border-radius: 2px; padding: 2px 4px; overflow-wrap: break-word; font-variant-ligatures: no-common-ligatures;&quot;&gt;--tables&lt;/code&gt;&lt;span style=&quot;color: #4D4D4D; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: 16px; font-variant-ligatures: no-common-ligatures; background-color: #FFFFFF;&quot;&gt;&amp;nbsp;参数，会生成所有的表&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-actionscript&quot;&gt;sqlacodegen&amp;nbsp;mysql+pymysql://root:123456@localhost:3306/web&amp;nbsp;--outfile=models.py&lt;/pre&gt;&lt;p style=&quot;white-space: normal;&quot;&gt;&lt;span style=&quot;color: #4D4D4D; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: 16px; font-variant-ligatures: no-common-ligatures; background-color: #FFFFFF;&quot;&gt;&lt;/span&gt;&lt;/p&gt;&lt;h1 style=&quot;white-space: normal; box-sizing: border-box; outline: 0px; margin: 8px 0px 16px; padding: 0px; font-family: &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, SimHei, Arial, SimSun; font-size: 24px; color: rgb(79, 79, 79); line-height: 32px; overflow-wrap: break-word; font-variant-ligatures: no-common-ligatures; background-color: rgb(255, 255, 255);&quot;&gt;使用 autoload = True&lt;/h1&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 16px; white-space: normal; box-sizing: border-box; outline: 0px; padding: 0px; font-size: 16px; color: rgb(77, 77, 77); line-height: 26px; overflow: auto hidden; overflow-wrap: break-word; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-variant-ligatures: no-common-ligatures; background-color: rgb(255, 255, 255);&quot;&gt;还有一种方法可以让模型代码跟数据库表字段关联起来，&lt;code style=&quot;box-sizing: border-box; outline: 0px; font-family: &amp;quot;Source Code Pro&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, &amp;quot;Anonymous Pro&amp;quot;, &amp;quot;Droid Sans Mono&amp;quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, sans-serif; font-size: 14px; line-height: 22px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); border-radius: 2px; padding: 2px 4px; overflow-wrap: break-word;&quot;&gt;__table__&lt;/code&gt;&amp;nbsp;中使用&amp;nbsp;&lt;code style=&quot;box-sizing: border-box; outline: 0px; font-family: &amp;quot;Source Code Pro&amp;quot;, &amp;quot;DejaVu Sans Mono&amp;quot;, &amp;quot;Ubuntu Mono&amp;quot;, &amp;quot;Anonymous Pro&amp;quot;, &amp;quot;Droid Sans Mono&amp;quot;, Menlo, Monaco, Consolas, Inconsolata, Courier, monospace, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, sans-serif; font-size: 14px; line-height: 22px; color: rgb(199, 37, 78); background-color: rgb(249, 242, 244); border-radius: 2px; padding: 2px 4px; overflow-wrap: break-word;&quot;&gt;autoload = True&lt;/code&gt;&lt;br style=&quot;box-sizing: border-box; outline: 0px; overflow-wrap: break-word;&quot;/&gt;它会自动加载 model 的 Column, 使用这种方法时，在构建 model 之前，Base 类要与 engine 进行绑定.&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-actionscript&quot;&gt;from&amp;nbsp;sqlalchemy&amp;nbsp;import&amp;nbsp;create_engine
from&amp;nbsp;sqlalchemy.ext.declarative&amp;nbsp;import&amp;nbsp;declarative_base
from&amp;nbsp;sqlalchemy.sql.schema&amp;nbsp;import&amp;nbsp;Table

engine&amp;nbsp;=&amp;nbsp;create_engine(&amp;quot;mysql+pymysql://root:123456@localhost:3306/web&amp;quot;)
Base&amp;nbsp;=&amp;nbsp;declarative_base()
metadata&amp;nbsp;=&amp;nbsp;Base.metadata
metadata.bind&amp;nbsp;=&amp;nbsp;engine


class&amp;nbsp;Employee(Base):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;__table__&amp;nbsp;=&amp;nbsp;Table(&amp;quot;employees&amp;quot;,&amp;nbsp;metadata,&amp;nbsp;autoload=True)&lt;/pre&gt;&lt;p style=&quot;white-space: normal;&quot;&gt;&lt;span style=&quot;color: #4D4D4D; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: 16px; font-variant-ligatures: no-common-ligatures; background-color: #FFFFFF;&quot;&gt;这种方法我们看不到代码里面表字段名称，一般不推荐用。&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;color: #4D4D4D; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: 16px; font-variant-ligatures: no-common-ligatures; background-color: #FFFFFF;&quot;&gt;原文来自：&lt;/span&gt;&lt;span style=&quot;color: #4D4D4D; font-family: -apple-system, &amp;quot;SF UI Text&amp;quot;, Arial, &amp;quot;PingFang SC&amp;quot;, &amp;quot;Hiragino Sans GB&amp;quot;, &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;WenQuanYi Micro Hei&amp;quot;, sans-serif; font-size: 16px; font-variant-ligatures: no-common-ligatures; background-color: #FFFFFF;&quot;&gt;https://blog.csdn.net/qq_27371025/article/details/126440632&lt;/span&gt;&lt;/p&gt;</description><pubDate>Tue, 29 Nov 2022 16:59:15 +0800</pubDate></item><item><title>宝塔面板非https站点使用https访问跳转其他网站内容的处理办法</title><link>http://www.zajiben.cn/post/565.html</link><description>&lt;h3 id=&quot;h3--https-https-&quot; style=&quot;margin: 8px 0px 16px; padding: 0px; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); font-size: 22px; line-height: 30px; color: rgb(79, 79, 79); font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, &amp;quot;PingFang SC&amp;quot;, Tahoma, Arial, sans-serif；; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;宝塔面板非https站点使用https访问跳转其他网站内容的处理办法&lt;/h3&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 0px; padding: 0px; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); word-break: break-word; color: rgb(77, 77, 77); font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, &amp;quot;PingFang SC&amp;quot;, Tahoma, Arial, sans-serif；; font-size: 16px; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;进入宝塔后台-&amp;gt;网站-&amp;gt;（指定未启用ssl的网站）设置-&amp;gt;配置文件进行修改&lt;br/&gt;其实说白了就是修改nginx或者Apache的配置文件而已&lt;br/&gt;首先，加一个443端口，也就是https的端口监听&lt;br/&gt;一般会默认添加80端口监听，我们直接在80端口监听下面添加一行监听443就行&lt;/p&gt;&lt;pre class=&quot;prettyprint linenums prettyprinted&quot; style=&quot;margin: 15px auto; padding: 0.5em; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); overflow-wrap: break-word; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 15px; line-height: 20px; font-family: &amp;quot;courier new&amp;quot;; word-break: break-all; border: 1px solid rgb(136, 136, 136); background-color: rgba(0, 0, 0, 0.05); text-size-adjust: none; overflow-x: auto; color: rgb(77, 77, 77); background-image: url(&amp;quot;img/codecolorer_bg.gif&amp;quot;) !important; background-position: center top !important;&quot;&gt;listen&amp;nbsp;80；linsten&amp;nbsp;443；&lt;/pre&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 0px; padding: 0px; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); word-break: break-word; color: rgb(77, 77, 77); font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, &amp;quot;PingFang SC&amp;quot;, Tahoma, Arial, sans-serif；; font-size: 16px; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;监听完端口后，进行判断，如果当前仅使用80端口，则同时键入如下规则：&lt;br/&gt;若当前访问端口非80端口时，自动跳转至80端口&lt;/p&gt;&lt;pre class=&quot;prettyprint linenums prettyprinted&quot; style=&quot;margin: 15px auto; padding: 0.5em; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); overflow-wrap: break-word; font-variant-numeric: normal; font-variant-east-asian: normal; font-stretch: normal; font-size: 15px; line-height: 20px; font-family: &amp;quot;courier new&amp;quot;; word-break: break-all; border: 1px solid rgb(136, 136, 136); background-color: rgba(0, 0, 0, 0.05); text-size-adjust: none; overflow-x: auto; color: rgb(77, 77, 77); background-image: url(&amp;quot;img/codecolorer_bg.gif&amp;quot;) !important; background-position: center top !important;&quot;&gt;if&amp;nbsp;($server_port&amp;nbsp;!=&amp;nbsp;80&amp;nbsp;)&amp;nbsp;{&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;rewrite&amp;nbsp;^/(.*)$&amp;nbsp;http://$host/$1&amp;nbsp;permanent;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;}&lt;/pre&gt;&lt;p style=&quot;margin-top: 0px; margin-bottom: 0px; padding: 0px; -webkit-tap-highlight-color: rgba(0, 0, 0, 0); word-break: break-word; color: rgb(77, 77, 77); font-family: &amp;quot;Helvetica Neue&amp;quot;, Helvetica, &amp;quot;PingFang SC&amp;quot;, Tahoma, Arial, sans-serif；; font-size: 16px; white-space: normal; background-color: rgb(255, 255, 255);&quot;&gt;随后保存，至此配置结束。&lt;br/&gt;某些情况下，需要重启nginx或者apache才会生效，因此建议大家还是重启一下;&lt;/p&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Mon, 17 Oct 2022 09:08:13 +0800</pubDate></item><item><title>​sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (2003, &amp;quot;Can&#039;t connect to MySQL报错解决</title><link>http://www.zajiben.cn/post/564.html</link><description>&lt;p&gt;sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (2003, &amp;quot;Can&amp;#39;t connect to MySQL server on &amp;#39;xxxx@localhost&amp;#39; ([Errno 11003] getaddrinfo failed)&amp;quot;)&amp;nbsp;报错时，是因为密码是含有@字符导致，需要使用urllib.parse中导入quote_plus解决&lt;/p&gt;&lt;p&gt;例如：&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-python&quot;&gt;from&amp;nbsp;urllib.parse&amp;nbsp;import&amp;nbsp;quote_plus&amp;nbsp;as&amp;nbsp;urlquote
dbConnect=create_engine(f&amp;#39;mysql+pymysql://{userName}:{urlquote(password)}@{dbHost}:{dbPort}/{dbName}?charset=utf8&amp;#39;)&lt;/pre&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Thu, 15 Sep 2022 17:50:38 +0800</pubDate></item><item><title>PyCharm下找不到flask_sqlalchemy的问题</title><link>http://www.zajiben.cn/post/563.html</link><description>&lt;p&gt;使用：flask-sqlalchemy&amp;nbsp;进行搜索&lt;/p&gt;</description><pubDate>Thu, 15 Sep 2022 17:48:31 +0800</pubDate></item><item><title>MySQL重置自增ID方法</title><link>http://www.zajiben.cn/post/562.html</link><description>&lt;p&gt;1.&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-sql&quot;&gt;alter&amp;nbsp;table&amp;nbsp;&amp;nbsp;aaaa&amp;nbsp;&amp;nbsp;&amp;nbsp;AUTO_INCREMENT=1;&lt;/pre&gt;&lt;p&gt;&lt;span style=&quot;color: #4D4D4D; font-family: &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;SF Pro Display&amp;quot;, Roboto, Noto, Arial, &amp;quot;PingFang SC&amp;quot;, sans-serif; font-size: 16px; background-color: #FFFFFF;&quot;&gt;&lt;br/&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style=&quot;color: #4D4D4D; font-family: &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;SF Pro Display&amp;quot;, Roboto, Noto, Arial, &amp;quot;PingFang SC&amp;quot;, sans-serif; font-size: 16px; background-color: #FFFFFF;&quot;&gt;2.&lt;/span&gt;&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-sql&quot;&gt;TRUNCATE&amp;nbsp;TABLE&amp;nbsp;aaaa;&lt;/pre&gt;&lt;p&gt;&lt;span style=&quot;color: #4D4D4D; font-family: &amp;quot;Microsoft YaHei&amp;quot;, &amp;quot;SF Pro Display&amp;quot;, Roboto, Noto, Arial, &amp;quot;PingFang SC&amp;quot;, sans-serif; font-size: 16px; background-color: #FFFFFF;&quot;&gt;&lt;/span&gt;&lt;br/&gt;&lt;/p&gt;&lt;p&gt;3.&lt;/p&gt;&lt;pre class=&quot;prism-highlight prism-language-sql&quot;&gt;DELETE&amp;nbsp;FROM&amp;nbsp;aaaa;&lt;/pre&gt;&lt;p&gt;&lt;br/&gt;&lt;/p&gt;</description><pubDate>Thu, 15 Sep 2022 17:45:00 +0800</pubDate></item></channel></rss>