分類
软件

我的Git命令記錄

把本地項目傳到 Gitea

首先在 Gitea 新建項目,輸入項目名 YOUR_PROJECT_NAME,其他都不用動。

然後根據 Gitea 的提示,在本地執行下列命令:

#創建說明文檔
touch README.md
#創建忽略文檔,下面有個示例
touch .gitignore
#初始化 git 並推送至服務器
git init
git checkout -b main
(或 github 的 git branch -M main)
git add *
git commit -m "first commit"
git remote add origin https://git.disroot.org/user/YOUR_PROJECT_NAME.git
git push -u origin main

.gitignore 示例

# Django #
*.log
*.pot
*.pyc
__pycache__
db.sqlite3
/app1/migrations
/app1/profile_dir/*
*.lock

#mysite/settings.py
*.env
*.env_1
media
/static

# Backup files # 
*.bak 
*.log
*.log.*

# Eclipse # 
.project
.pydevproject

在服務器部署和更新 Git 代碼倉庫中的代碼

#Clone 項目到服務器
git clone https://git.disroot.org/user/YOUR_PROJECT_NAME.git
cd YOUR_PROJECT_NAME
#拉取代碼倉庫的更新
git fetch
git checkout origin main
[code]

<h3>?</h3>
<p>在服務器上初始化項目</p>
[code language="bash"]
cd /temp
git clone --bare /home/fred/Documents/workspace/amazon/.git amazon.git
scp -P 2009 -r amazon.git [email protected]:/data/42/git

在本地添加遠程項目

git remote add origin ssh://[email protected]:2009/data/42/git/amazon.git
git remote -v
#推送
git push origin master
#下載更新
git clone ssh://[email protected]:2009/data/42/git/unlock.git

本文更新於 2023/11/25。

分類
Linux

Fedora使用DNSCrypt

DNSCrypt是一種認證DNS客戶端和DNS解析器之間通信的協議。 它可以防止DNS欺騙。下面記錄下在Fedora25上使用DNSCrypt的步驟。

dnscrypt-proxy 2 是一個更棒的升級,如果你用的是v1,非常建議升級。官方的安裝文檔已經寫的很詳盡,這裡再簡單記錄一下。

#用超級用戶操作
su -s
#下載dnscrypt-proxy-linux_x86_64-2.0.25.tar.gz並解壓至/opt/dnscrypt-proxy/
#其實解壓到哪裡都無所謂啦
cd /opt/dnscrypt-proxy/
cp example-dnscrypt-proxy.toml dnscrypt-proxy.toml
#選擇性修改fallback dns如
fallback_resolver = '114.114.114.114:53'
#開啟分流文件
#曾經在不分流的情況下用了一年左右,奈何網絡持續惡化,現在不分流體驗會很差
#中國域名來自https://github.com/felixonmars/dnsmasq-china-list/blob/master/accelerated-domains.china.conf
#需要替換成dnscrypt-proxy的格式
forwarding_rules = '/home/fred/Programs/dnscrypt-proxy/forwarding-rules.txt'
./dnscrypt-proxy
#出現dnscrypt-proxy is ready即為成功,可以先Ctrl+C關閉
#执行下面命令使普通用戶也能運行dnscrypt-proxy
setcap cap_net_bind_service=+pe dnscrypt-proxy
#下面設置本機dns解析方法一:
cp /etc/resolv.conf /etc/resolv.conf.backup
nano /etc/resolv.conf
#文件內容如下
nameserver 127.0.0.1
options edns0 single-request-reopen
#下面設置本機dns解析方法二:
#右擊網絡連接圖標,選擇“編輯網絡連接”,選擇網絡,點齒輪圖標。
#在“IPv4設定”選項卡,Method選“只用自動(DHCP)位址”
#DNS servers填入127.0.0.1, 8.8.4.4,按“儲存”。
#右擊網絡連接圖標,反選啟用網絡,再勾選啟用網絡。
#設置完成,測試解析
./dnscrypt-proxy -resolve ft.shaman.eu.org
#如果返回了IP就說明OK

#自動啟動我都是用的xfce的啟動程序,位於
#應用程式選單/設定值/工作階段與初始啟動/應用程式自動啟動/加入
#指令框輸入/opt/dnscrypt-proxy/dnscrypt-proxy
#NetworkManager會在開機時生成重寫/etc/resolv.conf
#所以需要在NetworkManager的IPV4設定中指定127.0.0.1為dns服務器
#或者
#給resolv.conf上把鎖
chattr +i /etc/resolv.conf
#解鎖
chattr -i /etc/resolv.conf

如果想分享dnscrypt-proxy服務給局域網用戶,可以修改dnscrypt-proxy.toml中的監聽地址為['0.0.0.0:53']。然後開啟防火牆的53端口。

部分配置示例

#程序日誌
log_file = '/home/ft/Programs/dnscrypt-proxy/log.log'

#解析日誌
[query_log]
file = '/home/ft/Programs/dnscrypt-proxy/query.log'
ignored_qtypes = ['AAAA', 'DNSKEY', 'NS']

#域名黑名單
[blocked_names]
blocked_names_file = '/home/ft/Programs/dnscrypt-proxy/mybase_blocked-names.txt'
#此處使用的黑名單來自 https://download.dnscrypt.info/blacklists/domains/

#NextDNS 解析
[static]
  [static.'NextDNS-12abcd']
  stamp = 'sdns://AgEAAAAAAAAAAAAOZG5zLm5leHRkbnMuaW8HLzc3WiXnZO'
#使用 NextDNS 時還要設置 server_names
server_names = ['NextDNS-12abcd']

值得提醒的是,如果你使用 BT 下載,那麼很多黑名單是禁止 trackers 相關域名的,記得禁用這一條#tracker.*。自定義的 DNS 服務器可以使用 Online DNS Stamp calculator 來生成簽章。

不再實用的配置

安裝dnscrypt-proxy並新建一個執行用戶

sudo dnf install dnscrypt-proxy
sudo adduser -m -N  -r -s /bin/false dnscrypt

安裝完成後可以從/usr/share/dnscrypt-proxy/dnscrypt-resolvers.csv的第一列挑選一個服務商,我嘗試用香港的發現連接不上,於是選擇法國cs-fr。嘗試運行dnscrypt-proxy:

sudo dnscrypt-proxy -u dnscrypt -R cs-fr

我的桌面是Xfce,所以設置DNS很方便。找到程序/設定值/網路連線,選中需要編輯的網路點編輯。在IPv4設定面板中,如果你之前方法是“自動(DHCP)”,則變更方法為“只用自動(DHCP)位址”,並在DNS伺服器一欄填入127.0.0.1。如果之前就有固定IP,則只需要把DNS伺服器一欄改為127.0.0.1即可。多個DNS伺服器可以用半角逗號隔開。

如果沒有桌面環境,要設置DNS的話可以參考The adventurous can edit the appropriate script in /etc/sysconfig/network-scripts/. If you don't have NetworkManager installed, editing /etc/resolv.conf would work too.

重啟網絡服務已使剛剛新設置的DNS生效。可以使用dig驗證當前dns,出現SERVER: 127.0.0.1#53即說明成功。

sudo systemctl restart network.service
dig ft.wupo.info

設置自動重啟也很簡單,新建文件/etc/systemd/system/dnscrypt.service,內容如下:

[Unit]
Description=dnscrypt - Encrypted DNS service provided by OpenDNS
After=NetworkManager.service

[Service]
ExecStart=/usr/sbin/dnscrypt-proxy -u dnscrypt -R cs-fr
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=basic.target

重啟系統守護

sudo systemctl daemon-reload

添加dnscrypt到開啟啟動

sudo systemctl enable dnscrypt.service

當然你也可以手動通過systemctl命令來啟動和停止dnscrypt-proxy,像這樣:

sudo systemctl start dnscrypt.service

參考鏈接:Lucid Electric Dreams: Setting up dnscrypt on Fedora

本文更新於 2024/10/17。

分類
网站

未備案域名被拒絕解析緊急處理

未備案域名的80端口被停止解析,業務被中段。緊急將域名指向香港服務器,並在香港服務器nginx做如下轉發即可:

server {
    server_name manage.wupo.info;
    location / {
        proxy_redirect off;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://1.2.3.4:8888;
    }
    access_log logs/manage.wupo.info_access.log;
}

如果目標地址仍是80,需要注釋掉proxy_set_header Host $host;這句,否則還是訪問不了。

分類
网站

nginx記錄特定請求的日誌

通過nginx的access log可以記錄訪問日誌,如果只想記錄特定的某條請求,例如所有以/get開頭的請求,可以這麼配置:

map $request $loggable {
    ~/get* 1;
    default 0;
}

server {
        listen 8085;
        server_name 127.0.0.1;
        charset utf-8;

        access_log logs/flask.access.log combined if=$loggable;
        location /  { try_files $uri @yourapplication; }
        location @yourapplication {
                include uwsgi_params;
                uwsgi_pass 127.0.0.1:3031;
        }
}

如果要排除,只記錄以/get開頭的請求,map可以這麼寫

map $request $loggable {
    ~/get* 0;
    default 1;
}

修改之後可以通過 tail -f ../logs/flask.access.log實時查看log的變動。

分類
网站

黑屏

我的這塊戴爾S2340Mc屏,黑色時完全就是一面鏡子!為了當鏡子用,我需要一塊黑色。另外div中height設1000%是不行,參考height: 100% not working

浮動無邊黑屏

#!/usr/bin/python3
# -*- coding: utf8 -*-

#dnf install python3-matplotlib
#pip install matplotlib,fire

#指定起始坐標xy、寬度、高度和顏色,來畫一個填充好的矩形
#為了遮擋盜版電影頂部和底部的賭城廣告

import fire,matplotlib

def drawRectangle(x='0',y='0',width='400',length='400',color='black'):
    #"640x400+0+200"
    conf = str(width) + 'x' + str(length) + '+' + str(x) + '+' + str(y)
    # make sure Tk backend is used
    matplotlib.use("TkAgg")  
    import matplotlib.pyplot as plt
    # turn navigation toolbar off
    plt.rcParams['toolbar'] = 'None'
    plt.rcParams['figure.facecolor'] = color
    # create a figure and subplot
    fig, ax = plt.subplots(figsize=(2,2))
    #remove margins
    fig.subplots_adjust(0,0,1,1)
    # turn axes off
    ax.axis("off")
    # show image
    # im = plt.imread("black.png")
    # ax.imshow(im)
    
    # remove window frame
    fig.canvas.manager.window.overrideredirect(1)
    plt.get_current_fig_manager().window.wm_geometry(conf)
    plt.show()
    
#drawRectangle('10','980')

if __name__ == '__main__':
    fire.Fire(drawRectangle)
    
#默認在屏幕左上角生成一個400*400的黑屏
python drawRectangle.py
#在左下角(0,980)生成一個128*72的紅屏
python drawRectangle.py 0 980 128 72 red

本文更新於 2018/07/23。

分類
程序

Flask簡易搭建

最近用python寫了個小服務,既然都用python寫了,不如順便用python的服務器來運行,簡單搜索後決定用Flask+uwsgi+nginx來實現。virtualenv的安裝就不多說了。

#新建一個python3虛擬環境emailApp
mkdir pythons
cd pythons
virtualenv --python=/usr/local/bin/python3.5 emailApp
source emailApp/bin/activate
#安裝uwsgi和Flask
pip install uwsgi Flask
cd emailApp
#新建emailApp1.py
#!/root/42/pythons/emailApp/bin/python
# -*- coding: utf8 -*-

from flask import Flask,request
import json

app = Flask(__name__)

def getTS():
    TS={}

    nowTS=int(time.time())
    TS['当前时间戳']=str(nowTS)
    localTimeString=time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(int(nowTS)))
    TS['服務器時間']=str(localTimeString)
    gmtTimeString=time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime(int(nowTS)))
    TS['GMT時間']=str(gmtTimeString)
    localTSToday=int(time.mktime(time.strptime(localTimeString[:10], '%Y-%m-%d')))
    TS['服務器今天時間戳']=str(localTSToday)
    print('服務器今天時間戳'+str(localTSToday))
    TS['GMT今天時間戳']=str(localTSToday+time.timezone)

    return TS

@app.route('/')
def hello_world():
    return 'Good luck!'

@app.route('/taskCms/service/getTS')
def checkTS():
    TS = getTS()


    return json.dump(TS)
            
if __name__ == '__main__':
#     app.debug = True
#     app.run(host='0.0.0.0',port=8080)
    app.run()
#此時執行
python emailApp1.py
#即可在本地http://127.0.0.1:5000/訪問到服務了。
#Ctrl+C關閉測試,新建nginx站點配置文件emailApp.conf
#nginx站點配置通常在/etc/nginx/conf.d
server {
        listen 8042;
        server_name 127.0.0.1;
        charset utf-8;

        location /  { try_files $uri @yourapplication; }
        location @yourapplication {
                include uwsgi_params;
                uwsgi_pass 127.0.0.1:3031;
        }
}
#測試nginx配置文件是否有誤
nginx -t
#重新加載nginx
nginx -s reload
#此時訪問你的ip加端口號8042,出現502 Bad Gateway則證明nginx已配置好
#若出現訪問超時則可能是有防火牆阻擋
#接下來在項目目錄下新建config.ini作為uwsgi的配置文件
[uwsgi]
socket = 127.0.0.1:3031
chdir = /root/42/pythons/emailApp
master = true
binary-path = /root/42/pythons/emailApp/bin/uwsgi
virtualenv = /root/42/pythons/emailApp
module = emailApp1:app
processes = 2
threads = 4
#使用uwsgi運行Flask程序
/root/42/pythons/emailApp/bin/uwsgi --ini /root/42/pythons/emailApp/config.ini
#如果遇到uwsgi: error while loading shared libraries: libpcre.so.1可嘗試
ln -s /usr/local/lib/libpcre.so.1 /lib64
#正常的話此時應該能通過8042訪問到服務
#開機啟動我使用的centos6自帶的Upstart
nano /etc/init/uwsgi.conf
# simple uWSGI script

description "uwsgi tiny instance"
start on runlevel [2345]
stop on runlevel [06]

respawn

exec /root/42/pythons/emailApp/bin/uwsgi --ini /root/42/pythons/emailApp/config.ini

最後可以通過screen執行uwsgi,然後退出服務器。這樣就完成了一個簡單Flask項目的搭建。Flask就是簡單快速。

如果是通過Upstart自動啟動的,可以通過initctl reload uwsgi和initctl restart uwsgi來重啟uwsgi。


Connection reset by peer鏈接被中斷

過了幾天發現接口不穩定,有時能正常返回數據,有時出現Connection reset by peer鏈接被中斷。從firebug里看發現數據返回有時是先返回個0,就是什麼也沒有然後真是數據才回來,這是瀏覽器已經報錯了。此時可嘗試在uwsgi配置中增加buffer-size=65535和post-buffering = 1。以及在nginx的conf中設置

http{
    ...
    keepalive_timeout  0;

    uwsgi_read_timeout 86400;
    uwsgi_send_timeout 86400;
    ....

}

本文更新於 2017/03/09。

分類
其它

意大利簽證

意大利簽證中文官網里詳細的申請步驟、所需材料和所需材料格式(如保險單的要求),不必去旅遊網站亂搜。

條件方面簡單概括下要求就是要有一份穩定的工作和足以支付本次旅行的資金,行程單要認真寫。首次辦理申根簽證需要在簽證中心錄十指指紋,所以沒有錄過指紋的就不要想代辦了。辦理順序就是自己根據所需資料準備材料》去簽證中心遞交材料並錄指紋》等待大使館發回簽證到簽證中心》領取簽證。順便一提,夫妻通行也是和單個辦理是一樣的,各自準備自己的結婚證複印件,即使是相同的材料也都需要各有一份。

我們的簽證辦理的挺順利的,雖然中間接到電話調查有點怕怕,但還好順利出簽。電話調查的應對秘訣就是誠實。

…… 2/16/2017.(到簽證中心交材料錄指紋)

Visa application ref no. SHEZ/xxxxxx/xxx/xx is being processed at the Italy Embassy/Consulate on 2/17/2017.(材料送抵大使館)

Visa application ref no. SHEZ/xxxxxx/xxx/xx – Your application has been processed and is in transit to the Italy Visa Application Centre on 2/22/2017.(大使館處理完畢)

Visa application ref no. SHEZ/xxxxxx/xxx/xx – Your processed passport has been dispatched to the Italy Visa Application Centre on 2/24/2017 and is ready for collection.(簽證送抵簽證中心)