shadowsocks:

1
2
3
apt-get update
apt-get install -y python-pip python-m2crypto
pip install shadowsocks

Debian / Ubuntu:

1
2
apt-get install python-pip
pip install shadowsocks

CentOS:

1
2
yum install python-setuptools && easy_install pip
pip install shadowsocks

启动:

1
ssserver -p 3000 -k password -m aes-128-cfb -d start

停止:

1
ssserver -d stop

二级COW架设源码:https://github.com/cyfdecyf/cow 安装过程:

1
curl -L git.io/cow  bash

配置文件路径:

1
vim ~/.cow/rc

手工安装: http://dl.chenyufei.info/cow/0.9.6/cow-linux64-0.9.6.gz 配置文件: https://raw.github.com/cyfdecyf/cow/0.9.6/doc/sample-config/rc /root/.cow/rc

二级proxy部署 第二篇

上面写的是shadowsocks+cow实现二级proxy,接下来用一种简单的方式来实现二级proxy: 首先,一级proxy开启ssh服务。 二级proxy上用SSH端口转发:

1
ssh -N -f -D 0.0.0.0:8888 username@ssh.malu.me

输入密码,这段命令意思是连接远程主机ssh.malu.me,然后在本地0.0.0.0地址、端口8888上开启socket5监听。 这样只要访问二级proxy上的socket5代理就能穿过两层代理了。

二级proxy部署 自动脚本

相关参数根据实际修改

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/expect -f
set timeout 30
set host ssh.malu.me
set name root
set passwd userpasswd
set port 22
set lisenport 8888
spawn sudo /etc/init.d/ssh start
expect "*#"
spawn killall ssh
expect "*#"
spawn ssh -NfR 1234:localhost:2222 $host -l $name -p $port
expect {
"yes/no" { send "yes\r"; exp_continue }
"password:" { sleep 1;send "$passwd\r" }
}
expect "*#"
spawn ssh $host -l $name -p $port
expect {
"yes/no" { send "yes\r"; exp_continue }
"password:" { sleep 1;send "$passwd\r" }
}
expect "]$"
sleep 1
send "ssh -N -f -D 0.0.0.0:$lisenport root@localhost -p1234\r"
expect {
"yes/no" { send "yes\r"; exp_continue }
"password:" { sleep 1;send "$passwd\r" }
}
expect "]$"
sleep 1
send "exit\r"
expect eof
exit

二级proxy部署 - 直连windows

windows下安装openssh 下载地址:https://github.com/PowerShell/Win32-OpenSSH/releases 1.解压OpenSSH-Win64.zip到C:\Program Files\OpenSSH目录下,在DOS窗口进入OpenSSH目录 2.安装SSH host keys

1
.\ssh-keygen.exe -A

3.打开防火墙22端口 4.安装SSHD服务并在服务窗口找到名为“SSHD”的服务,右键将其启动,并设置为随操作系统自动启动

1
.\sshd.exe install

也可以直接启动:

1
.\sshd.exe

5.查看启动端口,如果需要监听外网,可以修改当前目录sshd_config文件

1
netstat -ant

sshd_config:

1
ListenAddress 0.0.0.0

内网穿透

根据二级proxy的原理,实质上是在两台服务器之间实现端口转发。 那么对应内网的服务器,只要能访问外网,那么利用SSH隧道端口映射就能实现内网穿透。 首先需要一台能远程登录的外网服务器。 然后内网服务器上执行:

1
ssh -gCNfR 80:localhost:8080 ssh.malu.me -l root -p 22

g:在-L/-R/-D参数中,允许远程主机连接到建立的转发的端口,如果不加这个参数,只允许本地主机建立连接。 (-g参数如果不生效,其实这是ssh默认的安全策略所致,需要在服务端/etc/ssh/sshd_config 添加 gatewayports yes 重启sshd即可) C:压缩数据传输。 N:不执行脚本或命令,通常与-f连用。 f:后台认证用户/密码,通常和-N连用,不用登录到远程主机。 -R 本地端口:目标IP:目标端口 将远程主机(服务器)的某个端口转发到本地端指定机器的指定端口. 工作原理是这样的, 远程主机上分配了一个 socket 侦听 port 端口, 一旦这个端口上有了连接, 该连接就经过安全通道转向出去, 同时本地主机和 host 的 hostport 端口建立连接. 可以在配置文件中指定端口的转发. 只有用 root 登录远程主机才能转发特权端口. IPv6 地址用另一种格式说明: port/host/hostport -L 本地端口:目标IP:目标端口 将本地机(客户机)的某个端口转发到远端指定机器的指定端口. 工作原理是这样的, 本地机器上分配了一个 socket 侦听 port 端口, 一旦这个端口上有了连接, 该连接就经过安全通道转发出去, 同时远程主机和 host 的 hostport 端口建立连接. 可以在配置文件中指定端口的转发. 只有 root 才能转发特权端口. IPv6 地址用另一种格式说明: port/host/hostport -D IP:port 指定一个本地机器 “动态的’’ 应用程序端口转发. 工作原理是这样的, 本地机器上分配了一个 socket 侦听 port 端口, 一旦这个端口上有了连接, 该连接就经过安全通道转发出去, 根据应用程序的协议可以判断出远程主机将和哪里连接. 目前支持 SOCKS4 协议, 将充当 SOCKS4 服务器. 只有 root 才能转发特权端口. 可以在配置文件中指定动态端口的转发.

serveo

官网:https://serveo.net eg:

1
ssh -R testname:80:localhost:80 serveo.net -o ServerAliveInterval=60

文档:https://www.jianshu.com/p/d0b3991a9ce1

zerotier

官网:https://www.zerotier.com 文档:https://www.zerotier.com/manual 国内服务:https://www.kancloud.cn/baoji\_enku/tx\_ip\_01/936021

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 启动
zerotier-one -d

# 获取地址和服务状态
zerotier-cli status

# 加入、离开、列出网络
zerotier-cli join <Network ID>
zerotier-cli leave <Network ID>
zerotier-cli listnetworks

# 重启
systemctl restart zerotier-one

# moon
主机需要公网开放9993端口

报错:Cannot connect to Zerotier service

查看9993端口是否被占用

1
netstat -ab

二级proxy部署 - 轻量级SSH安装

下载地址:https://matt.ucc.asn.au/dropbear/ dropbear的编译安装:

1
2
3
# ./configure --prefix=/usr/local/dropbear --sysconfdir=/etc/dropbear --disable-pam 
# make PROGRAMS="dropbear dbclient dropbearkey dropbearconvert scp"
# make PROGRAMS="dropbear dbclient dropbearkey dropbearconvert scp" install

加入环境变量:

1
export PATH=/usr/local/dropbear/bin:/usr/local/dropbear/sbin:$PATH

使用方法:

1
./n1.sh eth0

cat n1.sh

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/bin/bash
eth=$1
RXpre=$(cat /proc/net/dev grep $eth tr : " " awk '{print $2}')
TXpre=$(cat /proc/net/dev grep $eth tr : " " awk '{print $10}')
sleep 1
RXnext=$(cat /proc/net/dev grep $eth tr : " " awk '{print $2}')
TXnext=$(cat /proc/net/dev grep $eth tr : " " awk '{print $10}')
#clear
echo -e "\t RX `date +%k:%M:%S` TX"
RX=$((${RXnext}-${RXpre}))
TX=$((${TXnext}-${TXpre}))

if [[ $RX -lt 1024 ]];then
RX="${RX}B/s"
elif [[ $RX -gt 1048576 ]];then
RX=$(echo $RX awk '{print $1/1048576 "MB/s"}')
else
RX=$(echo $RX awk '{print $1/1024 "KB/s"}')
fi

if [[ $TX -lt 1024 ]];then
TX="${TX}B/s"
elif [[ $TX -gt 1048576 ]];then
TX=$(echo $TX awk '{print $1/1048576 "MB/s"}')
else
TX=$(echo $TX awk '{print $1/1024 "KB/s"}')
fi

echo -e "$eth \t $RX $TX "

iftop

1、iftop界面相关说明 界面上面显示的是类似刻度尺的刻度范围,为显示流量图形的长条作标尺用的。 中间的<= =>这两个左右箭头,表示的是流量的方向。

1
2
3
4
5
6
7
TX:发送流量 
RX:接收流量
TOTAL:总流量

cum:运行iftop到目前时间的总流量
peak:流量峰值
rates:分别表示过去 2s 10s 40s 的平均流量

2、iftop相关参数

1
2
3
4
5
6
7
8
9
10
11
-i设定监测的网卡,如:# iftop -i eth1 
-B 以bytes为单位显示流量(默认是bits),如:# iftop -B
-n使host信息默认直接都显示IP,如:# iftop -n
-N使端口信息默认直接都显示端口号,如: # iftop -N
-F显示特定网段的进出流量,如# iftop -F 10.10.1.0/24或# iftop -F 10.10.1.0/255.255.255.0
-h(display this message),帮助,显示参数信息
-p使用这个参数后,中间的列表显示的本地主机信息,出现了本机以外的IP信息;
-b使流量图形条默认就显示;
-f这个暂时还不太会用,过滤计算包用的;
-P使host信息及端口信息默认就都显示;
-m设置界面最上边的刻度的最大值,刻度分五个大段显示,例:# iftop -m 100M

3、进入iftop画面后的一些操作命令(注意大小写)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
按h切换是否显示帮助; 
按n切换显示本机的IP或主机名;
按s切换是否显示本机的host信息;
按d切换是否显示远端目标主机的host信息;
按t切换显示格式为2行/1行/只显示发送流量/只显示接收流量;
按N切换显示端口号或端口服务名称;
按S切换是否显示本机的端口信息;
按D切换是否显示远端目标主机的端口信息;
按p切换是否显示端口信息;
按P切换暂停/继续显示;
按b切换是否显示平均流量图形条;
按B切换计算2秒或10秒或40秒内的平均流量;
按T切换是否显示每个连接的总流量;
按l打开屏幕过滤功能,输入要过滤的字符,比如ip,按回车后,屏幕就只显示这个IP相关的流量信息;
按L切换显示画面上边的刻度;刻度不同,流量图形条会有变化;
按j或按k可以向上或向下滚动屏幕显示的连接记录;
按1或2或3可以根据右侧显示的三列流量数据进行排序;
按<根据左边的本机名或IP排序;
按>根据远端目标主机的主机名或IP排序;
按o切换是否固定只显示当前的连接;
按f可以编辑过滤代码
按!可以使用Shell命令
按q退出监控。

首先2台主机都要安装ssh服务端:

1
apt-get install openssh-server

如果有需要开启root远程登录,可以修改/etc/ssh/sshd_config 找到PermitRootLogin no一行,改为PermitRootLogin yes

A要控制B

A主机:外网,ip:123.123.123.123,sshd端口:2221 B主机:内网,sshd端口:2223 无论是外网主机A,还是内网主机B都需要跑ssh daemon

1.首先在B上执行

1
ssh -NfR 1234:localhost:2223 user1@123.123.123.123 -p2221

这句话的意思是将A主机的1234端口和B主机的2223端口绑定,相当于远程端口映射(Remote Port Forwarding)。

2.这时在A主机上sshd会listen本地1234端口

1
ssh localhost -p1234

自动登录

方法1.在内网B主机上生产公钥和私钥

1
$ ssh-keygen

…(一直按Enter,最后在~/.ssh/下生成密钥)

1
2
$ ls ~/.ssh/
id_rsa id_rsa.pub known_hosts

复制B主机上生成的id_rsa.pub公钥到外网A主机上,并将内容加入到~/.ssh/authorized_keys中 方法2.直接在B主机上执行

1
$ ssh-copy-id user1@123.123.123.123

SSH-keygen 根据私钥生成公钥

1
$ ssh-keygen -y -f id_rsa

用Autossh保持ssh反向隧道一直连接

1
autossh -NfR 1234:localhost:2223 user1@123.123.123.123 -p2221

注:默认autossh没有配置环境变量,需要自己设定

1
2
3
4
5
export AUTOSSH_PIDFILE=/var/run/autossh.pid
export AUTOSSH_POLL=60
export AUTOSSH_FIRST_POLL=30
export AUTOSSH_GATETIME=0
export AUTOSSH_DEBUG=1

为了保证开机时就启动,需要把以上环境变量写入/etc/profile中 然后在/etc/init/rc.local中添加:

1
autossh -NfR 1234:localhost:2223 user1@123.123.123.123 -p2221

使用curl让反向隧道保持连接

在A主机上配置计划任务:

1
*/1 * * * * netstat -lnt4pgrep "sshd: root"awk '{print $4}'awk -F ':' '{print $2}'xargs -i curl localhost:{}

定时向本地的隧道端口请求数据

其他技巧

默认只能通过ssh localhost -p来连接,如果要实现远程登录内网B主机,可以在A主机上再开一个本地端口转发:

1
ssh -g -L 80:localhost:1234 localhost

远程就可以通过A主机的80端口去连接B主机了。 我们甚至可以启动socket5隧道:

1
ssh -N -f -D 0.0.0.0:8888 root@localhost -p1234

ssh 指定私钥文件:

1
ssh -i /root/.ssh/idrsa root@malu.me -p 2111

ssh取消主机密钥检查

1.使用ssh连接远程主机时加上“-o StrictHostKeyChecking=no”的选项,如下:

1
ssh  -o StrictHostKeyChecking=no  192.168.xxx.xxx

2.一个彻底去掉这个提示的方法是,修改/etc/ssh/ssh_config文件(或$HOME/.ssh/config)中的配置,添加如下两行配置:

1
2
StrictHostKeyChecking no
UserKnownHostsFile /dev/null

Vim乱码处理

/etc/vim/vimrc文件末尾添加 set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936

vim 去掉自动注释和自动回车

取消

1
:set paste

恢复

1
:set paste!

操作

vim删除

1
2
3
4
5
6
7
x        删除当前光标下的字符
dw 删除光标之后的单词剩余部分。
d$ 删除光标之后的该行剩余部分。
dd 删除当前行。

c 功能和d相同,区别在于完成删除操作后进入INSERT MODE
cc 也是删除当前行,然后进入INSERT MODE

vim撤销、恢复

1
2
u   撤销上一步的操作
Ctrl+r 恢复上一步被撤销的操作

快速移动光标

1
w    移动到下一个单词

行编辑

1
Ctrl+v,hjkl,Shift+i

vim折叠

1
2
3
set foldmethod=syntax 或者是其它方法。设置好了之后可以用 zM 和 zR 来打开或关闭所有的折叠。

:h fold-commands 可以用来查看有关折叠的命令,所有的折叠命令全部由 z 开关。比如 zo 和 zc 用来打来和关闭折叠(助记符是 open 和 close)。

设置行号

1
:set number

设置相对行号

1
:set relativenumber

查找时忽略大小写

1
set ic

取消设置

1
:set no*****

每行最后添加字符

1
:%s/$/需要追加的字符

配置文件

编辑~/.vimrc文件

vim中文乱码

1
set encoding=utf-8

vim记录上次编辑的位置(编辑~/.vimrc文件)

1
2
3
4
autocmd BufReadPost *
\ if line("'\"") > 0 && line ("'\"") <= line("$")
\ exe "normal g'\""
\ endif

开启虚拟主机

1.编辑文件 F:\wamp\bin\apache\apache2.4.9\conf\httpd.conf 去掉httpd-vhosts.conf的注释

1
2
# Virtual hosts
Include conf/extra/httpd-vhosts.conf

把Directory修改成如下

1
2
3
4
5
<Directory />
Order Deny,Allow
Deny from all
Allow from all
</Directory>

2.编辑文件 F:\wamp\bin\apache\apache2.4.9\conf\extra\httpd-vhosts.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<VirtualHost *:80>
DocumentRoot D:/00_cloud/server-php
ServerName server-php.com
<Directory "D:/00_cloud/server-php">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

<VirtualHost *:80>
DocumentRoot F:/wamp/www
ServerName localhost
<Directory "F:/wamp/www">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

3.修改 C:\Windows\System32\drivers\etc\hosts 添加

1
127.0.0.1 server-php.com

启动时加载bat

运行: shell:startup -> startup.vbs

1
2
set ws=WScript.CreateObject("WScript.Shell")
ws.Run "C:\auto_run\startup\start.bat /start",0

命令行工具

windows curl

下载地址:https://curl.haxx.se/windows/

计算文件Hash值:

在Windows中可以通过以下方式:

1
2
3
certutil -hashfile yourfilename MD5
certutil -hashfile yourfilename SHA1
certutil -hashfile yourfilename SHA256

而在Linux下,命令为:

1
2
3
md5sum yourfilename
sha1sum yourfilename
sha256sum yourfilename

windows命令行工具 nircmd

下载地址:http://www.nirsoft.net/utils/nircmd.html 关闭监视器:

1
nircmd.exe monitor off

锁屏:

1
nircmd.exe lockws

截屏:

1
nircmd.exe savescreenshotfull "f:\tmp\shot.png"

设置鼠标在屏幕位置:

1
nircmd.exe setcursor 100 50

按鼠标键:

1
2
3
4
5
6
① sendmouse right click 右键鼠标
② sendmouse left click 左键鼠标
③ sendmouse left dblclick 双击鼠标左键
④ sendmouse left down 按下鼠标左键
⑤ sendmouse left up 松开鼠标左键
⑥ sendmouse middle click

工具集

视频下载工具 annie https://github.com/iawia002/annie 视频转码工具 FFmpeg https://www.ffmpeg.org/ 比如mp4转mp3: ffmpeg -i xx.mp4 xx.mp3 tcping https://elifulkerson.com/projects/index.php nircmd,wake_on_lan,GUIPropView http://www.nirsoft.net/utils/index.html 网络唤醒wol https://www.depicus.com/wake-on-lan/wake-on-lan-cmd 设置分辨率 QRes http://www.softpedia.com/progDownload/QRes-Download-618.html

1
QRes.exe /x:1920 /y:1080

windows开启关闭防火墙

1
2
3
NetSh Advfirewall set allprofiles state off   #关闭防火墙
NetSh Advfirewall set allprofiles state on #开启防火墙
Netsh Advfirewall show allprofiles #查看防火墙状态

在 Windows 10 中启用可匿名访问的共享

就是不用输入用户名和密码,直接通过网上邻居可以访问的共享。

1
2
3
4
5
6
7
1、打开本地组策略编辑器(快捷键Win+R,打开运行,输入gpedit.msc,确定);
2、打开:“本地计算机策略->计算机配置->Windows设置->安全设置->本地策略->用户权限分配”;
3、找到:“拒绝从网络访问这台计算机”,将列表中的“Guest”删除;
4、打开:“本地计算机策略->计算机配置->Windows设置->安全设置->本地策略->安全选项”;
5、找到:“网络访问:本地帐户的共享和安全模型”,改为:“仅来宾 - 对本地用户进行身份验证,其身份为来宾”;
6、找到:“网络访问:将 Everyone 权限应用于匿名用户”,改为:“已启用”;
7、找到:“账户:来宾账户状态”,改为:“已启用”;

注意:如果访问共享文件夹时出现“你不能访问此共享文件夹,因为你组织的安全策略阻止未经身份验证的来宾访问,这些策略可帮助保护你的电脑免受网络上不安全设备或者恶意设备的威胁” 需要如下操作:

1
2
3
1、打开本地组策略编辑器(快捷键Win+R,打开运行,输入gpedit.msc,确定);
2、在“计算机配置”中找到“管理模板”->“网络”->“Lanman工作站”;
3、在本地策略编辑器的右侧双击“启用不安全的来宾登录”。选择“已启用”,并点击确定,解决问题。

Win10 开机自动登录

方法一:

1
control userpasswords2

方法二:

1
netplwiz

方法三:

1
rundll32 netplwiz.dll,UsersRunDll

方法四: 创建autologin.reg文件,双击导入

1
2
3
4
5
6
Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon]
"DefaultUserName"="Administrator"
"AutoAdminLogon"="1"
"DefaultPassword"="your_password"

Win10 右键菜单Intel图形属性删除

管理员权限打开cmd,输入

1
regsvr32 /u igfxDTCM.dll

恢复

1
regsvr32 igfxDTCM.dll

windows 删除进程

查看指定端口的连接信息:

1
netstat -ano  findstr "8080"

查看进程列表:

1
tasklist  findstr "java"

通过上面的方式可以查看占用端口号的进程ID:

1
taskkill -PID 进程号 -F

win10

安装

微软官方下载地址:https://www.microsoft.com/zh-cn/software-download/windows10

激活

序列号

1
2
3
4
5
6
7
8
9
10
Home: TX9XD-98N7V-6WMQ6-BX7FG-H8Q99
Home N: 3KHY7-WNT83-DGQKR-F7HPR-844BM
Home Single Language: 7HNRX-D7KGG-3K4RQ-4WPJ4-YTDFH
Home Country Specific: PVMJN-6DFY6-9CCP6-7BKTT-D3WVR
Professional: W269N-WFGWX-YVC9B-4J6C9-T83GX
Professional N: MH37W-N47XK-V7XM9-C7227-GCQG9
Education: NW6C2-QMPVW-D7KKK-3GKT6-VCFB2
Education N: 2WH4N-8QGBV-H22JP-CT43Q-MDWWJ
Enterprise: NPPR9-FWDCX-D2C8J-H872K-2YT43
Enterprise N: DPH2V-TTNVB-4X9Q3-TJR4H-KHJW4

激活步骤:

1
2
3
slmgr /ipk W269N-WFGWX-YVC9B-4J6C9-T83GX
slmgr /skms kms8.msguides.com
slmgr /ato

win11

安装

微软官方下载地址:https://www.microsoft.com/zh-cn/software-download/windows11

绕过 TPM 2.0 检测

Win11 会提示“该电脑无法运行 Win11”解决办法:

1、注册表大法

在安装界面按 Shift+F10,打开命令行界面,输入 regedit 打开注册表,然后定位到:

HKEY_LOCAL_MACHINE\SYSTEM\Setup

创建一个名为“LabConfig”的项,接着在“LabConfig”下创建两个 DWORD 值:

  • 键为“BypassTPMCheck”,值为“00000001”
  • 键为“BypassSecureBootCheck”,值为“00000001”
  • 键为“BypassRAMCheck”,值为“00000001”

保存退出后,上图的提示就消失了,就可以正常安装 Win11。

2、修改 ISO 镜像

如果想通过直接从 Win11 ISO 镜像运行 setup.exe 程序来升级系统,而非全新安装,还有另一种简单的解决方法。 需要找到 Win10 ISO 的 appraiserres.dll 文件,替换 Win11 ISO 的同名文件。完成后,需要使用第三方工具(如 Rufus 或 AnyBurn)重新创建 ISO 镜像,然后再次运行安装文件。

激活

win11激活工具 https://github.com/zbezj/HEU_KMS_Activator

脚本重连蓝牙耳机

首先去该网站下载:蓝牙命令行管理工具 然后打开命令行,输入

1
btdiscovery -s  # 扫描蓝牙设备,需要等待一会

获取到设备的 DEVICE_ADDRESS 和 SERVICE_UUID DEVICE_ADDRESS 是蓝牙设备的mac地址 SERVICE_UUID 是设备的服务ID,比如耳麦是1108,免提网关111E

自动重新连接bat脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
@echo off

rem The following line is needed only if you haven't added Bluetooth Command Line Tools to system PATH
REM set PATH=C:\Program Files (x86)\Bluetooth Command Line Tools\bin;%PATH%

rem Change the following 2 lines to match your device
set DEVICE_ADDRESS=1C:52:16:58:8F:95
set SERVICE_UUID=1108

rem If your device requires PIN code other than '0000', uncomment and change the following line
set PIN=0000

rem Remove the device. Ignoring possible error here
btpair -u -b"%DEVICE_ADDRESS%"

rem Pair the device
btpair -p%PIN% -b"%DEVICE_ADDRESS%"
if errorlevel 1 goto error

rem Enable the service
REM btcom -c -b"%DEVICE_ADDRESS%" -s%SERVICE_UUID%
REM if errorlevel 1 goto error

goto success

rem Allow user to read error message before window is closed
:error
pause
exit

:success
exit

查看AC电源状态

1
WMIC Path Win32_Battery Get BatteryStatus

操作系统中查看硬件制造商和BIOS版本

1
dxdiag

或者cmd里输入:

1
wmic bios get biosversion

1
wmic bios get SMBIOSBIOSVersion

查看磁盘硬件名称

1
wmic diskdrive get caption

查看内存

查看内存信息

1
wmic memorychip

查看内存硬件厂商

1
wmic memorychip get Manufacturer

利用Windows内置工具测试硬盘速度

测试默认磁盘

1
winsat disk

指定磁盘进行测速

1
winsat disk -drive d 

注:请使用管理员权限打开cmd,否则在win10下面最终测试结果会一闪而过

windows下查看wifi信息

进入cmd输入:

1
netsh wlan show interface

Win7下格式化成 FAT32

右键管理员身份打开cmd 如果你格式化的是E盘 输入format E: /fs:fat32 回车后会提示输入卷标,就是指该分区名称

win8远程连接win10

1.账户前面需跟计算机名,如:计算机名\用户名. 2.win10上,运行gpedit.msc-计算机配置-Windows设置-安全设置-本地策略-安全选项-网络访问:本地账户的共享安全模型 设置成:经典-对本地用户进行身份验证,不改变其本来身份

指定用户访问共享samba

清除用户记录:

1
net use \\192.168.1.1 /del

指定用户登录(需要输入密码)

1
net use \\192.168.1.1 /user:malu

携带密码登录:

1
net use \\192.168.1.1 "password" /user:malu /persistent:yes

查看状态:

1
net use

自动登录脚本:

1
2
3
4
@echo off
net use \\192.168.0.1 /delete
net use \\192.168.0.1 "password" /user:malu /persistent:yes
explorer \\192.168.0.1\

指定DNS

1
2
3
4
5
6
7
@echo off
netsh interface ip set dns name="本地连接" source=dhcp
netsh interface ip set dns name="以太网" source=dhcp
netsh interface ip add dns "以太网" 192.168.11.200
netsh interface ip add dns "本地连接" 192.168.11.200
netsh interface ip add dns "以太网" 61.177.7.1 index=2
netsh interface ip add dns "本地连接" 61.177.7.1 index=2

本文记录nvm、node、npm、yarn安装过程

Windows下安装

nvm-windowns下载 https://github.com/coreybutler/nvm-windows/releases

切换nvm安装源:

在 nvm 的安装路径下,找到 settings.txt,在后面加上这两行

1
2
node_mirror: https://npm.taobao.org/mirrors/node/
npm_mirror: https://npm.taobao.org/mirrors/npm/

切换npm安装源:

1
npm config set registry https://registry.npm.taobao.org

Linux下安装

官方地址:https://github.com/creationix/nvm Linux下推荐使用nvm来安装nodejs

安装nvm

1
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.11/install.sh  bash

脚本会自动把以下执行环境写入.bashrc:

1
2
3
export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion

安装nodejs

1
nvm install 10.8.0

国内使用淘宝node镜像,加速nodejs安装过程:

1
2
export NVM_NODEJS_ORG_MIRROR=https://npm.taobao.org/mirrors/node/
nvm install 10.11.0

或者:

1
NVM_NODEJS_ORG_MIRROR=https://npm.taobao.org/mirrors/node/ nvm install 10.11.0

Linux使用淘宝NPM镜像:

编辑 ~/.npmrc,添加

1
registry=https://npm.taobao.org/mirrors/npm/

若不想将本源设置为默认源,只想使用本源安装某个软件包,可在安装包时采用以下用法:

1
npm --registry https://npm.taobao.org/mirrors/npm/ install <packagename>

windows下安装

直接去github下载msi安装包: https://github.com/coreybutler/nvm-windows/releases windows使用淘宝node镜像:

1
nvm node_mirror https://npm.taobao.org/mirrors/node/

windows使用淘宝npm镜像:

1
nvm npm_mirror https://npm.taobao.org/mirrors/npm/

CNPM

安装方法:

1
npm install -g cnpm --registry=https://registry.npm.taobao.org

YARN

下载地址:https://github.com/yarnpkg/yarn/releases 使用文档:https://yarnpkg.com/zh-Hans/docs

升级自身yarn

1
npm install yarn -g

查看yarn版本

1
yarn -v

Yarn 设置淘宝镜像 1.查询当前配置的镜像

1
2
3
yarn config get registry

> https://registry.yarnpkg.com

2.设置成淘宝镜像

1
yarn config set registry http://registry.npm.taobao.org/

3.显示当前安装的全局yarn依赖库

1
yarn global list

npm与yarn CLI 命令比较

npm (v5)

Yarn

npm install

yarn install

(不适用)

yarn install –flat

(不适用)

yarn install –har

npm install –no-package-lock

yarn install –no-lockfile

(不适用)

yarn install –pure-lockfile

npm install [package]

yarn add [package]

npm install [package] –save-dev

yarn add [package] –dev

(不适用)

yarn add [package] –peer

npm install [package] –save-optional

yarn add [package] –optional

npm install [package] –save-exact

yarn add [package] –exact

(不适用)

yarn add [package] –tilde

npm install [package] –global

yarn global add [package]

npm update –global

yarn global upgrade

npm rebuild

yarn install –force

npm uninstall [package]

yarn remove [package]

npm cache clean

yarn cache clean [package]

rm -rf node_modules && npm install

yarn upgrade

异常处理: 使用yarn升级vue cli后显示 ‘vue’ 不是内部或外部命令,也不是可运行的程序

解决办法:把yarn的包执行目录添加到系统环境变量里。 处理方式: 1.执行yarn global dir 显示出yarn安装路径 2.定位到Yarn\bin目录,把该路径复制到系统环境变量Path里

nvm使用方法

列出全部可以安装的版本号

1
nvm ls-remote

(windows下为)

1
nvm list available

安装指定版本nodejs

1
nvm install 9.3.0

切换指定版本,切换效果是全局的

1
nvm use v8.0.0

查看当前使用的版本

1
nvm current

查看本地安装版本,这个命令也能看到当前使用的是哪个版本

1
nvm ls --depth 0

清空模块

1
rm -rf node_modules/ && npm cache clean && npm prune

npm的常用命令:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
npm ci                #使用安装package.lock.json安装,锁定依赖版本

npm -v #显示版本,检查npm 是否正确安装。

npm install express #安装express模块

npm install -g express #全局安装express模块

npm list #列出已安装模块

npm show express #显示模块详情

npm update #升级当前目录下的项目的所有模块

npm update express #升级当前目录下的项目的指定模块

npm update -g express #升级全局安装的express模块

npm uninstall express #删除指定的模块

npm start --prefix path/to/your/app # start时指定路径

生成package.json文件

1
node init

其他安装方式 old

快速安装过程:

1
2
3
4
apt-get install -y nodejs npm
npm config set registry http://registry.npm.taobao.org #使用淘宝源
npm install -g n #安装n模块
n stable#升级到nodejs最新稳定版

n后面也可以跟随版本号比如:

1
2
n v0.10.26
n 0.10.26

编译安装: nodejs下载地址:https://nodejs.org/dist/

1
2
3
4
5
6
wget https://nodejs.org/download/rc/v4.0.0-rc.1/node-v4.0.0-rc.1.tar.gz
tar -zxvf node-v4.0.0-rc.1.tar.gz
cd node-v4.0.0-rc.1
./configure
make && make install
node -v

源码安装:

1
2
3
4
5
6
7
8
9
10
11
12
cd /tmp && \
wget http://nodejs.org/dist/node-latest.tar.gz && \
tar xvzf node-latest.tar.gz && \
rm -f node-latest.tar.gz && \
cd node-v* && \
./configure && \
CXX="g++ -Wno-unused-local-typedefs" make && \
CXX="g++ -Wno-unused-local-typedefs" make install && \
cd /tmp && \
rm -rf /tmp/node-v* && \
npm install -g npm && \
printf '\n# Node.js\nexport PATH="node_modules/.bin:$PATH"' >> /root/.bashrc

ERROR

MSBUILD : error MSB3428: 未能加载 Visual C++ 组件“VCBuild.exe”。

解决方法:npm install –global –production windows-build-tools (全局安装windows构建工具)

Module build failed: Error: ENOENT: no such file or directory, scandir node-sass

解决办法:npm rebuild node-sass

首先网络唤醒需要硬件支持,目前大部分主流的板载网卡都支持,只需在bios里开启即可,笔记本中thinkpad全系列都支持,部分品牌的部分型号是不支持的,比如我有2台acer笔记本不支持。(很多时候wol是为了节电考虑,但是电源插座是必须通电的,笔记本也是)

路由器下安装

路由器中有相关插件可以直接进行唤醒,比如OpenWRT提供了wol和etherwake两个包来实现WOL功能

1
2
opkg update
opkg install wol etherwake

使用方法:

1
2
/usr/bin/wol 00:1D:5C:1F:5D:16
/usr/bin/etherwake 00:1D:5C:1F:5D:16

ubuntu下安装:

1
apt-get install wakeonlan

使用方法:

1
wakeonlan 00:1D:5C:1F:5D:16

windows下安装:

下载地址:https://www.depicus.com/downloads/wolcmd.zip 使用方法: 打开cmd,CD到下载wolcmd的文件路径

1
wolcmd [mac address] [ip address] [subnet mask] [port number]

比如:

1
WolCmd.exe 1016932061F0 192.168.0.255 255.255.255.0 80

公网唤醒内网主机

外网进行唤醒,前提是路由器上得设置端口映射,和mac绑定。 原理是这样的: 1.魔术包数据发送到外网地址的映射端口上。 2.由于做了映射,路由器会找到对应的IP地址。 3.IP与对应的mac地址绑定了,所以路由器自然得将数据包发到对应mac地址上。 4.此时数据包已经发到内网待唤醒主机上了,网卡判断数据帧符合唤醒内容,就把机器启动。 公网唤醒工具:http://ip.malu.me/wol/

附录

断电后再通电自动唤醒:在BIOS中电源设置,Restore on AC设置为Last Stste。

运行环境:

线上:RDS(内网)+ECS 本地:xampp 由于本地只能访问ECS,需要在ECS上架设mysql代理: 参考这篇笔记:http://git.malu.me/MySQL-Proxy/

mysql线上与本地实现主从同步

ECS配置(作为主服务器master):

修改配置文件:

1
2
3
4
5
#vim /etc/my.cnf

[mysqld]
log-bin=mysql-bin #[必须]启用二进制日志
server-id=1 #[必须]服务器唯一ID,默认是1

重启mysql:

1
/etc/init.d/mysql restart

在主服务器上建立帐户mysync并授权给slave主机:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
mysql -uroot -h localhost

mysql> GRANT REPLICATION SLAVE ON *.* to 'mysync'@'%' identified by 'passwd';

mysql> show master status; #查看master的状态
+------------------+----------+--------------+------------------+
File Position Binlog_Do_DB Binlog_Ignore_DB
+------------------+----------+--------------+------------------+
mysql-bin.000002 532
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)

注:执行完此步骤后不要再操作主服务器MYSQL,防止主服务器状态值Position变化

mysql> show master logs; #查看master二进制日志位置

mysql> show variables like 'server_id'; #查看server_id

mysql> SET GLOBAL server_id=2; #临时设置server_id,下次重启会失效

本地xampp配置(作为从服务器slave):

修改配置文件:

1
2
3
4
5
X:\Xampp\mysql\bin\my.ini   #xampp默认配置文件

[mysqld]
log-bin=mysql-bin #[不是必须]启用二进制日志
server-id=2 #[必须]服务器唯一ID,默认是1,不要与master一样

配置Slave:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
mysql> change master to  master_host='mysql.malu.me',master_port=3306,master_user='mysync',master_password='passwd',master_log_file='mysql-bin.000001',master_log_pos=532;

mysql> start slave; #启动从服务器复制功能

注:master_log_pos即为master主机状态里的Position

mysql> show slave status\G #检查slave的状态

*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: mysql.malu.me
Master_User: mysync
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 532
Relay_Log_File: mysql-relay-bin.000008
Relay_Log_Pos: 695
Relay_Master_Log_File: mysql-bin.000001
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 532
Relay_Log_Space: 868
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1
Master_UUID:
Master_Info_File: X:\Xampp\mysql\data2\master.info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set:
Executed_Gtid_Set:
Auto_Position: 0

接下来往RDS写入数据的时候会自动同步到本地mysql

mysql线上与本地实现主主同步

双主架构需要mysql双方能互相通讯,但是本地mysql在内网,所以必须先让ECS穿透到内网: 内网穿透参考这篇笔记:http://git.malu.me/二级proxy部署/

ECS (作为master-A):

1
2
3
4
5
6
7
8
9
10
11
[mysqld]
log-bin=mysql-bin #开启二进制日志功能
server-id=1 #注意server-id的唯一性
binlog-ignore-db = mysql,information_schema #忽略写入binlog日志的库
relay-log=/app/mysql/relaylogs/relay-bin #指定中继日志路径
log_slave_updates=1 #开启从库更新操作写入二进制日志功能*
auto_increment_increment=2 #双主复制中自增长字段的步长*
auto_increment_offset=1 #双主复制中自增长字段的起始值,主为1 副为2*
sync_binlog = 1 #可保证事务日志及时写入磁盘文件
binlog-do-db = TestXXX #指定binlog日志记录哪个db
slave-skip-errors #定义复制过程中从服务器可以自动跳过错误

本地xampp(作为master-B):

1
2
3
4
5
6
7
8
9
10
11
[mysqld]
log-bin=mysql-bin #开启二进制日志功能
server-id=2 #注意server-id的唯一性
binlog-ignore-db = mysql,information_schema #忽略写入binlog日志的库
relay-log=/app/mysql/relaylogs/relay-bin #指定中继日志路径
log_slave_updates=1 #开启从库更新操作写入二进制日志功能*
auto_increment_increment=2 #双主复制中自增长字段的步长*
auto_increment_offset=2 #双主复制中自增长字段的起始值,主为1 副为2*
sync_binlog = 1 #可保证事务日志及时写入磁盘文件
binlog-do-db = TestXXX #指定binlog日志记录哪个db
slave-skip-errors #定义复制过程中从服务器可以自动跳过错误

ECS执行:

1
2
3
4
5
6
7
mysql> GRANT REPLICATION SLAVE ON *.* to 'mysync'@'%' identified by 'passwd';
mysql> flush privileges;
mysql> change master to master_host='127.0.0.1',master_port=3307,master_user='mysync',master_password='passwd',master_log_file='mysql-bin.000001',master_log_pos=532;

注:3307为隧道入口

mysql> start slave; #启动master-A复制功能

本地xampp执行:

1
2
3
4
5
6
7
mysql> GRANT REPLICATION SLAVE ON *.* to 'mysync'@'%' identified by 'passwd';
mysql> flush privileges;
mysql> change master to master_host='mysql.malu.me',master_port=3306,master_user='mysync',master_password='passwd',master_log_file='mysql-bin.000001',master_log_pos=532;

mysql> start slave; #启动master-B复制功能

mysql> show slave status\G #检查slave的状态

接下来写入数据试试吧! 附录: mysql主从自动切换脚本:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash
cat << README
#####################################################################################################
#Step 1: point the slave IP #
#Step 2: check the master and slave information whether good for change #
#Step 3: stop old slave,then get new master binlog name and postation,then execute change master to #
#Step 4: start slave,and show whether change successed. #
#####################################################################################################
README
User=root
PW=123456
read -p "-- Please input the slave IP:" Slave
Master=$(mysql -u${User} -h${Slave} -p${PW} -e "show slave status \G;"awk '/Master_Host/{print $2}')
if [ -n "${Master}" ]
then
echo -e "--Master IP:${Master},Slave IP:${Slave}"
M=$(mysql -u${User} -h${Master} -p${PW} -e "show master status;"awk 'NR==2{print $2}')
S=$(mysql -u${User} -h${Slave} -p${PW} -e "show slave status \G;"awk '/Read_Master_Log_Pos/{print $2}')
echo -e "-- master pos:${M};slave pos is:${S}"
else
echo "-- Slave IP input wrong,please input again ! "
exit 1
fi
if [ "${M}" -eq "${S}" ]
then
read -p "-- Master-Slave is accordance,input Yes to start changing:" var
case "$var" in
[Yy]es)
mysql -u${User} -h${Slave} -p${PW} -e "stop slave;reset slave;change master to master_host='';"
Pos=$(mysql -u${User} -h${Slave} -p${PW} -e "show master status;"awk 'NR==2{print $2}')
File=$(mysql -u${User} -h${Slave} -p${PW} -e "show master status;"awk 'NR==2{print $1}')
mysql -u${User} -h${Master} -p${PW} -e "stop slave;
change master to master_user='ideal',master_host='${Slave}',master_password='123456',master_log_file='${File}',master_log_pos=${Pos};
start slave;"
;;
*)
echo "-- error input .... exit!"
;;
esac
echo "-- changing, please wait 3s...."
sleep 3
echo "-- change successfull,the new master is:${Slave},new slave is ${Master}"
SlaveIOStatus=$(mysql -u${User} -h${Master} -p${PW} -e "show slave status \G;"awk '/Slave_IO_Running/{print $2}')
SlaveSQLStatus=$(mysql -u${User} -h${Master} -p${PW} -e "show slave status \G;"awk '/Slave_SQL_Running/{print $2}')
printf "The new master is: \n Slave_IO_Running=${SlaveIOStatus}\n"
printf "Slave_SQL_Running=${SlaveSQLStatus}\n"
else
echo "node change failed please change again ! "
exit 1
fi

github.com SSH 加速访问

修改 C:\Users\Dell\.ssh\config 文件,添加如下内容:

1
2
3
4
5
6
7
Host github.com
User git
Port 22
Hostname github.com
IdentityFile "C:/Users/Dell/.ssh/id_ecdsa"
TCPKeepAlive yes
ProxyCommand connect -S 127.0.0.1:7891 -a none %h %p

全局设置 GPG 签名工具

GPG4Win 下载地址:https://www.gpg4win.org/

1
git config --global gpg.program "C:/Program Files (x86)/GnuPG/bin/gpg.exe"

列举 GPG Key

1
gpg --list-secret-keys --keyid-format=long

针对 Git Repo 启用 GPG 签名

1
2
git config --local user.signingkey [YOUR GPG KEY]
git config --local commit.gpgsign true

github走proxy

1.首先开启代理,这种方式只支持https方式,ssh不行 2.给全局git-config配置代理

1
git config --global http.https://github.com.proxy socks5://127.0.0.1:50001

3.clone的时候使用proxy

1
git clone https://github.com/xxx.git -c http.proxy=socks5://127.0.0.1:50001

4.取消全局代理

1
git config --global --unset http.https://github.com.proxy

直接用git下载Gist ID内容

1
git clone git@github.com:cc13e0fcf2c348cc126f918e4a3917eb.git

github与七牛云持续集成

七牛云的CDN提供API刷新缓存服务,我们可以使用github的webhooks来触发刷新。 1.首先配置github的hook: 在项目里找到settings->Webhooks 设置:Payload URL 项为我们服务器的地址,然后保存 2.生成token,如下:

1
echo "/v2/tune/refresh" openssl dgst -binary -hmac "用户SK" -sha1 base64  tr + -  tr / _

3.编写服务端脚本,来触发七牛API: 比如我用PHP来触发http://git.malu.me:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
#七牛刷新缓存函数
function refresh_qiniu($path){
$message = exec('curl -X POST -H "Authorization: QBox <用户AK>:<生成的token>" http://fusion.qiniuapi.com/v2/tune/refresh -d \''.json_encode($path).'\' -H \'Content-Type: application/json\' 2>&1');
return $message;
}
$getin = file_get_contents("php://input");
#追加写入日志
file_put_contents('file.log',$getin, FILE_APPENDLOCK_EX);
$getinarr = json_decode($getin);
$getinarr = $getinarr->commits[0];
$path = array();
#添加文章
if(!empty($getinarr->added) !empty($getinarr->removed)){
echo '刷page:';
$path['urls']=array('http://git.malu.me','http://git.malu.me/index.html');
$path['dirs']=array('http://git.malu.me/page/*');
echo refresh_qiniu($path);
}
#修改文章
if(!empty($getinarr->modified)){
echo '刷url:';
foreach($getinarr->modified as $key=>$value){
//echo $value;
#匹配出文章名
if(preg_match('/-\d\d-\d\d-(.*?)\.md/is', $value, $out)){
//var_dump($out);
echo $out[1];
#对中文编码
$renewurl = 'http://git.malu.me/'.urlencode($out[1]).'/';
$path['urls']=array($renewurl);
echo refresh_qiniu($path);
}
}
}

七牛对象存储301跳转

1
qrsctl redirect <Bucket> <Key> <RedirectUrl> [<RedirectCode>]
0%