2017年12月22日星期五

Debian8添加开机启动项 (update-rc.d)

例如:将test.sh脚本添加到开机自启。

1.将test.sh脚本放到/etc/init.d/目录下

cp test.sh /etc/init.d/  
cd /etc/init.d/  
chmod +x  test.sh  

2.设置开机自启

update-rc.d test.sh defaults  
运行update-rc.d很可能会出现错误提示:
insserv: warning: script 'test.sh' missing LSB tags and overrides  
这是因为test.sh不符合debian开机自启文件的内容规范,debian要求文件头部有启动信息。参考同目录下的/etc/init.d/skeleton文件头,把以下内容复制到test.sh再运行update-rc.d test.sh defaults
#!/bin/sh
### BEGIN INIT INFO
# Provides:          test
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Should-Start: $network
# Should-Stop: $network
# Default-Start:        2 3 4 5
# Default-Stop:         0 1 6
# Short-Description: test
# Description: test
### END INIT INFO

3.删除开机启动

update-rc.d -f test.sh remove

2017年4月19日星期三

在Debian8 / CentOS7上使用systemd管理的服务如何查看日志

journalctl

systemd管理shadowsocks-libev多端口自启动

以下在Debian8和CentOS7测试成功。仅路径有所不同。
安装参考shadowsocks-libev在github的说明。Debian用jessie-backports安装,CentOS用Fedora-Copr安装。


以下说明为Debian8上的操作。


cp /lib/systemd/system/shadowsocks-libev.service /lib/systemd/system/shadowsocks-libev1.service
nano /lib/systemd/system/shadowsocks-libev1.service

#  This file is part of shadowsocks-libev.
#
#  Shadowsocks-libev is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 3 of the License, or
#  (at your option) any later version.
#
#  This file is default for Debian packaging. See also
#  /etc/default/shadowsocks-libev for environment variables.

[Unit]
Description=Shadowsocks-libev 1 Server Service
Documentation=man:shadowsocks-libev(8)
After=network.target

[Service]
Type=simple
EnvironmentFile=/etc/default/shadowsocks-libev1
User=nobody
Group=nogroup
LimitNOFILE=32768
ExecStart=/usr/bin/ss-server -c $CONFFILE $DAEMON_ARGS

[Install]
WantedBy=multi-user.target



cp /etc/default/shadowsocks-libev /etc/default/shadowsocks-libev1
nano /etc/default/shadowsocks-libev1

# Defaults for shadowsocks initscript
# sourced by /etc/init.d/shadowsocks-libev
# installed at /etc/default/shadowsocks-libev by the maintainer scripts

#
# This is a POSIX shell fragment
#
# Note: `START', `GROUP' and `MAXFD' options are not recognized by systemd.
# Please change those settings in the corresponding systemd unit file.

# Enable during startup?
START=yes

# Configuration file
CONFFILE="/etc/shadowsocks-libev/config1.json"

# Extra command line arguments
DAEMON_ARGS="-u -v"

# User and group to run the server as
USER=nobody
GROUP=nogroup

# Number of maximum file descriptors
MAXFD=32768



cp /etc/shadowsocks-libev/config.json /etc/shadowsocks-libev/config1.json
nano /etc/default/shadowsocks-libev1

修改config1.json文件。
systemctl enable shadowsocks-libev1
systemctl start shadowsocks-libev1
systemctl status shadowsocks-libev1

2017年4月8日星期六

EdgeRouter Lite更换U盘

EdgeRouter Lite 确实性能强悍,但是自带的 USB 存储质量确实一般。

下面介绍 EdgeRouter Lite 原有 USB 存储损坏后新 U 盘制作系统启动盘的方法。此操作需要一定的 Linux 基础,但无需额外的辅助设备( Console 线等)。进需要两个U盘,一台电脑即可完成。(一个U盘是用来替换原有EdgeRouter Lite里面已损坏的U盘,这个U盘要注意尺寸,太大装不下。容量根据自己需要来,2G以上。另一个U盘用来制作Linux启动盘,4G以上)。

一、准备 Linux 环境

如果你已经有 Linux 操作系统,那么请跳过这一步。
下载 Deepin 安装盘:
https://www.deepin.org/download/
推荐64位,使用ISO内的启动盘制作工具制作一个USB启动盘。
开机后切换到U盘启动,按“上”方向键进入failsafe模式启动。

二、分区

使用Deepin自带的图形界面GParted分区编辑器对要替换的U盘进行分区,一个分区至少150M,fat16格式;剩余空间设置为第二个分区,ext3格式,两个分区均为主分区。

为第一个分区设置lba标志。

三、放入启动镜像

1、下载固件

从UBNT官网下载EdgeRouter Lite固件:
https://www.ubnt.com/download/edgemax
或者:
http://www.ubnt.com.cn/download/
下载固件为tar格式,解压。

2、将固件放入U盘

将vmlinux.tmp重命名为vmlinux.64
将vmlinux.tmp.md5重命名为vmlinux.64.md5
将vmlinux.64和vmlinux.64.md5复制到第一个分区(fat16)。

将squashfs.tmp重命名为squashfs.img
将squashfs.tmp.md5重命名为squashfs.img.md5
将version.tmp重命名为version
将上述三个文件复制到第二个分区,由于ext3分区有权限管理,无法直接复制,打开深度终端Deepin Terminal,执行命令:
cd /home/deepin/Desktop/ER-e100.v1.9.1.4939093 #
sudo mv squashfs.img /media/deepin/3b0232gersfffesfes-abi3hf #具体路径可以在文件管理器中点选路径栏查看。
sudo mv squashfs.img.md5 /media/deepin/3b0232gersfffesfes-abi3hf
sudo mv version /media/deepin/3b0232gersfffesfes-abi3hf

3、创建数据可写目录

sudo mkdir /media/deepin/3b0232gersfffesfes-abi3hf/w
大功告成,可以放入EdgeRouter Lite启动了。

第一次启动,多等一会~

2017年2月15日星期三

EdgeRouter 使用dnsmasq 进行广告过滤

参考:https://help.ubnt.com/hc/en-us/articles/205223340-EdgeRouter-Ad-blocking-content-filtering-using-EdgeRouter


第一步,获取并生成conf配置文件:
#!/bin/bash
# define variables
host_version=0
host_new=0
host_url="
https://raw.githubusercontent.com/vokins/yhosts/master/hosts"

cd /root/hosts
echo
date
echo
echo +++ Delete old files...
echo
rm -f temp1 temp2 temp3 result host
rm -f hosts*

echo +++ Download new hosts file...
echo
wget $host_url

echo +++ Check if download succeeded...
echo
if [ ! -f hosts ]; then
    echo --- Download failed... Exit.
    exit
fi

host_version=$(sed -n '1p' version | awk -F"=" '{print $2}')
cat hosts|grep version|sed -n 1p > version
host_new=$(sed -n '1p' version | awk -F"=" '{print $2}')

echo +++ Version check:
echo +++ Old: $host_version, New: $host_new

# check hosts version
if [ "$host_version"x = "$host_new"x ]; then
    echo --- No update for hosts. Exit
    exit
fi



########################################################
# following lines are just shell learning, ignore.
# get column 2, space as delimiter.
# cat hosts|cut -d ' ' -f 2
#
# compress extra space
# cat hosts|tr -s ' '
#
# compress extra space and get column 2, space as delimiter
# cat hosts|tr -s ' '|cut -d ' ' -f 2
#
# remove comment line start with "#"
# cat hosts| grep -v ^# | grep -v ^$
########################################################

echo
echo +++ Split hosts file to two column file.
cat hosts| grep -v ^# | grep -v ^$|tr -s ' '|cut -d ' ' -f 1 >temp1
cat hosts| grep -v ^# | grep -v ^$|tr -s ' '|cut -d ' ' -f 2 >temp2

# combine two files and add "address=/" at beginning of each line
echo +++ Combine two column file to one.
paste temp2 temp1 -d "/" | sed 's/^/address=\/&/g' >temp3
echo +++ Add self defined hosts
cat self temp3 > result
# remove ipv6 address and useless hosts
echo +++ Remove useless hosts.
sed -e '/\:/d' result | sed -e '/XiaoQiang/d' | sed -e '/localhost/d' > conf

echo +++ Delete temp files.
rm -f temp1 temp2 temp3 result

echo
echo +++ Copy files to web folder
cp -f ./version /usr/share/nginx/html/hosts/
cp -f ./conf /usr/share/nginx/html/hosts/
echo --- Hosts conf file updated.




将上述脚本设置为Linux开机启动。


第二步,配置EdgeRouter

2017年1月3日星期二

移动光猫改桥接模式

使用以下管理用户名和密码登录移动光猫: 用户名:CMCCAdmin 密码:aDm8H%MdA 登陆后,查看“网络-宽带设置”,选择名称中含有“INTERNET”的连接名称,截图记录原有INTERNET设置: 截图记录后,删除此配置。 参考原有配置,新建一个INTERNET连接,并...