wuguokai / blog Goto Github PK
View Code? Open in Web Editor NEW个人学习博客
个人学习博客
本文分享下我在CentOS7上安装Shadowsocks 客户端
的的过程。
pip是Python的包管理工具,我们接下来是使用pip安装的Shadowsocks。
这里介绍两种方法:
1. 通过yum管理工具安装:
yum install -y pip
2. 可能你的镜像库没有这个包,那么可以手动安装:
curl "https://bootstrap.pypa.io/get-pip.py" -o "get-pip.py"
python get-pip.py
pip install --upgrade pip
pip install shadowsocks
新建配置文件/etc/shadowsocks.json
:
vi /etc/shadowsocks.json
然后填写以下内容:
{
"server":"x.x.x.x", #你的 ss 服务器 ip
"server_port":0, #你的 ss 服务器端口
"local_address": "127.0.0.1", #本地ip
"local_port":0, #本地端口
"password":"password", #连接 ss 密码
"timeout":300, #等待超时
"method":"aes-256-cfb", #加密方式
"workers": 1 #工作线程数
}
nohup sslocal -c /etc/shadowsocks.json /dev/null 2>&1
若需要配置自启动,则再运行:
echo " nohup sslocal -c /etc/shadowsocks.json /dev/null 2>&1 &" /etc/rc.local
运行 curl --socks5 127.0.0.1:1080 http://httpbin.org/ip
, 如下返回你的ss服务器ip,则说明Shadowsocks客户端启动成功。
{
"origin": "x.x.x.x" #你的 ss 服务器 ip
}
到这里只是安装好了shadowsocks客户端,但是linux系统下的命令行却还不能够走代理,接下来还需要安装Privoxy。
Shadowsocks 是一个 socket5 服务,我们需要使用 Privoxy 把流量转到 http/https 上。
没有wget
命令的可以使用yum install wget
命令安装。
wget http://www.privoxy.org/sf-download-mirror/Sources/3.0.26%20%28stable%29/privoxy-3.0.26-stable-src.tar.gz
tar -zxvf privoxy-3.0.26-stable-src.tar.gz
cd privoxy-3.0.26-stable
建议在下载前去 Privoxy官网下载页 检查一下版本。
Privoxy 不建议使用 root 用户运行,所以我们这里新建一个用户:
useradd privoxy
autoheader && autoconf
./configure
make && make install
如果没有autoconf命令的,同样需要执行yum install autoconf
命令安装。
编辑/usr/local/etc/privoxy/config文件
vi /usr/local/etc/privoxy/config
找到以下两句,确保没有注释掉:
listen-address 127.0.0.1:8118 # 8118 是默认端口,不用改,下面会用到
forward-socks5t / 127.0.0.1:0 . # 这里的端口写 shadowsocks 的本地端口(注意最后那个 . 不要漏了)
privoxy --user privoxy /usr/local/etc/privoxy/config
vi /etc/profile
在上面添加这两句:
export http_proxy=http://127.0.0.1:8118 #这里的端口和上面 privoxy 中的保持一致
export https_proxy=http://127.0.0.1:8118
然后执行source /etc/profile
使配置生效。
curl www.google.com
返回一大堆 HTML 则说明你成功了。
如果不能访问,请重启机器,依次打开 shadowsocks 和 privoxy 再测试。
nohup sslocal -c /etc/shadowsocks.json /dev/null 2>&1 &
privoxy --user privoxy /usr/local/etc/privoxy/config
如果不需要用代理了,记得把/etc/profile
里的配置注释掉,不然会一直走代理流量。
拼接授权的client_id和client_secret,并使用base64编码之后作为请求头:
先拼接:client_id:client_secret 如 : client:secret
使用任意base64工具编码: Y2xpZW50OnNlY3JldA==
最后在请求头添加: "Authorization" : "Basic Y2xpZW50OnNlY3JldA=="
使用post请求:
url: http://localhost:8020/oauth/token?grant_type=password&username=admin&password=admin
获取结果:
当我们在开发react-native项目时,JS端与原生端的通信是很必要的。但是在iOS开发中我发现很难找到使用RCTResponseSenderBlock方式回调一组数据的方式,找了很多半天,终于找到一种方式,所以记录下来。
@objc func getConfigData(_ callback: RCTResponseSenderBlock){
let bunderManager:BundleManager? = BundleManager.getBundleManager()
let appModel:AppModel = (bunderManager?.getAppModel())!
let token:String = appModel.token!
let serverUrl:String = appModel.url!
let loginUrl:String = serverUrl.replacingOccurrences(of: "/mobileCloud/v1/bundle", with: "/oauth/oauth/authorize?response_type=token&state=&client_id=mobile")
let appVetsionId:String = appModel.id!
let homeDirectory:String = NSHomeDirectory()+"/Documents"
//cllback回调键值对组
callback([
["serverUrl":serverUrl,"token":token,"loginUrl":loginUrl,"appVetsionId":appVetsionId,"homeDirectory":homeDirectory]
])
}
注:参数callback前面的下划线是为了接受JS端传过来的参数不用前缀,swift的方法参数在调用时正常时需要加上参数前缀的。如:
bunderManager?.checkBundleConfigUpdate(callback: callback)
RCT_EXTERN_METHOD(getConfigData:(RCTResponseSenderBlock)callback)
这样,JS端就可以调用到这个方法了。
NativeModules.NativeManager.getConfigData((back) => {
var REQUEST_URL = back.serverUrl + "/getData/"+back.appVetsionId;
var token = back.token;
});
JS端就通过这样拿到原生端的数据组了。
使用callback方式调用键值对组数据的方式就是这样。iOS开发中也可以使用promises的方式回调一个数组,但是这样JS端就必须使用async和await的方式调用,比较麻烦,当然也有优势。之后会再发文说明promises的调用方式。
使用过程中有问题的可以再私信我。
springfox-swagger2 创建新的group,只需要实例化一个新的Docket实例,配置groupName,在请求时。使用/v2/api-docs?group=test就可以请求这个group对应的swagger json。
@Bean
public Docket customImplementation() {
ApiInfo apiInfo = ApiInfo.DEFAULT;
apiInfo = new ApiInfo(apiInfo.getTitle(), "my descript", apiInfo.getVersion(),
apiInfo.getTermsOfServiceUrl(), apiInfo.getContact(), apiInfo.getLicense(), apiInfo.getLicenseUrl());
return new Docket(DocumentationType.SWAGGER_2)
.groupName("test")
.apiInfo(apiInfo);
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.