2016年9月24日星期六

在OS X系统使用QEMU模拟器为UBNT EdgeRouter编译deb软件包

一、在OS X系统安装QEMU

1、安装Homebrew

Homebrew是OS X上强大的包管理器。为了解决QEMU安装的依存关系,我们先按照Homebrew官网的介绍安装Homebrew:
http://brew.sh/index_zh-cn.html


2、使用Homebrew安装QEMU

Bash
$ brew install qemu


二、在QEMU上构建EdgeRouter的软件包编译环境

此步骤主要参考了以下文章:
https://blog.austinchou.com/compile-shadowsocks-libev-and-chinadns-for-edgerouter-poe/

1、在QEMU上构建MIPS64编译环境

首先在EdgeRouter中使用打开CLI窗口登陆,使用uname命令查看平台架构:
Bash
$ uname -a 
Linux ERL-3 3.10.20-UBNT #1 SMP Sat May 28 09:46:11 PDT 2016 mips64 GNU/Linux
从显示结果可以看到是mips64架构。
然后从下面网址下载已经预安装mips64架构的debian系统的系统映像。
https://people.debian.org/~aurel32/qemu/
选择mips文件夹,依据说明下载wheezy 64位相关的两个文件:
vmlinux-3.2.0-4-5kc-malta 
debian_wheezy_mips_standard.qcow2
然后再OS X系统的终端中运行以下命令启动:
Bash
qemu-system-mips64 -M malta -kernel vmlinux-3.2.0-4-5kc-malta -hda debian_wheezy_mips_standard.qcow2 -append "root=/dev/sda1 console=tty0"

搬瓦工Debian系统Lighttpd/SQLite/PHP安装Z-Blog

1.系统选择

众所周知,Debian是Linux系统中做Web服务器比较稳定的发行版。由于Debian 6(squeeze)已经停止支持,而搬瓦工上的Debian 8又是全64位系统,所以我们选用Debian 7系统。
Debian Long Term Support
Debian 6   “Squeeze” until 29th of February 2016
Debian 7   “Wheezy” from 26th of April 2016 to 31st of May 2018

2.安装系统

先在搬瓦工管理后台KiwiVM面板左侧的Main Controls里面使用Stop按钮停止服务器。
然后选择Install new OS,选择debian-7.0-x86-minimal,在I agree that all existing data on my VPS will be lost.前面打勾,点击Reload重装系统。
重装系统后会生成新的SSH端口号和root账户密码。要记录下来方便SSH远程管理。

3.升级系统

系统安装完成后要先升级系统,先更新软件包信息:
Bash
apt-get update
运行此命令时可能会出现以下出错信息:
There is no public key available for the following key ids ****
运行以下命令解决这个问题:
Bash
apt-get install debian-archive-keyring
apt-key update

4.安装Lighttpd/SQLite/PHP

4.1.安装Lighttpd

Bash
apt-get install lighttpd

4.2.安装SQLite

Bash
apt-get install sqlite

4.3.安装php5

Bash
apt-get install php5-cgi php5-curl php5-gd php5-idn php-pear php5-imagick php5-imap php5-mcrypt php5-mhash php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl

4.4.修改php配置文件

Bash
vi /etc/php5/cgi/php.ini
查找cgi.fix_pathinfo,将其值改为1:
PHP
cgi.fix_pathinfo=1

4.5.配置lighttpd

Bash
vi /etc/lighttpd/lighttpd.conf
更改文件内容为:
Bash
server.modules = (
 "mod_access",
 "mod_alias",
 "mod_compress",
 "mod_redirect",
 "mod_rewrite",
 "mod_fastcgi",
)
server.document-root = "/var/www"
server.upload-dirs = ( "/var/cache/lighttpd/uploads" )
server.errorlog = "/var/log/lighttpd/error.log"
server.pid-file = "/var/run/lighttpd.pid"
server.username = "www-data"
server.groupname = "www-data"

index-file.names = ( "index.php", "index.html",
 "index.htm", "default.htm",
 " index.lighttpd.html" )
url.access-deny = ( "~", ".inc" )

static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )
include_shell "/usr/share/lighttpd/use-ipv6.pl"

dir-listing.encoding = "utf-8"
server.dir-listing = "enable"

compress.cache-dir = "/var/cache/lighttpd/compress/"
compress.filetype = ( "application/x-javascript", "text/css", "text/html", "text/plain" )

include_shell "/usr/share/lighttpd/create-mime.assign.pl"
include_shell "/usr/share/lighttpd/include-conf-enabled.pl"

fastcgi.server = ( ".php" => ((
  "bin-path" => "/usr/bin/php5-cgi",
  "socket" => "/tmp/php.socket",
  "max-procs" => 1,
  "bin-environment" => (
    "PHP_FCGI_CHILDREN" => "4",
    "PHP_FCGI_MAX_REQUESTS" => "1000"
  ),
)))
 重启lighttpd使配置生效:
Bash
/etc/init.d/lighttpd restart

5.功能测试

使用phpinfo检测:
Bash
vi /var/www/phpinfo.php
输入以下内容:
PHP
<?php
phpinfo();
?>
然后可以通过IP地址访问此页面:
http://11.22.33.44/phpinfo.php

6.安装Z-Blog

6.1.在主目录下载Z-Blog文件


Bash
cd ~
wget https://github.com/zblogcn/Release/raw/master/zip/Z-BlogPHP_1_4_Deeplue_150101.zip
下载完成后用unzip命令解压发现命令不存在……
先安装unzip:
Bash
apt-get install unzip
然后解压备用:
Bash
unzip Z-BlogPHP_1_4_Deeplue_150101.zip
解压后Blog程序在/root/Release文件夹。

6.2.创建站点目录

Bash
mkdir -p /home/wwwroot/blog
在home/wwwroot创建站点,并根据站点内容创建子目录,如果以后进行多站点管理可以清除的知道站点目录。

6.3.修改站点环境连接

Bash
vi /etc/lighttpd/lighttpd.conf
在最后一行添加:
Bash
$HTTP["host"] =~ "(^|\.)localhost\.localdomain$" {
 server.document-root = "/home/wwwroot/blog"
 accesslog.filename = "/var/log/lighttpd/blog/access.log"
 server.error-handler-404 = "/404.html"
}
根据自己的域名修改localhost和localdomain。
重启lighttpd使配置生效:
Bash
/etc/init.d/lighttpd restart

6.4.站点安装

将刚才下载解压好的程序文件放到/home/wwwroot/blog/目录下:
Bash
cp -R ~/Release/ /home/wwwroot/blog/
为了防止运行出错,需要修改文件夹权限:
Bash
chown -R www-data:www-data /home/wwwroot
用IP地址(或者已经绑定好的域名)直接打开:
http://11.22.33.44/
根据安装向导安装即可。

2016年9月17日星期六

UBNT airMax设备 airOS 5.5.8以上版本开启compliance test模式方法

SSH登入设备。

方法一:
touch /etc/persistent/ct
save
reboot

方法二:
echo "radartool cactime 1000" > /etc/persistent/rc.poststart
echo "echo '<option value=\"511\">MLINK</option>' >> /etc/ccodes.inc" >> /etc/persistent/rc.poststart
chmod +x /etc/persistent/rc.poststart
cfgmtd -w -p /etc/
touch /etc/persistent/ct
reboot

方法二会使Main页面出现Costum Script : Enabled,并且国家代码出现MLINK 。国家代码选择MLINK 即可。

2016年9月15日星期四

UniFi Picostation M2HP 刷入openwrt

第一步,选择bullut m的openwrt固件
第二步,长按reset进入tftp模式
第三步,tftp刷入openwrt的factory固件
第四步,通过192.168.1.1 LuCIa管理界面,启用wifi
第五步,wifi连入设备,确保wifi连接通畅,将eth0从lan中移除
第六步,新建wan接口,物理设备为eth0,设置为dhcp 客户端或者pppoe拨号。

注意:airOS 5.6之后uboot无法正常刷第三方固件,openwrt给的办法是降级的5.5版本的固件,但网络上难以找到。我的办法是picostation由airmax改unifi,然后刷4.8.20的unifi controller带的固件。刷完后uboot被降级,可以刷入openwrt。

2016年8月29日星期一

UBNT Edgemax Edgerouter Lite-3内部USB存储损坏

手动制作恢复U盘:
找一台Linux电脑
1.大于2G U盘一个,格式化俩分区(FAT/ext3),
# Device Boot Start End Blocks Id System
# /dev/sdd1 2048 292863 145408 c W95 FAT32 (LBA)
# /dev/sdd2 292864 3710975 1709056 83 Linux

2.下载1.6升级包解压(ER-e100.v1.6.0.4716006.tar);
3.将ER-e100.v1.6.0.4716006目录下得vmlinux.64和vmlinux.64.md5,复制到第一个分区根目录下;
4.将ER-e100.v1.6.0.4716006目录下squashfs.tmp,用dd写入第二个分区“ dd if=/路径/squashfs.tmp of=/dev/sda2 bs=4096”
5. sync

6,将U盘插入erlite,通电启动。

2016年8月27日星期六

UniFi UAP-LR刷入openwrt

由于需要一台吸顶安装的胖AP,刚好手头还有台UAP-LR,决定刷入openwrt当胖AP使用。


需要注意的是,在openwrt的wiki页面,将UAP和UAP-LR列在了一起:
https://wiki.openwrt.org/toh/ubiquiti/unifi
一开始输入了UAP的openwrt固件,结果UAP-LR直接变砖了。
后来用TFTP刷入UAP-Outdoor的固件,才正常使用。参考页面:
https://forum.openwrt.org/viewtopic.php?id=55032


1、使用tftp刷入最新openwrt固件

建议使用weird-solutions的TFTP Client,非常好用。

UAP-LR进入TFTP模式需要断电后,按住RESET上电,一直等到UAP-LR绿色和橙色的灯交替闪烁才行。

2、启用SSH

刷入openwrt固件后,进入192.168.1.1使用LuCI设置密码,启用SSH。

3、设置灯的状态

SSH登陆设备,设置灯亮,参考如下网址:

https://wiki.openwrt.org/toh/ubiquiti/unifi

发现将如下设置添加到 /etc/config/system文件尾部后,重启仍不亮
config led
 option default '0'
 option name 'led1'
 option sysfs 'ubnt:green:dome'
 option trigger 'netdev'
 option dev 'br-lan'
 option mode 'link'

config led
 option default '0'
 option name 'led2'
 option sysfs 'ubnt:orange:dome'
 option trigger 'netdev'
 option dev 'br-lan'
 option mode 'tx rx'
进入/sys/class/leds目录,发现灯名称改为ubnt:green:front和 ubnt:orange:front

修改配置:
config led
 option default '0'
 option name 'led1'
 option sysfs 'ubnt:green:front'
 option trigger 'netdev'
 option dev 'br-lan'
 option mode 'link'

config led
 option default '0'
 option name 'led2'
 option sysfs 'ubnt:orange:front'
 option trigger 'netdev'
 option dev 'br-lan'
 option mode 'tx rx'

4、配置网络



由于UAP-LR只有一个网口,所以跟一般的路由器不同,默认情况下这个网口是LAN口,我们需要拿UAP-LR当路由器,必须将这个口设为WAN口进行拨号。需要按照特定顺序配置:




4.1. 使用LuCI页面启用无线,无线是桥接到LAN网络的。


4.2. 连接到无线网络,断开电脑到设备的网线连接。确保可以通过无线SSH登录设备。

4.3. 默认eth0对应LAN,eth1对应WAN,由于网口对应eth0,所以我们要修改/etc/config/network文件,替换LAN和WAN下的eth0和eth1,使LAN对应eth1,WAN对应eth0。

4.4. 重启设备。

4.5. 将PoE电源上的LAN连接到猫上,设置WAN口为PPPoE,并设置拨号密码。

4.6. 连接openwrt的无线,上网吧。

2016年3月25日星期五

Debian系统Shadowsocks安装与配置

一、安装之前确保系统最新


# apt-get update&&apt-get upgrage

二、安装python版的shadowsocks


# apt-get install python-pip
# pip install shadowsocks


三、配置与启动


创建配置文件:

# vi /etc/shadowsocks/config.json


将下述内容粘贴:


{
    "server":"107.182.179.116",
    "local_address": "127.0.0.1",
    "local_port":1080,
    "port_password":{
         "443":"myPassword1",
         "8388":"myPassword2"
    },

    "timeout":600,
    "method":"aes-256-cfb",
    "fast_open": false,
    "workers": 2
}


将server-ip以及myPassword更改为服务器的IP地址和自己的密码。


然后可以使用下述命令启动或者停止shadowsocks服务:


ssserver -c /etc/shadowsocks/config.json -d start
ssserver -c /etc/shadowsocks/config.json -d stop


想让shadowsocks开机自动运行,修改rc.local

# vi /etc/rc.local


将下述内容放到exit 0之前:


/usr/bin/python /usr/local/bin/ssserver -c /etc/shadowsocks/config.json -d start

移动光猫改桥接模式

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