没有记录,就没有发生。

0%

原硬盘情况

[email protected]_FreeBSD:~ # gpart show ada0
=>       40  117231328  ada0  GPT  (56G)
         40     409600     1  efi  (200M)
     409640       1024     2  freebsd-boot  (512K)
     410664        984        - free -  (492K)
     411648   33554432     3  freebsd-swap  (16G)
   33966080   83263488     4  freebsd-zfs  (40G)
  117229568       1800        - free -  (900K)

[email protected]_FreeBSD:~ # zpool status zroot
  pool: zroot
 state: ONLINE
  scan: none requested
config:

    NAME        STATE     READ WRITE CKSUM
    zroot       ONLINE       0     0     0
      ada0p4    ONLINE       0     0     0

errors: No known data errors

给新硬盘分区

1
2
3
4
5
6
7
8
9
10
11
# Create a fresh partition table
gpart destroy da0
gpart create -s gpt da0

# Create the bootcode partition for UEFI Boot
gpart add -a 4k -s 200M -t efi da0
gpart bootcode -p /boot/boot1.efifat -i 1 da0

# Create Partitions
gpart add -a 1m -s 16G -t freebsd-swap -l swap da0
gpart add -a 1m -t freebsd-zfs -l disk0 da0
[email protected]_FreeBSD:~ # gpart show da0
=>       40  250085296  da0  GPT  (119G)
         40     409600    1  efi  (200M)
     409640       2008       - free -  (1.0M)
     411648   33554432    2  freebsd-swap  (16G)
   33966080  216117248    3  freebsd-zfs  (103G)
  250083328       2008       - free -  (1.0M)

参考资料:GPTZFSBoot

迁移原zroot

1
2
3
4
5
6
7
8
9
10
[email protected]_FreeBSD:~ # zpool attach zroot ada0p4 da0p3
Make sure to wait until resilver is done before rebooting.

If you boot from pool 'zroot', you may need to update
boot code on newly attached disk 'da0p3'.

Assuming you use GPT partitioning and 'da0' is your new boot disk
you may use the following command:

gpart bootcode -b /boot/pmbr -p /boot/gptzfsboot -i 1 da0

参考资料:freebsd-and-uefi-boot, 管理 ZFS 根池

移除旧硬盘,刷新储存池容量

1
2
zpool detach zroot xxxxxxxxxxxxxx
zpool online -e zroot da0p3
------------- END OF FILE meow~-------------

目的

  1. 放假前用掉囤积的淡奶油们;

材料

  1. 鸡蛋 4个;

  2. 炼乳 20 g;

  3. 奶油 150 ml;

  4. 砂糖 60 g;

  5. 水 125 ml;

  6. 蛋挞皮 若干;

步骤

  1. 乳液配制:加入炼乳、奶油、砂糖、水于盆中,室温下充分混合;

  2. 蛋液配制:鸡蛋打入盆中,混合蛋清蛋黄;

  3. 蛋挞液配制:混合蛋液与乳液,粗过滤3次;

  4. 将蛋挞液装于蛋挞皮至1/2处;

  5. 将蛋挞置于烤箱中下层,设定上管200℃,下管150℃,定时20 min;

  6. 烤制时保持观察,待表面焦褐色即可,取出放凉;

------------- END OF FILE meow~-------------

中国大学MOOC不久前把他们的视频从mp4换到m3u8了,为了更好的学习,有了以下脚本,基于那谁的改的来着,算了这不重要。

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
64
#!/usr/bin/env python3
import os
import re
import sys
import argparse
import threading


def clean_name(name, count):
file_type = name.split('.')[-1]
name = ''.join(name.split('.')[:-1])
name = re.sub('[.\/:*?"<>|-]', '', name)
name = re.sub('[0-9]', '', name)
return '%s_%s.%s'%(str(count).zfill(3), name, file_type)


class FFMPEG_thread(threading.Thread):

def __init__(self, name):
threading.Thread.__init__(self)
self.name = name

def run(self):
print('Thread %s start!' % self.name)
global dl_pool
while True:
try:
name, url = dl_pool.pop()
os.system('ffmpeg -i "{}" -c copy -bsf:a aac_adtstoasc "{}"'\
.format(url,os.path.join(video_dir,name)))
except:
print('Thread %s end!' % self.name)
break


if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Download m3u8 to mp4')
parser.add_argument('-l', default=r'', help='视频列表')
parser.add_argument('-d', default=r'', help='下载目录')
parser.add_argument('-c', default=8, help='线程数,默认8')
args = parser.parse_args()
video_list = os.path.abspath(args.l)

if args.d == '':
video_dir = os.path.dirname(video_list)
else:
video_dir = os.path.abspath(args.d)

count = 1
dl_pool = []

with open(video_list, encoding = 'utf-8') as f:
lines = f.readlines()
lines = [_.strip() for _ in lines if _ != '\n']
for line in lines:
name,url = line.split('\t')
name = clean_name(name, count)
print(name,url)
dl_pool.append([name, url])
count += 1

tp = [FFMPEG_thread(i) for i in range(args.c)]
[t.start() for t in tp]
[t.join() for t in tp]

默认的效果大概也能看吧,就是对中文字体有点不满意,考完试换掉它。最后还是祝大家2020快乐啦,虽然在2019肯定没人看。

------------- END OF FILE meow~-------------

重新开始,希望2020能像之前一样好。

------------- END OF FILE meow~-------------

有一些截图,需要合并为pdf,查了下,python的img2pdf库可以干:

1
2
3
4
5
import os
import img2pdf

with open('./output.pdf', 'wb') as f:
f.write(img2pdf.convert(['./%s' %x for x in os.listdir('./') if x[-3:] == 'png']))
------------- END OF FILE meow~-------------

今天在写煎蛋的爬虫,解析吐槽返回的json发现出错:

>>> b=json.loads(a)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\hly20\AppData\Local\Programs\Python\Python37\lib\json\__init__.py", line 348, in loads
    return _default_decoder.decode(s)
  File "C:\Users\hly20\AppData\Local\Programs\Python\Python37\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Users\hly20\AppData\Local\Programs\Python\Python37\lib\json\decoder.py", line 353, in raw_decode
    obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting ',' delimiter: line 1 column 198 (char 197)

发现引起错误的json在双引号中嵌套了双引号,如下所示:

{"code":0,"hot_tucao":[{"comment_ID":"5206422","comment_post_ID":"102312","comment_author":"不懂可以不说","comment_date":"2019-06-29 14:12:43","comment_date_int":1561788763,"comment_content":"  \u003ca href=\"#tucao-5206353\" data-id=\"5206353\" class=\"tucao-link\"\[email protected]乐色分类\u003c/a\u003e 很简单。我喜欢她 = 我恋爱了。","comment_parent":"4286850","comment_reply_ID":"0","is_jandan_user":0,"is_tip_user":0,"vote_positive":"11","vote_negative":"0"}],"tucao":[{"comment_ID":"5206353","comment_post_ID":"102312","comment_author":"乐色分类","comment_date":"2019-06-29 14:01:29","comment_date_int":1561788089,"comment_content":"所以你是怎么定义谈恋爱的?看蛋友故事多了我不确定你们对谈恋爱的标准…","comment_parent":"4286850","comment_reply_ID":"0","is_jandan_user":0,"is_tip_user":0,"vote_positive":"4","vote_negative":"0"},{"comment_ID":"5206422","comment_post_ID":"102312","comment_author":"不懂可以不说","comment_date":"2019-06-29 14:12:43","comment_date_int":1561788763,"comment_content":"  \u003ca href=\"#tucao-5206353\" data-id=\"5206353\" class=\"tucao-link\"\[email protected]乐色分类\u003c/a\u003e 很简单。我喜欢她 = 我恋爱了。","comment_parent":"4286850","comment_reply_ID":"0","is_jandan_user":0,"is_tip_user":0,"vote_positive":"12","vote_negative":"0"},{"comment_ID":"5206522","comment_post_ID":"102312","comment_author":"慕行秋","comment_date":"2019-06-29 14:31:29","comment_date_int":1561789889,"comment_content":"  \u003ca href=\"#tucao-5206353\" data-id=\"5206353\" class=\"tucao-link\"\[email protected]乐色分类\u003c/a\u003e 众所周知,蛋友的恋爱==暗恋","comment_parent":"4286850","comment_reply_ID":"0","is_jandan_user":0,"is_tip_user":0,"vote_positive":"3","vote_negative":"0"},{"comment_ID":"5206613","comment_post_ID":"102312","comment_author":"不懂就要说不说怎么知道对错","comment_date":"2019-06-29 14:59:58","comment_date_int":1561791598,"comment_content":" \u003ca href=\"#tucao-5206353\" data-id=\"5206353\" class=\"tucao-link\"\[email protected]乐色分类\u003c/a\u003e 因为不同的人对谈恋爱的定义不一样。\n有的人觉得谈恋爱重点在于谈(婚论嫁),有的人觉得在于恋爱","comment_parent":"4286850","comment_reply_ID":"0","is_jandan_user":0,"is_tip_user":0,"vote_positive":"0","vote_negative":"0"}],"has_next_page":false}

查了下,使用Python处理json字符串中的非法双引号 似乎显示的是同样的问题,但是他的解决方法在这儿似乎行不通,因为他那儿有意义的"情况有限,直接穷举了。 于是换个思路,检测"前后有无 {}[], 来判定引号有没有意义,无意义则在其前加入\,代码如下:

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
def clean_json(data):
# 转义换行符们
data = data.replace("\n", "\\n") \
.replace("\r", "\\r") \
.replace("\n\r", "\\n\\r") \
.replace("\r\n", "\\r\\n") \
.replace("\t", "\\t")
# 确认每个引号有没有意义
start_index = 0
origin_index = data.find('"', start_index)
while origin_index &gt;= 0:
check_index = origin_index - 1
while check_index &gt;= 0:
# 向左搜索
if data[check_index] == ' ':
# 遇到空格跳过
check_index -= 1
continue
elif data[check_index] in '{}:[],':
# 有意义引号,结束当前测试
start_index = origin_index + 1
break
else:
# 左侧没有意义,检测右侧
check_index = origin_index + 1
while check_index &lt; len(data):
if data[check_index] == ' ':
# 遇到空格跳过
check_index += 1
continue
elif data[check_index] in '{}:[],':
# 有意义引号,结束当前测试
start_index = origin_index + 1
break
else:
# 无意义引号,添加 \
data = r'%s\%s' % (data[:origin_index], data[origin_index:])
start_index = origin_index + 2
break
break
origin_index = data.find('"', start_index)
if origin_index == data.rfind('"'):
# 转换完了
break
return(data)

结果如下:

{"code":0,"hot_tucao":[{"comment_ID":"5206422","comment_post_ID":"102312","comment_author":"不懂可以不说","comment_date":"2019-06-29 14:12:43","comment_date_int":1561788763,"comment_content":"  <a href=\"#tucao-5206353\" data-id=\"5206353\" class=\"tucao-link\">@乐色分类</a> 很简单。我喜欢她 = 我恋爱了。","comment_parent":"4286850","comment_reply_ID":"0","is_jandan_user":0,"is_tip_user":0,"vote_positive":"11","vote_negative":"0"}],"tucao":[{"comment_ID":"5206353","comment_post_ID":"102312","comment_author":"乐色分类","comment_date":"2019-06-29 14:01:29","comment_date_int":1561788089,"comment_content":"所以你是怎么定义谈恋爱的?看蛋友故事多了我不确定你们对谈恋爱的标准…","comment_parent":"4286850","comment_reply_ID":"0","is_jandan_user":0,"is_tip_user":0,"vote_positive":"4","vote_negative":"0"},{"comment_ID":"5206422","comment_post_ID":"102312","comment_author":"不懂可以不说","comment_date":"2019-06-29 14:12:43","comment_date_int":1561788763,"comment_content":"  <a href=\"#tucao-5206353\" data-id=\"5206353\" class=\"tucao-link\">@乐色分类</a> 很简单。我喜欢她 = 我恋爱了。","comment_parent":"4286850","comment_reply_ID":"0","is_jandan_user":0,"is_tip_user":0,"vote_positive":"12","vote_negative":"0"},{"comment_ID":"5206522","comment_post_ID":"102312","comment_author":"慕行秋","comment_date":"2019-06-29 14:31:29","comment_date_int":1561789889,"comment_content":"  <a href=\"#tucao-5206353\" data-id=\"5206353\" class=\"tucao-link\">@乐色分类</a> 众所周知,蛋友的恋爱==暗恋","comment_parent":"4286850","comment_reply_ID":"0","is_jandan_user":0,"is_tip_user":0,"vote_positive":"3","vote_negative":"0"},{"comment_ID":"5206613","comment_post_ID":"102312","comment_author":"不懂就要说不说怎么知道对错","comment_date":"2019-06-29 14:59:58","comment_date_int":1561791598,"comment_content":" <a href=\"#tucao-5206353\" data-id=\"5206353\" class=\"tucao-link\">@乐色分类</a> 因为不同的人对谈恋爱的定义不一样。\n有的人觉得谈恋爱重点在于谈(婚论嫁),有的人觉得在于恋爱","comment_parent":"4286850","comment_reply_ID":"0","is_jandan_user":0,"is_tip_user":0,"vote_positive":"0","vote_negative":"0"}],"has_next_page":false}
{'code': 0, 'hot_tucao': [{'comment_ID': '5206422', 'comment_post_ID': '102312', 'comment_author': '不懂可以不说', 'comment_date': '2019-06-29 14:12:43', 'comment_date_int': 1561788763, 'comment_content': '  <a href="#tucao-5206353" data-id="5206353" class="tucao-link">@乐色分类</a> 很简单。我喜欢她 = 我恋爱了。', 'comment_parent': '4286850', 'comment_reply_ID': '0', 'is_jandan_user': 0, 'is_tip_user': 0, 'vote_positive': '11', 'vote_negative': '0'}], 'tucao': [{'comment_ID': '5206353', 'comment_post_ID': '102312', 'comment_author': '乐色分类', 'comment_date': '2019-06-29 14:01:29', 'comment_date_int': 1561788089, 'comment_content': '所以你是怎么定义谈恋爱的?看蛋友故事多了我不确定你们对谈恋爱的标准…', 'comment_parent': '4286850', 'comment_reply_ID': '0', 'is_jandan_user': 0, 'is_tip_user': 0, 'vote_positive': '4', 'vote_negative': '0'}, {'comment_ID': '5206422', 'comment_post_ID': '102312', 'comment_author': '不懂可以不说', 'comment_date': '2019-06-29 14:12:43', 'comment_date_int': 1561788763, 'comment_content': '  <a href="#tucao-5206353" data-id="5206353" class="tucao-link">@乐色分类</a> 很简单。我喜欢她 = 我恋爱了。', 'comment_parent': '4286850', 'comment_reply_ID': '0', 'is_jandan_user': 0, 'is_tip_user': 0, 'vote_positive': '12', 'vote_negative': '0'}, {'comment_ID': '5206522', 'comment_post_ID': '102312', 'comment_author': '慕行秋', 'comment_date': '2019-06-29 14:31:29', 'comment_date_int': 1561789889, 'comment_content': '  <a href="#tucao-5206353" data-id="5206353" class="tucao-link">@乐色分类</a> 众所周知,蛋友的恋爱==暗恋', 'comment_parent': '4286850', 'comment_reply_ID': '0', 'is_jandan_user': 0, 'is_tip_user': 0, 'vote_positive': '3', 'vote_negative': '0'}, {'comment_ID': '5206613', 'comment_post_ID': '102312', 'comment_author': '不懂就要说不说怎么知道对错', 'comment_date': '2019-06-29 14:59:58', 'comment_date_int': 1561791598, 'comment_content': ' <a href="#tucao-5206353" data-id="5206353" class="tucao-link">@乐色分类</a> 因为不同的人对谈恋爱的定义不一样。\n有的人觉得谈恋爱重点在于谈(婚论嫁),有的人觉得在于恋爱', 'comment_parent': '4286850', 'comment_reply_ID': '0', 'is_jandan_user': 0, 'is_tip_user': 0, 'vote_positive': '0', 'vote_negative': '0'}], 'has_next_page': False}

虽然暂时能跑了,但是无法处理内部引号前有{}[],的情况,而且似乎效率有点低…不知道这个问题有没有更好的解决方法了…誒…

------------- END OF FILE meow~-------------

旧服务器配置

旧服务器是一台蜗牛星际矿渣,带了一块3t盘,用FreeBSD架了NFS给内网机器用。

导出 ZFS 存储池

显式导出

zpool export tank

若无法取消挂载,则可以使用 -f 选项强制取消挂载这些文件系统

zpool export -f tank

拔出硬盘,这样就可以了

参考资料:迁移ZFS储存池本地存档页面

新服务器配置

新服务器是还一台蜗牛星际矿渣,新加了一块3t盘,准备安装FreeBSD架NFS给内网机器用。

安装 FreeBSD

下下下下一步就行了… 不要用ultraiso制作FreeBSD安装盘,用dd比较合适。

开启 ssh

据说FreeBSD默认不允许root远程登录,需手动开启,但是我安装完12后发现SSH默认已经开启了,所以第一步可以跳过:

# 编辑/etc/rc.conf
sshd_enable="yes"

# 编辑/etc/ssh/sshd_config
PermitRootLogin yes
PermitEmptyPasswords no
passwordAuthentication yes

参考资料:FreeBSD开启SSH远程登陆本地存档页面

ZFS 配置

导入 ZFS 储存池

# 插入原硬盘后检测zpool
zpool import

# 确认名称后导入
zpool import tank

参考资料:迁移ZFS储存池本地存档页面

为储存池添加新设备

# 插入一块新硬盘,确认设备名,此处为ada3
zpool add tank ada3

参考资料:向存储池中添加设备本地存档页面

NFS 服务端配置

编辑 /etc/rc.conf 启用 NFS

rpcbind_enable="YES"
nfs_server_enable="YES"
mountd_flags="-r"

/etc/exports 文件指定了哪个文件系统 NFS 应该输出,以下式一个多目录例子

/nfs  -maproot=root -alldirs 192.168.2.129
/work  -maproot=root -alldirs 192.168.2.129

重启系统或重启 mounted 服务使修改生效

kill -HUP `cat /var/run/mountd.pid`

参考资料:30.3.网络文件系统(NFS)本地存档页面

smaba 服务端配置

由于官方源太慢,又没有啥合理的第三方源,此处使用proxychains代理

[email protected]_FreeBSD:~ # proxychains pkg search samba
p5-Samba-LDAP-0.05_2           Manage a Samba PDC with an LDAP Backend
p5-Samba-SIDhelper-0.0.0_3     Create SIDs based on G/UIDs
samba-nsupdate-9.13.3_1        nsupdate utility with GSS-TSIG support
samba46-4.6.16_1               Free SMB/CIFS and AD/DC server and client for Unix
samba47-4.7.12                 Free SMB/CIFS and AD/DC server and client for Unix
samba48-4.8.9_1                Free SMB/CIFS and AD/DC server and client for Unix

[email protected]_FreeBSD:~ # proxychains pkg install samba48-4.8.9_1

编辑 /etc/rc.conf 启用 samba

nmbd_enable="YES"
winbindd_enable="YES"
samba_enable="NO"
samba_server_enable="YES"

编辑配置文件 /usr/local/etc/smb4.conf

[nfs]
    comment = nfs
    path = /nfs
    public = no
    browseable = yes
    writable = yes
    printable = no
    create mask = 0755


[work]
    comment = work area
    path = /work
    public = no
    browseable = yes
    writable = yes
    printable = no
    create mask = 0755

添加 samba root 用户

smbpasswd -a root

直接重启或重启 samba 使配置生效即可

参考资料:FreeBSD 11.1安装samba服务本地存档页面

------------- END OF FILE meow~-------------

Background

某个不想看书的下午…

TEST

创建macvlan设备

ip netns add netns1
ip link add eth0.1 link eth0 type macvlan mode bridge #新建设备eth0.1,桥接eth0
ip link set eth0.1 netns netns1 #将设备丢进netns1
ip netns exec netns1 ip link set eth0.1 up #启动设备

一般情况下,网卡只有一个MAC地址。然而,有些场景下需要给一个网卡设置多个MAC地址。Linux通过MACVLAN技术在一个物理网卡上创建多个MACVLAN虚拟设备,每个设备有着不同的MAC地址。当物理网卡收到数据包时,MACVLAN driver根据数据包MAC地址将数据包交由匹配的虚拟网卡处理。使用MACVLAN可以替代使用bridge来连接物理网卡和虚拟网络设备。

pppoe拨号时,服务器根据mac地址分配ip,如果直接使用同一个设备拨号是不能达到多播效果的(但是能拿到同一个ip??ppp0,ppp1同一个ip,然后不出意料的掉线了)

一般情况下,Linux的网络接口,路由表、协议栈、iptables规则等资源由操作系统的全部进程共享。通过使用netowrk namespace, 可以将这些网络资源隔离开,只由namespace内的进程共享。

效果:

ref:虚拟网络设备

ppp拨号

若先前已经使用pppoeconf配置过拨号,则可在/etc/ppp/peers找到现成的配置文件,稍加更改便可使用:

#在某个netnamespace中创建进程既可以用ip netns exec的方式,也可以直接创建一个bash,但是记得要退出(不然真的傻傻分不清了)
ip netns exec netns1 bash
cd /etc/ppp/peers
cp dsl-proviser test

#然后将文件中的plugin rp-pppoe.so XXX换成刚刚新建的设备
pon test
exit

Script

太懒了,手动一个个设置,干脆来个脚本:

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
num=10 #多拨数量
user=test #pppoe用户名
wan=eth0 #拨号所用的物理端口

#交互部分,如果上面直接填的话就注释掉吧
read -p "请输入用户名:" user
read -p "请输入多拨数量:" num
read -p "请输入拨号所用的物理端口(默认eth0):" wan

rt=1
while \[ ${rt} -lt ${num} \]
do
dev=${wan}.${rt}
ip link add ${dev} link ${wan} type macvlan mode bridge
ip netns add ns${rt}
ip link set ${dev} netns ns${rt}
ip netns exec ns${rt} ip link set ${wan}.${rt}
cat >>/etc/ppp/peers/p${rt} <<-EOF
\# Minimalistic default options file for DSL/PPPoE connections

noipdefault
defaultroute
replacedefaultroute
hide-password
#lcp-echo-interval 30
#lcp-echo-failure 4
noauth
persist
#mtu 1492
#persist
#maxfail 0
#holdoff 20
plugin rp-pppoe.so ${dev}
usepeerdns
user "${user}"
EOF
ip netns exec ns${rt} pon p${rt}
sleep 10s
echo "第${rt}次拨号,状态:"
ip netns exec ns${rt} ifconfig ppp0
rt=\`expr ${rt} + 1\`
done

echo "拨号结束,可使用ip netns exec ns(1,2...拨号数) \[cmd\]在对应的命名空间进行操作"

我没试过啊,后果自负(也没啥后果,重启就好了)

Something else…

树莓派网卡也就100M,校园网一拨50M,玩个毛线多拨啊

------------- END OF FILE meow~-------------

连续一星期都是两三点睡觉…终于…

1
2
3
4
5
6
7
8
9
10
11
12
13
[email protected]:/home/wwwroot# rm -rf www.hly.space/
rm: cannot remove ‘www.hly.space/.user.ini’: Operation not permitted
[email protected]:/home/wwwroot# chattr -i www.hly.space/.user.ini
[email protected]:/home/wwwroot# rm -rf www.hly.space/
[email protected]:/home/wwwroot# ls
bak wiki.hly.space xjtu.hly.space
[email protected]:/home/wwwroot# rm bak wordpress
rm: cannot remove ‘bak’: Is a directory
rm: cannot remove ‘wordpress’: No such file or directory
[email protected]:/home/wwwroot# rm -r bak wordpress
rm: cannot remove ‘wordpress’: No such file or directory
[email protected]:/home/wwwroot# ls
wiki.hly.space xjtu.hly.space

谢天谢地数据库还在,就是各种链接都挂了 所以如果在你想这儿下载什么却下载不了的话,留个言吧 但愿有空的时候我能把他们补回来

------------- END OF FILE meow~-------------

一些废话

不知怎么的,在学校就是不想上路由器,恰巧树莓派3自带wifi,并且可以使用原版hostapd,作为热点使用也是极为方便的。网上也有现成的教程:用树莓派3做无线路由器。 但是呢作为一个不折腾就难受的人…一折腾就挂…总是重装也是够麻烦的,干脆写了个安装脚本。

原理

开机根据/root/start.sh脚本决定使用AP模式或wifi模式 AP模式使用了hostapd、dnsmasq;

使用脚本安装

1
wget http://www.hly.space/downloads/set_ap.sh && chmod 700 set_ap.sh && sudo  ./set_ap.sh

使用相关

/root/start.sh 决定了开机后wlan0的工作模式

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/bin/bash
#This shell will run at boot

#Hostapd&dnsmasp
#改成wifi便是wifi模式
way=ap
#wlan0桥接的接口,我是用pppoe拨号故为ppp0
#可以改成eth0等,可用ifconfig命令查看具体外网接口
interface=ppp0
if [ ${way} == ap ] ; then
ifconfig wlan0 down
ifconfig wlan0 192.168.3.1 netmask 255.255.255.0 up
iwconfig wlan0 power off
service dnsmasq restart
hostapd -B /etc/hostapd/hostapd.conf & > /dev/null 2>&1
iptables -t nat -A POSTROUTING -o ${interface} -j MASQUERADE
iptables -A FORWARD -i ${interface} -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i wlan0 -o ${interface} -j ACCEPT
fi
echo "wlan0 works in ${way} mod"

日志文件则为/root/start.log

安装脚本

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
#!/bin/bash

#适用于树莓派3 raspbian系统,至于其他的我就不知道了

apt update& apt upgrade -y
apt install hostapd dnsmasq -y
if [ $? == 1 ] ; then echo"相关软件获取失败,请检查网络连接" && exit 1 ; fi ;
echo 设定AP参数
read -p "Local IP(默认192.168.3.1):" ip
[ -z "$ip" ] && ip=192.168.3.1
read -p "Start of DHCP(默认192.168.3.2):" start
[ -z "$start" ] && start=192.168.3.2
read -p "End of DHCP(默认192.168.3.100):" end
[ -z "$end" ] && sel=end
read -p "Name of AP:" name
read -p "Password:" ser
cat >>/etc/dnsmasq.conf <<-EOF
interface=wlan0
dhcp-range=${start},${end},255.255.255.0,12h
EOF
cat >/etc/hostapd/hostapd.conf <<-EOF
interface=wlan0
hw_mode=g
channel=10
auth_algs=1
wpa=2
wpa\_key\_mgmt=WPA-PSK
wpa_pairwise=CCMP
rsn_pairwise=CCMP
wpa_passphrase=${ser}
ssid=${name}
EOF
sed -i '/^#net.ipv4.ip\_forward=1/c\\net.ipv4.ip\_forward=1' /etc/sysctl.conf
sed -i '/^exit 0/i\\cd \\/root' /etc/rc.local
sed -i '/^exit 0/i\\.\\/start.sh >start.log' /etc/rc.local
cat >/root/start.sh <<-EOF
#!/bin/bash

#Hostapd&dnsmasp
way=ap
interface=ppp0
if \[ \\${way} == ap \] ; then
ifconfig wlan0 down
ifconfig wlan0 ${ip} netmask 255.255.255.0 up
iwconfig wlan0 power off
service dnsmasq restart
hostapd -B /etc/hostapd/hostapd.conf & > /dev/null 2>&1
iptables -t nat -A POSTROUTING -o \\${interface} -j MASQUERADE
iptables -A FORWARD -i \\${interface} -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i wlan0 -o \\${interface} -j ACCEPT
fi
echo "wlan0 works in \\${way} mod"
EOF
chmod 755 /root/start.sh
echo "AP配置完成,重启生效"
echo "默认为AP模式,可在/root/start.sh中更改"
------------- END OF FILE meow~-------------