GPS授时服务器DIY

国内外厂商制造的高精度时钟服务器实际都是基于x86服务器,加装铷钟和GPS接收模块构成。树莓派流行起来后,网上也有配套的模块,让大家可以制造一个小巧的时钟服务器。实际这淘宝上有很多USB接口的GPS接收模块,产品特性:GPS+GLONASS双模定位内置FLASH,USB供电自适应1200-921600波特率1Hz输出,NMEA-0183协议输出。NTPD是业内对各种GPS接受器支持的最好的,绝大部分GPS接受模块实际都是使用标准的NMEA协议从/dev/gps输出。 测试的配置如下: # For more information about this file, see the man pages # ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5). logfile /var/log/ntp.log driftfile /var/lib/ntp/drift Permit time synchronization with our time source, but do not permit the source to query or modify the service on this system. restrict default nomodify notrap nopeer noquery Permit all access over the loopback interface. This could be tightened as well, but to do so would effect some of the administrative functions. restrict 127.0.0.1 restrict ::1 ...

October 1, 2019 · 2 min · pm

salt里定义账号和公钥

salt可以支持账号的增加以及ssh的公钥管理 user_add: user.present: - uid: 1000 - name: myuser - groups: - myuser group_add: group.present: - gid: 1000 - name: myuser - require_in: - user: user_add user_sshkey: ssh_auth.present: - user: myuser - names: - 'ssh-rsa XXXXXX' - 'ssh-rsa yyyyyy' - require: - user: user_add

September 25, 2019 · 1 min · pm

bind rpz常见的用法

bind 从9.10开始,将RPZ(Response Policy Zones)的性能做了进一步优化,解决了之前RPZ引起的性能下降问题,目前是可以大规模做部署。简单整理常见的RPZ规则用法1. 劫持某个域名(劫持www.google.com)./client add www.google.com.rpz.zone. A 8.8.8.8 丢弃某个域名的解析请求(丢弃对www.google.com的解析请求)./client add blog.gnuers.org.rpz.zone. CNAME rpz-drop. 3. 将某个域名解析到NXDOMAIN(www.google.com指向NXDOMAIN)./client add www.google.com.rpz.zone. CNAME .

July 15, 2018 · 1 min · pm

IPV6 ready

政策趋势从去年年底开始国家开始力推IPV6。目前看到的相关文件有1. “推进互联网协议第六版(IPv6)规模部署行动计划”,这个由中共中央办公厅、国务院办公厅印发。2. “工业和信息化部关于贯彻落实《推进互联网协议第六版(IPv6)规模部署行动计划》的通知”,这是由工信部印发。 基本方案周末有时间,把blog重新整理了一下,目前支持native IPV6 only环境访问。相关的方案1. DNS服务器迁移到cloudflare。原本是准备自己再弄个VM,部署IPV6的DNS。后来觉得太费钱,直接用了cloudflare。2. V6地址是通过He.net的隧道接入。 注意事项使用隧道接入V6,需要注意防火墙规则的设定,主要是以下几点:1. 阿里云的网络安全组上放开he的隧道接入IP。2. 服务器上itables-v4放开he的隧道接入IP。3. 服务器上的ip6tables打开相关的端口。4. nginx的上的geoip库都使用IPV6(V6的包括了V4)的 相关的防火墙规则如下:v4规则 v6规则 4. 参考链接1. http://www.gov.cn/zhengce/2017-11/26/content_5242389.htm2. http://www.miit.gov.cn/n1146295/n1652858/n1652930/n3757020/c6154756/content.html

June 11, 2018 · 1 min · pm

配置802.11r提升家用AP漫游体验

问题 网络的拓扑图大致如下虽然在客厅和主卧都有部署无线路由器,2个AP的SSID一致,实际使用的时候从客厅走入主卧时实际接入端还是在连接之前的AP。另外也经常出现电脑一会连AP1,一会连AP2导致无线中断。所有没有AC+AP的方案,都会存在以上的情况,为了提升体验就在openwrt上配置好802.11r,结果还是比较满意的。 配置方案 所有的AP需要都是桥接在同一个LAN中,我的2个WNDR3700都是把路由器的WAN口设置一个静态的IP(方便登陆管理),另外无线网络都是桥接到WAN上,所有AP的客户端的IP实际都是走光猫DHCP。 配置802.11r实际比较简单,只需要在openwrt上把wpad安装一下(默认是wpad-mini),涉及的配置如下:1. NASID: PMK-R0 Key Holder identifier,每个AP不同,可以设置为MAC地址2. Mobility Domain: 每个AP相同,随便设置4位字符3. R0 Key Lifetime: 每个AP相同,可以就用默认值100004. R1 Key Holder: 每个AP不同,可以设置为MAC地址5. Reassociation Deadline: 每个AP相同,可以设置为默认的10006. r0kh(External R0 Key Holder List),格式Valid format:,,<128-bit key as hex string> ,每个设备的配置都是相同的,可以按照格式:– MAC,NASID,32位字符串7. r1kh (External R1 Key Holder List),格式:,,<128-bit key as hex string> ,每个设备相同,可以按照格式:– MAC,MAC,32位字符串我的实际配置如下: External R0 Key Holder List: - A4:2B:8C:0C:D7:B3,A42B8C0CD7B3,8a7fcc966ed0691ff2809e1f38c16999 - 04:A1:51:9B:0D:25,04A1519B0D25,8a7fcc966ed0691ff2809e1f38c16999 External R1 Key Holder List: - A4:2B:8C:0C:D7:B3,A4:2B:8C:0C:D7:B3,8a7fcc966ed0691ff2809e1f38c16999 - 04:A1:51:9B:0D:25,04:A1:51:9B:0D:25,8a7fcc966ed0691ff2809e1f38c16999

February 11, 2018 · 1 min · pm

cobbler配置

流程记录 软件包安装 并关闭SELinux – 配置epel源,直接使用yum安装 yum install cobbler cobbler-web dhcp bind pykickstart tftp -y 需要注意dhcp/bind需要单独安装一下,cobbler没依赖dhcp/bind sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config setenforce 0 ```bash systemctl restart cobblerd 配置cobbler参数 – 修改/etc/cobbler/settings的参数 allow_dynamic_settings: 1 ```bash default_password_crypted: "$1$random-p$yqLCVPP/OBjIT02WekZic1" next_server: 192.168.117.134 manage_dhcp: 1 manage_dns: 1 server: 192.168.117.134 manage_rsync: 1 pxe_just_once: 1 #防止循环装机 manage_forward_zones: [‘gnuers.org’] manage_reverse_zones: ['10.0.0', '192.168', '172.16.123'] - 修改dhcp池配置 /etc/cobbler/dhcp.template subnet 192.168.117.0 netmask 255.255.255.0 { option routers 192.168.117.2; option domain-name-servers 192.168.117.2; option subnet-mask 255.255.255.0; range dynamic-bootp 192.168.117.10 192.168.117.20; ...

January 30, 2018 · 3 min · pm

openssh 7.6p1编译打包

新版本代码获取 从官网下载 https://openbsd.hk/pub/OpenBSD/OpenSSH/portable/openssh-7.6p1.tar.gz 编译RPM包注意事项 需要注意新版的openssh的spec文件里使用的pam配置文件会导致无法登陆 #%PAM-1.0 auth required pam_stack.so service=system-auth account required pam_nologin.so account required pam_stack.so service=system-auth password required pam_stack.so service=system-auth session required pam_stack.so service=system-auth 需要修改为 #%PAM-1.0 auth required pam_sepermit.so auth include password-auth account required pam_nologin.so account include password-auth password include password-auth # pam_selinux.so close should be the first session rule session required pam_selinux.so close session required pam_loginuid.so # pam_selinux.so open should only be followed by sessions to be executed in the user context session required pam_selinux.so open env_params session optional pam_keyinit.so force revoke session include password-auth ...

December 20, 2017 · 1 min · pm

利用BGP community黑洞路由

场景 在被攻击的时候,当入口无法承受巨大的流量时大家采用的方式是切换业务IP,然后把之前的IP做黑洞。在与ISP对接时,每个ISP都有自己的BGP配置规范。接入方可以参考commuity属性对自己的路由做很多设置,包括MED,Localpref,AS-PATH 添加、路由定向宣告等,另外一个常用的就是黑洞某条路由 模拟拓扑 测试的环境有4个路由器:– R1:企业路由器– R2:ISP路由器– R3:其他ISP的路由器– R4: 其他ISP的客户 测试的方案 先把R1-R4的BGP调通,然后分别按下属操作:1. R1上添加prefix-list把5.5.5.6/32这个明细路由直接发送给R2,并设置community属性4134:666(电信的黑洞属性).2. R2上添加对community 4134:666的匹配操作 ip community-list standard cm-blackhole permit 4134:666 route-map out-filter permit 20 match community cm-blackhole set local-preference 10 set ip next-hop 172.20.20.1 set community additive no- export route-map out-filter permit 30 set local-preference 30 set metric 30 可以观察在R1-R4上的路由情况: R1 路由 094846cab3a9# show ip bgp BGP table version is 0, local router ID is 10.10.0.22 Status codes: s suppressed, d damped, h history, * valid, > best, = multipath, i internal, r RIB-failure, S Stale, R Removed Origin codes: i - IGP, e - EGP, ? - incomplete ...

March 14, 2017 · 6 min · pm

控制linux时钟速度的几个参数

1. tick 用户态下内核时钟计数间隔,默认都是100HZ。因此单个tick代表了10^4 us。 可以设置每个tick代表的时钟长度,因此把tick增加1(即增加为10001us)的影响是每天时间慢8.64s(24小时的tick被提前消耗完) 24*3600*100*10001/10^6-24*3600=8.64s。 2. ppm 百万分之一秒,1个PPM增加 24*360*(10^6+1)/10^6-24*3600=0.0864s。 PPM 增加500,每天的时间慢500*0.0864=43.2s 假设服务器现在标准的PPM为 A,为了让系统24小时快1s。则ppm的调整为A- 1*10^6/3600/24=A-11.574074。 处理闰秒如果想让时钟在一天内慢1s,则可以用ntptime -f把frequency改为服务器当前的值+11.574 ubuntu@ip-172-31-23-155:~/ntp-4.2.8p9$ ntptime ntp_gettime() returns code 0 (OK) time dc1e24a0.5e832b98 Mon, Jan 9 2017 15:02:56.369, (.369189989), maximum error 73959 us, estimated error 101 us, TAI offset 0 ntp_adjtime() returns code 0 (OK) modes 0x0 (), offset 75.601 us, frequency 18.063 ppm, interval 1 s, maximum error 73959 us, estimated error 101 us, status 0x2001 (PLL,NANO), time constant 5, precision 0.001 us, tolerance 500 ppm, ...

January 9, 2017 · 3 min · pm

升级kernel 4.9 尝试BBR

BBR介绍 BBR (Bottleneck Bandwidth and RTT)算法对弱网络下提升性能有一定帮助。虽然说在国内很多公司也都内部有类似的内核协议栈的改进,并且很多的效果都不比google差,但是这个好歹是进入了kernel 主干的,大家都可以自由使用。 centos7 编译升级 centos编译内核rpm yum -y install gcc ncurses ncurses-devel bc openssl–devel perl-devel make localmodconfig make menuconfig # 选中BBR grep -i bbr .config #确认是否选中 make rpm ### 修改引导项目 grub2-set-default 0 grub2-mkconfig -o /boot/grub2/grub.cfg 重启后查看 [root@CentOS ipv4]# uname -a Linux CentOS 4.9.0 #1 SMP Sat Dec 17 00:47:52 CST 2016 x86_64 x86_64 x86_64 GNU/Linux [root@CentOS ipv4]# sysctl net.ipv4.tcp_available_congestion_control net.ipv4.tcp_available_congestion_control = bbr reno cubic ## ubuntu 16.04升级 因为我买AWS EC2的时候忘记选磁盘了,磁盘只有8G,造成本地编译内核的时候发现编译不了。就网上找了几个deb包直接安装上了。 ```bash wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.9/linux-image-4.9.0-040900-generic_4.9.0-040900.201612111631_amd64.deb wget http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.9/linux-headers-4.9.0-040900-generic_4.9.0-040900.201612111631_amd64.deb get http://kernel.ubuntu.com/~kernel-ppa/mainline/v4.9/linux-headers-4.9.0-040900_4.9.0-040900.201612111631_all.deb ...

December 16, 2016 · 1 min · pm