<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <id>https://webddc.com</id>
    <title>webDDC</title>
    <updated>2024-03-21T03:32:04.638Z</updated>
    <generator>https://github.com/jpmonette/feed</generator>
    <link rel="alternate" href="https://webddc.com"/>
    <link rel="self" href="https://webddc.com/atom.xml"/>
    <subtitle>温故而知新
</subtitle>
    <logo>https://webddc.com/images/avatar.png</logo>
    <icon>https://webddc.com/favicon.ico</icon>
    <rights>All rights reserved 2024, webDDC</rights>
    <entry>
        <title type="html"><![CDATA[namesoli的主机体验有点差 ]]></title>
        <id>https://webddc.com/post/namesoli-de-zhu-ji-ti-yan-you-dian-chai/</id>
        <link href="https://webddc.com/post/namesoli-de-zhu-ji-ti-yan-you-dian-chai/">
        </link>
        <updated>2024-03-21T03:12:24.000Z</updated>
        <content type="html"><![CDATA[<p>今天注册了一个新的域名，直接用了namesoli家的host，结果开通后 cPanel 配置好wordpress，域名还需要再手动配置，而且ssl也需要独立购买。</p>
<p>太麻烦了，直接把域名放在了 cloudflare ，流畅很多。</p>
<p>域名把dns转过来，操作贼简单。</p>
<p>邮箱配置，直接点几下表单搞定。</p>
]]></content>
    </entry>
    <entry>
        <title type="html"><![CDATA[Mysql 创建用户和数据库]]></title>
        <id>https://webddc.com/post/mysql-chuang-jian-yong-hu-he-shu-ju-ku/</id>
        <link href="https://webddc.com/post/mysql-chuang-jian-yong-hu-he-shu-ju-ku/">
        </link>
        <updated>2023-09-17T12:07:34.000Z</updated>
        <content type="html"><![CDATA[<pre><code class="language-sql">create user 'newuser'@'localhost' identified by 'newpassword';
create database newdb default charset utf8mb4;
GRANT ALL PRIVILEGES ON *.* TO 'newuser'@'localhost';
FLUSH PRIVILEGES;
</code></pre>
]]></content>
    </entry>
    <entry>
        <title type="html"><![CDATA[🔢 数字emoji备忘]]></title>
        <id>https://webddc.com/post/shu-zi-emoji-bei-wang/</id>
        <link href="https://webddc.com/post/shu-zi-emoji-bei-wang/">
        </link>
        <updated>2023-04-18T09:05:50.000Z</updated>
        <content type="html"><![CDATA[<p>每次需要找数字 emoji 都要搜索很久，干脆保存一份。</p>
<p>Emojis</p>
<p>Emojis<br>
#️⃣ keycap: # (pound)<br>
*️⃣ keycap: * (asterisk)<br>
0️⃣ keycap: 0<br>
1️⃣ keycap: 1<br>
2️⃣ keycap: 2<br>
3️⃣ keycap: 3<br>
4️⃣ keycap: 4<br>
5️⃣ keycap: 5<br>
6️⃣ keycap: 6<br>
7️⃣ keycap: 7<br>
8️⃣ keycap: 8<br>
9️⃣ keycap: 9<br>
🔟 keycap: 10</p>
]]></content>
    </entry>
    <entry>
        <title type="html"><![CDATA[使用 ufw 管理防火墙 - Ubuntu]]></title>
        <id>https://webddc.com/post/shi-yong-ufw-guan-li-fang-huo-qiang-ubuntu/</id>
        <link href="https://webddc.com/post/shi-yong-ufw-guan-li-fang-huo-qiang-ubuntu/">
        </link>
        <updated>2023-04-18T03:12:23.000Z</updated>
        <content type="html"><![CDATA[<h2 id="安装">安装</h2>
<pre><code class="language-shell">sudo apt update &amp;&amp; sudo apt install ufw
</code></pre>
<h2 id="配置">配置</h2>
<p>允许访问</p>
<pre><code class="language-shell">sudo ufw allow ssh
sudo ufw allow 7722/tcp
</code></pre>
<p>允许源IP地址接口/网卡</p>
<pre><code class="language-shell">sudo ufw allow from 192.168.1.100 #仅允许单IP地址
sudo ufw allow from 192.168.1.100 to any port 3306 #仅允许单IP地址连接3306
sudo ufw allow from 192.168.1.0/24 to any port 3306 
sudo ufw allow in on eth2 to any port 3306
</code></pre>
<p>拒绝连接</p>
<pre><code class="language-shell">sudo ufw deny from 23.24.25.100 #拒绝指定的IP连接
sudo ufw deny from 23.24.25.0/24  #整个网段
sudo ufw deny proto tcp from 23.24.25.0/24 to any port 80,443
</code></pre>
<h2 id="启用">启用</h2>
<pre><code class="language-shell">sudo ufw enable
</code></pre>
<h2 id="删除防火墙规则">删除防火墙规则</h2>
<pre><code class="language-shell">sudo ufw status numbered #已编号的防火墙规则
sudo ufw delete 3 #根据编号删除
sudo ufw delete allow 8069 通过规则删除规则
</code></pre>
<h2 id="禁用防火墙">禁用防火墙</h2>
<pre><code class="language-shell">sudo ufw disable #禁用
sudo ufw enable #开启
sudo ufw reset #重置
</code></pre>
<h2 id=""></h2>
]]></content>
    </entry>
    <entry>
        <title type="html"><![CDATA[使用 ssh-copy-id 快速实现 ssh 证书登录 ]]></title>
        <id>https://webddc.com/post/shi-yong-ssh-copy-id-kuai-su-shi-xian-ssh-zheng-shu-deng-lu/</id>
        <link href="https://webddc.com/post/shi-yong-ssh-copy-id-kuai-su-shi-xian-ssh-zheng-shu-deng-lu/">
        </link>
        <updated>2023-04-18T02:39:42.000Z</updated>
        <content type="html"><![CDATA[<p>使用 <code>ssh-copy-id</code> 复制ssh证书到服务器</p>
<pre><code class="language-shell"># ssh -i ~/.ssh/mykey user@host
ssh-copy-id -i ~/.ssh/id_rsa.pub -p 22 root@1.2.3.4
</code></pre>
<p>输入密码，登录一次，完成证书上传</p>
<p>下次登录直接免密码</p>
<pre><code class="language-shell"># ssh user@host
ssh root@1.2.3.4 -p 22
</code></pre>
]]></content>
    </entry>
    <entry>
        <title type="html"><![CDATA[在ubuntu20.04上设置python2为默认方式]]></title>
        <id>https://webddc.com/post/zai-ubuntu2004-shang-she-zhi-python2-wei-mo-ren-fang-shi/</id>
        <link href="https://webddc.com/post/zai-ubuntu2004-shang-she-zhi-python2-wei-mo-ren-fang-shi/">
        </link>
        <updated>2023-04-16T02:08:33.000Z</updated>
        <content type="html"><![CDATA[<p>Python 2已经从ubuntu20.04中移除，但是如果您有需要旧Python的遗留程序，仍然可以安装和配置。</p>
<p>步骤1:安装Python 2<br>
SSH到您的Ubuntu 20.04服务器并使用apt安装Python 2。</p>
<pre><code class="language-shell">$ sudo apt install python2
</code></pre>
<p>检查Python版本。</p>
<pre><code class="language-shell">$ python2 -V
Python 2.7.17
</code></pre>
<p>步骤2:检查可用的Python版本<br>
检查系统上可用的Python版本。</p>
<pre><code class="language-shell">$ ls /usr/bin/python*
/usr/bin/python2  /usr/bin/python2.7  /usr/bin/python3  /usr/bin/python3.8
</code></pre>
<p>查看是否配置了Python替代方案。</p>
<pre><code class="language-shell">$ sudo update-alternatives --list python
update-alternatives: error: no alternatives for python
</code></pre>
<p>步骤3:设置替代版本</p>
<p>对于本例，我们将设置两个Python替代:Python2和Python3。</p>
<pre><code class="language-shell">$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 1
$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 2
</code></pre>
<p>确认两个备选方案都可以使用:</p>
<pre><code class="language-shell">$ sudo update-alternatives --list python
/usr/bin/python2
/usr/bin/python3
</code></pre>
<p>选择可选的Python版本。</p>
<p>复制代码</p>
<pre><code>$ sudo update-alternatives --config python
There are 2 choices for the alternative python (providing /usr/bin/python).
  Selection    Path              Priority   Status
------------------------------------------------------------
* 0            /usr/bin/python3   2         auto mode
  1            /usr/bin/python2   1         manual mode
  2            /usr/bin/python3   2         manual mode
Press  to keep the current choice[*], or type selection number: 1
</code></pre>
<p>复制代码<br>
输入您的选择。在本例中，选择1来选择python2。</p>
<p>检查你的python版本:</p>
<pre><code>$ python -V
Python 2.7.18rc1
</code></pre>
<p>结论</p>
<p>尽管Python 2已经被弃用了，但是仍然可以在运行Ubuntu 20.04 的VPS上安装和使用。</p>
<p>安装pip</p>
<pre><code>curl https://bootstrap.pypa.io/get-pip.py --output get-pip.py

sudo python2 get-pip.py
</code></pre>
<p>via: https://www.cnblogs.com/dancesir/p/14201267.html</p>
]]></content>
    </entry>
    <entry>
        <title type="html"><![CDATA[django 默认后台静态文件处理]]></title>
        <id>https://webddc.com/post/django-jing-tai-wen-jian-chu-li/</id>
        <link href="https://webddc.com/post/django-jing-tai-wen-jian-chu-li/">
        </link>
        <updated>2022-04-15T08:24:45.000Z</updated>
        <content type="html"><![CDATA[<p>官方文档：</p>
<p>Configuring static files</p>
<p>1 . Make sure that django.contrib.staticfiles is included in your INSTALLED_APPS.</p>
<p>2 . In your settings file, define STATIC_URL, for example:</p>
<pre><code>STATIC_URL = 'static/'
</code></pre>
<p>3 . In your templates, use the static template tag to build the URL for the given relative path using the configured STATICFILES_STORAGE.</p>
<pre><code>{% load static %}
&lt;img src=&quot;{% static 'my_app/example.jpg' %}&quot; alt=&quot;My image&quot;&gt;
</code></pre>
<p>4 . Store your static files in a folder called static in your app. For example my_app/static/my_app/example.jpg.</p>
<p>重点是这里，默认后台管理的static<br>
在 DEBUG=True 的时候，可以正常使用，<br>
在 DEBUG=False 的时候，就访问不到了。</p>
<p>这个时候就需要这个操作，</p>
<pre><code># 设置静态文件目录
STATIC_ROOT = &quot;/var/www/example.com/static/&quot;
</code></pre>
<pre><code># 集合静态文件到 STATIC_ROOT
python manage.py collectstatic
</code></pre>
<p>参考：<br>
https://docs.djangoproject.com/en/4.0/howto/static-files/</p>
]]></content>
    </entry>
    <entry>
        <title type="html"><![CDATA[django 数据库连接超时 OperationalError: (2006, 'MySQL server has gone away')]]></title>
        <id>https://webddc.com/post/django-shu-ju-ku-lian-jie-chao-shi-operationalerror-2006-mysql-server-has-gone-away/</id>
        <link href="https://webddc.com/post/django-shu-ju-ku-lian-jie-chao-shi-operationalerror-2006-mysql-server-has-gone-away/">
        </link>
        <updated>2022-03-11T06:18:19.000Z</updated>
        <content type="html"><![CDATA[<h2 id="解决-django-数据库连接-mysql-超时">解决 django 数据库连接 MySql 超时</h2>
<p>后台脚本操作数据库时，如果长时间没有与数据库交互，连接会被断开。</p>
<p>再次使用查询的时候，由于连接实质已断开，会提示以下错误:</p>
<pre><code>OperationalError: (2006, 'MySQL server has gone away')
</code></pre>
<p>解决方法：</p>
<pre><code>from django.db import connections
# ....
# 在合适的时机，主动断开链接
# ... 
connections.close_all()
</code></pre>
<p>或</p>
<pre><code># 只有一个连接时，这样也一样
from django.db import connection
connection.close()
</code></pre>
<p>主动断开链接，是有状态标识的，所以再次使用时，会重新连接数据库。</p>
<h2 id="mongodb-也有类似解决方案">MongoDb 也有类似解决方案</h2>
<p>以 <code>mongoengine</code>  举例：</p>
<pre><code>import time
from mongoengine import connection
# ...
# ...
# 在合适的位置调用，断开数据库，再次链接
connection.disconnect()
time.sleep(1)
connection.connect(db=settings.MONGODB_DB_NAME, host=settings.MONGODB_HOST, connect=False)
</code></pre>
]]></content>
    </entry>
    <entry>
        <title type="html"><![CDATA[mongodb 备份与恢复]]></title>
        <id>https://webddc.com/post/mongodb-bei-fen-yu-hui-fu/</id>
        <link href="https://webddc.com/post/mongodb-bei-fen-yu-hui-fu/">
        </link>
        <updated>2021-11-17T15:17:50.000Z</updated>
        <content type="html"><![CDATA[<h1 id="数据备份恢复">数据备份/恢复</h1>
<h3 id="mongodump-mongorestore">mongodump &amp;&amp; mongorestore</h3>
<pre><code>mongodump -h host:port -d db_source -c collection_source -o dump/collection_source.bson
mongorestore -h host:port -d db_target -c collection_target dump/collection_source.bson
</code></pre>
<h3 id="mongoexport-mongoimport">mongoexport &amp;&amp; mongoimport</h3>
<pre><code>mongoexport -h [ip_address] -d [database] -c [collection] &gt; source.json
mongoimport -h [ip_address] -d [database] -c [target] source.json


mongoexport --collection=events --db=reporting --out=events.json

</code></pre>
<h3 id="32-之后的版本-支持管道即时处理">3.2 之后的版本, 支持管道，即时处理</h3>
<pre><code>mongoexport -h [ip_address] -d [database] -c [collection] | mongoimport -h [ip_address] -d [database] -c [target]

</code></pre>
<h3 id="数据少也可以用命令行">数据少，也可以用命令行</h3>
<pre><code>use db_source;
var docs = db_source.collection_souce.find();
use db_target;
docs.forEach(function(d){db.collection_target.insert(d)});
</code></pre>
<p>或</p>
<pre><code>db.source.find().forEach(function(doc) {
  db.target.insert(doc);
});
</code></pre>
<h2 id="参考链接">参考链接</h2>
<p>https://segmentfault.com/q/1010000004949649<br>
https://docs.mongodb.com/database-tools/mongodump/<br>
https://docs.mongodb.com/database-tools/mongorestore/<br>
https://docs.mongodb.com/database-tools/mongoexport/<br>
https://docs.mongodb.com/database-tools/mongoimport/</p>
]]></content>
    </entry>
    <entry>
        <title type="html"><![CDATA[移除celery任务]]></title>
        <id>https://webddc.com/post/yi-chu-celery-ren-wu/</id>
        <link href="https://webddc.com/post/yi-chu-celery-ren-wu/">
        </link>
        <updated>2020-03-24T09:09:57.000Z</updated>
        <content type="html"><![CDATA[<pre><code>python manage.py celery purge
</code></pre>
]]></content>
    </entry>
</feed>