下载、配置clash
下载
wnlen/clash-for-linux: clash-for-linux
下载项目
$ git clone https://github.com/wnlen/clash-for-linux.git
进入到项目目录,编辑.env文件,修改变量CLASH_URL的值。
$ cd clash-for-linux
$ vim .env
把其中的export CLASH_URL=''改成自己的机场的订阅链接。CLASH_SECERT为空即可。
启动程序
直接运行脚本文件start.sh
- 进入项目目录
$ cd clash-for-linux
- 运行启动脚本
$ sudo bash start.sh
正在检测订阅地址...
Clash订阅地址可访问! [ OK ]
正在下载Clash配置文件...
配置文件config.yaml下载成功! [ OK ]
正在启动Clash服务...
服务启动成功! [ OK ]
Clash Dashboard 访问地址:http://<ip>:9090/ui
Secret:xxxxxxxxxxxxx
请执行以下命令加载环境变量: source /etc/profile.d/clash.sh
请执行以下命令开启系统代理: proxy_on
若要临时关闭系统代理,请执行: proxy_off
$ source /etc/profile.d/clash.sh
$ proxy_on
更改端口
vim conf/config.yaml
# 把proxy端口改成12378
port: 12378
重启程序
如果需要对Clash配置进行修改,请修改 conf/config.yaml 文件。然后运行 restart.sh 脚本进行重启。
注意: 重启脚本
restart.sh不会更新订阅信息。
停止程序
- 进入项目目录
$ cd clash-for-linux
- 关闭服务
$ sudo bash shutdown.sh
服务关闭成功,请执行以下命令关闭系统代理:proxy_off
$ proxy_off
然后检查程序端口、进程以及环境变量http_proxy|https_proxy,若都没则说明服务正常关闭。
使用
git 使用配置的端口
只给 Git 走代理,不影响其他程序
git config --global http.proxy "http://127.0.0.1:12378"
git config --global https.proxy "http://127.0.0.1:12378"
然后就能正常:
git clone https://github.com/xxx/yyy.git
取消 Git 代理
git config --global --unset http.proxy
git config --global --unset https.proxy
python程序中使用
import os
os.environ['HTTP_PROXY'] = 'http://127.0.0.1:12378'
os.environ['HTTPS_PROXY'] = 'http://127.0.0.1:12378'
import yfinance as yf
from curl_cffi import requests
import os
session = requests.Session(impersonate="chrome")
os.environ['HTTP_PROXY'] = 'http://127.0.0.1:12378'
os.environ['HTTPS_PROXY'] = 'http://127.0.0.1:12378'
def read_data(ticker, start_date, end_date, interval):
df = yf.download(tickers=ticker, start=start_date, end=end_date, interval=interval,session=session)
df['ret'] = df['Close'].pct_change()
df['log_ret'] = np.log(df['Close']) - np.log(df['Close'].shift(1))
df = df.dropna()
return df
df = read_data('AAPL', "2010-01-01", "2011-12-31", interval='1d')