Bernie Yu http://bernieyu.com 复刻生活 Tue, 17 May 2016 09:03:15 +0000 zh-CN hourly 1 https://wordpress.org/?v=4.2.38 VPS从DirectSpace迁移到vultr http://bernieyu.com/2016/05/vps-from-directspace-to-vultr/ http://bernieyu.com/2016/05/vps-from-directspace-to-vultr/#comments Tue, 17 May 2016 09:01:59 +0000 http://bernieyu.com/?p=271   >>阅读全文<<]]> DirectSpace的VPS已经用了好几年,稳定性差强人意。

而且由于是OpenVZ架构,做SS加速不是很理想,于是便决定迁到其他VPS。

对比后,最终决定用Vultr的$5/mo 产品,可惜日本机房要绕行美国,所以选了LA的机房,不过速度还好,比DS的要快不少。

对SS做了优化后,youtube1080P无压力。

]]>
http://bernieyu.com/2016/05/vps-from-directspace-to-vultr/feed/ 0
查看阻止电脑进入休眠的程序 http://bernieyu.com/2015/12/query-process-prevent-into-standby/ http://bernieyu.com/2015/12/query-process-prevent-into-standby/#comments Fri, 25 Dec 2015 07:22:54 +0000 http://bernieyu.com/?p=268 打开命令提示符窗口后,键入以下命令:

powercfg /requests
]]>
http://bernieyu.com/2015/12/query-process-prevent-into-standby/feed/ 0
HDCN,纪念 http://bernieyu.com/2015/10/hdcn%ef%bc%8c%e7%ba%aa%e5%bf%b5/ http://bernieyu.com/2015/10/hdcn%ef%bc%8c%e7%ba%aa%e5%bf%b5/#comments Thu, 29 Oct 2015 06:03:31 +0000 http://bernieyu.com/?p=264 竟然要关站了。。。。

发文留念。

 

]]>
http://bernieyu.com/2015/10/hdcn%ef%bc%8c%e7%ba%aa%e5%bf%b5/feed/ 0
[转] lsyncd实时同步搭建指南——取代rsync+inotify http://bernieyu.com/2015/10/lsyncd-synchronize-realtime/ http://bernieyu.com/2015/10/lsyncd-synchronize-realtime/#comments Thu, 22 Oct 2015 00:59:40 +0000 http://bernieyu.com/?p=261   >>阅读全文<<]]> 转自http://seanlook.com/2015/05/06/lsyncd-synchronize-realtime/

1. 几大实时同步工具比较

1.1 inotify + rsync

最近一直在寻求生产服务服务器上的同步替代方案,原先使用的是inotify + rsync,但随着文件数量的增大到100W+,目录下的文件列表就达20M,在网络状况不佳或者限速的情况下,变更的文件可能10来个才几M,却因此要发送的文件列表就达20M,严重减低的带宽的使用效率以及同步效率;更为要紧的是,加入inotifywait在5s内监控到10个小文件发生变化,便会触发10个rsync同步操作,结果就是真正需要传输的才2-3M的文件,比对的文件列表就达200M。使用这两个组合的好处在于,它们都是最基本的软件,可以通过不同选项做到很精确的控制,比如排除同步的目录,同步多个模块或同步到多个主机。

搭建过程参考 Linux下同步工具inotify+rsync使用详解

1.2 sersync

后来听同事说 sersync 这么个工具可以提高同步的性能,也解决了同步大文件时出现异常的问题,所以就尝试了一下。sersync是国内的一个开发者开源出来的,使用c++编写,采用多线程的方式进行同步,失败后还有重传机制,对临时文件过滤,自带crontab定时同步功能。网上看到有人说性能还不错,说一下我的观点:

  • 国产开源,文档不是很全,在2011年之后就没更新了(googlecode都要快关闭了,其实可以转交其他人维护),网上关于它的使用和讨论都止于10年了
  • 采用xml配置文件的方式,可读性比较好,但是有些原生的有些功能没有实现就没法使用了
  • 无法实现多目录同步,只能通过多个配置文件启动多个进程
  • 文件排除功能太弱。这个要看需求,不是每个人都需要排除子目录。而对于我的环境中,这个功能很重要,而且排除的规则较多
  • 虽然提供插件的功能,但很鸡肋,因为软件本身没有持续更新,也没有看到贡献有其它插件出现(可能是我知识面不够,还用不到里面的refreshCDN plugin)。

虽然不懂c++,但大致看了下源码 FileSynchronize,拼接rsync命令大概在273行左右,最后一个函数就是排除选项,简单一点可以将--exclude=改成--eclude-from来灵活控制。有机会再改吧。

另外,在作者的文章 Sersync服务器同步程序 项目简介与设计框架 评论中,说能解决上面 rsync + inotify中所描述的问题。阅读了下源码,这个应该是没有解决,因为在拼接rsync命令时,后面的目的地址始终是针对module的,只要执行rsync命令,就会对整个目录进行遍历,发送要比对的文件列表,然后再发送变化的文件。sersync只是减少了监听的事件,减少了rsync的次数——这已经是很大的改进,但每次rsync没办法改变。(如有其它看法可与我讨论)

其实我们也不能要求每一个软件功能都十分健全,关键是看能否满足我们当下的特定的需求。所谓好的架构不是设计出来的,而是进化来的。目前使用sersync2没什么问题,而且看了它的设计思路应该是比较科学的,特别是过滤队列的设计。双向同步看起来也是可以实现。

1.3 lsyncd

废话说这么多,本文就是介绍它了。有些博客说lsyncd是谷歌开源的,实际不是了,只是托管在了googlecode上而已,幸运的是已经迁移到github了:https://github.com/axkibe/lsyncd

Lysncd 实际上是lua语言封装了 inotify 和 rsync 工具,采用了 Linux 内核(2.6.13 及以后)里的 inotify 触发机制,然后通过rsync去差异同步,达到实时的效果。我认为它最令人称道的特性是,完美解决了 inotify + rsync海量文件同步带来的文件频繁发送文件列表的问题 —— 通过时间延迟或累计触发事件次数实现。另外,它的配置方式很简单,lua本身就是一种配置语言,可读性非常强。lsyncd也有多种工作模式可以选择,本地目录cp,本地目录rsync,远程目录rsyncssh。

实现简单高效的本地目录同步备份(网络存储挂载也当作本地目录),一个命令搞定。

2. 使用 lsyncd 本地目录实时备份

这一节实现的功能是,本地目录source实时同步到另一个目录target,而在source下有大量的文件,并且有部分目录和临时文件不需要同步。

2.1 安装lsyncd

安装lsyncd极为简单,已经收录在ubuntu的官方镜像源里,直接通过apt-get install lsyncd就可以。
在Redhat系(我的环境是CentOS 6.2 x86_64 ),可以手动去下载 lsyncd-2.1.5-6.fc21.x86_64.rpm,但首先你得安装两个依赖yum install lua lua-devel。也可以通过在线安装,需要epel-release扩展包:

1
2
# rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
# yum install lsyncd

源码编译安装
从源码编译安装可以使用最新版的lsyncd程序,但必须要相应的依赖库文件和编译工具:yum install lua lua-devel asciidoc cmake

googlecode lsyncd 上下载的lsyncd-2.1.5.tar.gz,直接./configuremake && make install就可以了。

从github上下载lsyncd-master.zip 的2.1.5版本使用的是 cmake 编译工具,无法./configure

1
2
3
4
# uzip lsyncd-master.zip
# cd lsyncd-master
# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lsyncd-2.1.5
# make && make install

我这个版本编译时有个小bug,如果按照INSTALLbuild目录中make,会提示:

1
2
3
4
5
6
[100%] Generating doc/lsyncd.1
Updating the manpage
a2x: failed: source file not found: doc/lsyncd.1.txt
make[2]: *** [doc/lsyncd.1] Error 1
make[1]: *** [CMakeFiles/manpage.dir/all] Error 2
make: *** [all] Error 2

解决办法是要么直接在解压目录下cmake,不要mkdir build,要么在CMakeList.txt中搜索doc字符串,在前面加上${PROJECT_SOURCE_DIR}

2.2 lsyncd.conf

下面都是在编译安装的情况下操作。

2.2.1 lsyncd同步配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# cd /usr/local/lsyncd-2.1.5
# mkdir etc var
# vi etc/lsyncd.conf
settings {
logfile =“/usr/local/lsyncd-2.1.5/var/lsyncd.log”,
statusFile =“/usr/local/lsyncd-2.1.5/var/lsyncd.status”,
inotifyMode = “CloseWrite”,
maxProcesses = 7,
nodaemon =true,
}
sync {
default.rsync,
source = “/tmp/src”,
target = “/tmp/dest”,
excludeFrom = “/etc/rsyncd.d/rsync_exclude.lst”,
rsync = {
binary = “/usr/bin/rsync”,
archive = true,
compress = true,
verbose = true
}
}

到这启动 lsycnd 就可以完成实时同步了,默认的许多参数可以满足绝大部分需求,非常简单。

2.2.2 lsyncd.conf配置选项说明

settings
里面是全局设置,--开头表示注释,下面是几个常用选项说明:

  • logfile 定义日志文件
  • stausFile 定义状态文件
  • nodaemon=true 表示不启用守护模式,默认
  • statusInterval 将lsyncd的状态写入上面的statusFile的间隔,默认10秒
  • inotifyMode 指定inotify监控的事件,默认是CloseWrite,还可以是ModifyCloseWrite or Modify
  • maxProcesses 同步进程的最大个数。假如同时有20个文件需要同步,而maxProcesses = 8,则最大能看到有8个rysnc进程
  • maxDelays 累计到多少所监控的事件激活一次同步,即使后面的delay延迟时间还未到

sync
里面是定义同步参数,可以继续使用maxDelays来重写settings的全局变量。一般第一个参数指定lsyncd以什么模式运行:rsyncrsyncsshdirect三种模式:

  • default.rsync :本地目录间同步,使用rsync,也可以达到使用ssh形式的远程rsync效果,或daemon方式连接远程rsyncd进程;
    default.direct :本地目录间同步,使用cprm等命令完成差异文件备份;
    default.rsyncssh :同步到远程主机目录,rsync的ssh模式,需要使用key来认证
  • source 同步的源目录,使用绝对路径。
  • target 定义目的地址.对应不同的模式有几种写法:
    /tmp/dest :本地目录同步,可用于directrsync模式
    172.29.88.223:/tmp/dest :同步到远程服务器目录,可用于rsyncrsyncssh模式,拼接的命令类似于/usr/bin/rsync -ltsd --delete --include-from=- --exclude=* SOURCE TARGET,剩下的就是rsync的内容了,比如指定username,免密码同步
    172.29.88.223::module :同步到远程服务器目录,用于rsync模式
    三种模式的示例会在后面给出。
  • init 这是一个优化选项,当init = false,只同步进程启动以后发生改动事件的文件,原有的目录即使有差异也不会同步。默认是true
  • delay 累计事件,等待rsync同步延时时间,默认15秒(最大累计到1000个不可合并的事件)。也就是15s内监控目录下发生的改动,会累积到一次rsync同步,避免过于频繁的同步。(可合并的意思是,15s内两次修改了同一文件,最后只同步最新的文件)
  • excludeFrom 排除选项,后面指定排除的列表文件,如excludeFrom = "/etc/lsyncd.exclude",如果是简单的排除,可以使用exclude = LIST
    这里的排除规则写法与原生rsync有点不同,更为简单:

    • 监控路径里的任何部分匹配到一个文本,都会被排除,例如/bin/foo/bar可以匹配规则foo
    • 如果规则以斜线/开头,则从头开始要匹配全部
    • 如果规则以/结尾,则要匹配监控路径的末尾
    • ?匹配任何字符,但不包括/
    • *匹配0或多个字符,但不包括/
    • **匹配0或多个字符,可以是/

rsync
(提示一下,deleteexclude本来都是rsync的选项,上面是配置在sync中的,我想这样做的原因是为了减少rsync的开销)

  • bwlimit 限速,单位kb/s,与rsync相同(这么重要的选项在文档里竟然没有标出)
  • compress 压缩传输默认为true。在带宽与cpu负载之间权衡,本地目录同步可以考虑把它设为false
  • perms 默认保留文件权限。
  • 其它rsync的选项

其它还有rsyncssh模式独有的配置项,如hosttargetdirrsync_pathpassword_file,见后文示例。rsyncOps={"-avz","--delete"}这样的写法在2.1.*版本已经不支持。

lsyncd.conf可以有多个sync,各自的source,各自的target,各自的模式,互不影响。

2.3 启动lsyncd

使用命令加载配置文件,启动守护进程,自动同步目录操作。

lsyncd -log Exec /usr/local/lsyncd-2.1.5/etc/lsyncd.conf

2.4 lsyncd.conf其它模式示例

以下配置本人都已经过验证可行,必须根据实际需要裁剪配置:

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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
settings {
logfile =“/usr/local/lsyncd-2.1.5/var/lsyncd.log”,
statusFile =“/usr/local/lsyncd-2.1.5/var/lsyncd.status”,
inotifyMode = “CloseWrite”,
maxProcesses = 8,
}
— I. 本地目录同步,direct:cp/rm/mv。 适用:500+万文件,变动不大
sync {
default.direct,
source = “/tmp/src”,
target = “/tmp/dest”,
delay = 1
maxProcesses = 1
}
— II. 本地目录同步,rsync模式:rsync
sync {
default.rsync,
source = “/tmp/src”,
target = “/tmp/dest1″,
excludeFrom = “/etc/rsyncd.d/rsync_exclude.lst”,
rsync = {
binary = “/usr/bin/rsync”,
archive = true,
compress = true,
bwlimit = 2000
}
}
— III. 远程目录同步,rsync模式 + rsyncd daemon
sync {
default.rsync,
source = “/tmp/src”,
target = “syncuser@172.29.88.223::module1″,
delete=“running”,
exclude = { “.*”, “.tmp” },
delay = 30,
init = false,
rsync = {
binary = “/usr/bin/rsync”,
archive = true,
compress = true,
verbose = true,
password_file = “/etc/rsyncd.d/rsync.pwd”,
_extra = {“–bwlimit=200″}
}
}
— IV. 远程目录同步,rsync模式 + ssh shell
sync {
default.rsync,
source = “/tmp/src”,
target = “172.29.88.223:/tmp/dest”,
target = “root@172.29.88.223:/remote/dest”,
— 上面target,注意如果是普通用户,必须拥有写权限
maxDelays = 5,
delay = 30,
init = true,
rsync = {
binary = “/usr/bin/rsync”,
archive = true,
compress = true,
bwlimit = 2000
rsh = “/usr/bin/ssh -p 22 -o StrictHostKeyChecking=no”
— 如果要指定其它端口,请用上面的rsh
}
}
— V. 远程目录同步,rsync模式 + rsyncssh,效果与上面相同
sync {
default.rsyncssh,
source = “/tmp/src2″,
host = “172.29.88.223”,
targetdir = “/remote/dir”,
excludeFrom = “/etc/rsyncd.d/rsync_exclude.lst”,
maxDelays = 5,
delay = 0,
init = false,
rsync = {
binary = “/usr/bin/rsync”,
archive = true,
compress = true,
verbose = true,
_extra = {“–bwlimit=2000″},
},
ssh = {
port = 1234
}
}

上面的内容几乎涵盖了所有同步的模式,其中第III个要求像rsync一样配置rsyncd服务端,见本文开头。第IVV配置ssh方式同步,达到的效果相同,但实际同步时你会发现每次同步都会提示输入ssh的密码,可以通过以下方法解决:

在远端被同步的服务器上开启ssh无密码登录,请注意用户身份:

1
2
3
4
user$ ssh-keygen -t rsa
一路回车
user$ cd ~/.ssh
user$ cat id_rsa.pub >> authorized_keys

id_rsa私钥拷贝到执行lsyncd的机器上

1
2
3
user$ chmod 600 ~/.ssh/id_rsa
测试能否无密码登录
user$ ssh user@172.29.88.223

3. lsyncd的其它功能

lsyncd的功能不仅仅是同步,官方手册 Lsyncd 2.1.x ‖ Layer 2 Config ‖ Advanced onAction 高级功能提到,还可以监控某个目录下的文件,根据触发的事件自己定义要执行的命令,example是监控某个某个目录,只要是有jpg、gif、png格式的文件参数,就把它们转成pdf,然后同步到另一个目录。正好在我运维的一个项目中有这个需求,现在都是在java代码里转换,还容易出现异常,通过lsyncd可以代替这样的功能。但,门槛在于要会一点点lua语言(根据官方example还是可以写出来)。

另外偶然想到个问题,同时设置了maxDelaysdelay,当监控目录一直没有文件变化了,也会发生同步操作,虽然没有可rsync的文件。

TO-DO:

  • 其它同步工具:csync2,clsync,btsync,drdb 。
  • lsyncd双向同步:GlusterFS
]]>
http://bernieyu.com/2015/10/lsyncd-synchronize-realtime/feed/ 0
在群晖NAS上搭建MantisBT Bug跟踪系统 http://bernieyu.com/2015/07/install-mantis-bug-tracking-on-synology-nas/ http://bernieyu.com/2015/07/install-mantis-bug-tracking-on-synology-nas/#comments Fri, 10 Jul 2015 04:01:48 +0000 http://bernieyu.com/?p=256   >>阅读全文<<]]>
  • 启用WEB服务
    进入群晖的管理后台,打开控制页面,在里面打开WEB服务
    201506261549467
  • 安装MariaDB数据库,配置好root账户的密码
  • 安装MantisBT
    打开套件中心,找到MantisBT,进行安装。安装过程中要输入Mysql (MariaDB)的root账号和密码,安装过程中会自动创建MantisBT所需要的库表
    20150710110313
  • 配置MantisBT
    • 打开http://synology_address/mantisbt,默认用户名:adminstrator,初始密码:root
    • 现在数据库是用root登录的,为了数据库安全,在数据库里新建mantis用户,仅拥有对mantis库的权限。然后修改config_inc.php:
      $g_hostname = 'localhost';
      $g_db_type = 'mysql';
      $g_database_name = 'mantis';
      $g_db_username = 'mantis';
      $g_db_password = 'mantis';
      
    • 修改默认语言为简体中文:在config_inc.php中添加:
      $g_default_language= 'chinese_simplified';
    • mantis默认新用户都是要邮件激活的,因此还需要添加邮件支持。修改config_defaults_inc.php,把发信人修改为真正使用的发件邮箱地址(有些邮箱服务器会校验发件人地址和真实发件地址,不匹配有可能造成发信失败)
      $g_administrator_email	= 'mantis@host.com';
      $g_webmaster_email	= 'mantis@host.com';
      $g_from_email			= 'mantis@host.com';
      $g_return_path_email	= 'mantis@host.com';

      继续修改发件的smtp信息

      $g_phpMailer_method		= PHPMAILER_METHOD_SMTP;
      $g_smtp_host			= 'smtp.exmail.qq.com';
      $g_smtp_username = 'mantis@host.com';
      $g_smtp_password = 'password';
      $g_smtp_connection_mode = 'ssl';
      $g_smtp_port = 465;
    • 登录到mantis里,新建管理员用户。然后以新建用户登录后,就可以禁用administrator,以保证安全。
    • Tips:
      • 在library\phpmailer下是邮件发送组件,可以新建一个mailtest.php,然后在浏览器打开这个页面测试邮件发送是否正常:
        <?php
        /**
         * @author [pooy] <[pooy@pooy.net]>
         * @blog  http://www.pooy.net
         */
        require 'class.phpmailer.php';
         
        $mail = new PHPMailer;
        $mail->SMTPDebug = 1;
        $mail->IsSMTP();                                      // Set mailer to use SMTP
         
        $mail->Host = 'smtp.exmail.qq.com';  // Specify main and backup server
        $mail->SMTPAuth = true;                               // Enable SMTP authentication
        $mail->Username = 'mantis@host.com';                            // SMTP username
        $mail->Port = 465;
        $mail->Password = 'password';                           // SMTP password
        $mail->SMTPSecure = 'ssl';                            // Enable encryption, 'ssl' also accepted
        $mail->From = 'mantis@host.com';
         
        $mail->FromName = 'Mailer Testing';
        $mail->AddAddress('reciver@host.com');   
        $mail->WordWrap = 50;                                 // Set word wrap to 50 characters
        $mail->IsHTML(true);                                  // Set email format to HTML
         
        $mail->Subject = 'Here is the subject';
        $mail->Body    = 'This is the HTML message body <b>in bold!</b>';
        $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
         
        if(!$mail->Send()) {
           echo 'Message could not be sent.';
           echo 'Mailer Error: ' . $mail->ErrorInfo;
           exit;
        }
         
        echo 'Message has been sent';
        // To load the Chinese version
        $mail->SetLanguage('cn', '/path_to_mantisbt/library/phpmailer/language');
        ?>
      • 在scripts下的send_eamils.php,可以在控制台执行,测试在config_defaults_inc.php里的邮件配置是否能正常发送邮件
        php -q /path_to_mantisbt/scripts/send_emails.php
  • ]]>
    http://bernieyu.com/2015/07/install-mantis-bug-tracking-on-synology-nas/feed/ 0
    在群晖Nas上搭建Git服务器 http://bernieyu.com/2015/06/built-git-server-on-synology-nas/ http://bernieyu.com/2015/06/built-git-server-on-synology-nas/#comments Fri, 26 Jun 2015 07:53:57 +0000 http://bernieyu.com/?p=244   >>阅读全文<<]]>
  • 开启DSM的SSH远程功能
    在“控制面板” →“终端机和SNMP”→“启动SSH功能”
    20150626141436
  • 建立Git用户
    在“控制面板” →“用户账号”中添加Git专用用户。此处设置为git,用户组为users。权限为禁止访问任何共享文件夹
    20150626141852
  • 安装Git
    进入“套件中心”,找到Git Server,安装
    20150626142125安装完成后,打开Git设置界面,将之前添加的git用户设置为允许访问20150626142342
  • 创建Git库文件夹并设置权限
    以root用户SSH登录到DSM,在目标盘下创建git库目录

    cd /volume1
    mkdir git

    创建测试项目

    cd git
    mkdir test

    初始化git

    cd test
    git init --bare

    设置目录权限

    chown -R git:users /volume1/git
  • 客户端:
    Windows:
    下载并安装  http://msysgit.github.io/
    Linux:

    yum install git-core

    apt-get install git-core

    安装完成后,进入git-bash,测试

    git clone ssh://git@192.168.1.5/volume1/git/test

    测试添加文件并提交到本地库

    echo "t1.txt" >t1.txt
    
    git add t1.txt
    
    git commit -m "add t1.txt"

    推送到远程库

    git push origin master
  • 设置SSH Key
    现在所有与远程库的交互都需要输入密码,除了不方便,还有不安全,不过可以使用SSH公钥来进行授权。
    在msysgit安装好后,已经生成了公钥和密钥。在git-bash中查看:

    $ ls ~/.ssh
    id_rsa  id_rsa.pub  known_hosts

    其中,id_rsa就是私钥,id_rsa.pub则是公钥。把公钥复制到远程服务器:

    $ scp -P 9822 ~/.ssh/id_rsa.pub  root@192.168.1.5:/volume1/homes/git/.

    这里用的不是SSH标准的22端口,而是9822。如果是标准端口,则不用输入-P参数
    把公钥内容追加到authorized_keys

    mkdir /volume1/homes/git/.ssh
    cat /volume1/homes/git/id_rsa.john.pub >> /volume1/homes/git/.ssh/authorized_keys

    更改权限

    chown -R git:users /volume1/homes/git/.ssh
    chmod 644 /volume1/homes/git/.ssh/authorized_keys

    再与远程库交互就不会再要求输入密码了。

  • 配置SourceTree的SSH Key
    使用SourceTree做客户端的话,SSH Key的配置有一些不同。
    首先需要在“工具”→“选项”→“一般”中,将SSH客户端设置为“PuTTY/Plink”
    20150626154646
    然后进入“工具”→“创建或导入SSH密钥”
    20150626154946
    其中“Generate”是生成新的密钥对,“Load”则是读取已经存在的私钥(比如上面git-bash里已经生成的私钥。
    生成或读取后,分别保存公钥和私钥。私钥由客户端使用,公钥则需要添加到服务上的authorized_keys文件里。
    在服务器端添加成功后,就可以不用再输入密码了。
  • ]]>
    http://bernieyu.com/2015/06/built-git-server-on-synology-nas/feed/ 0
    Android SDK在线更新镜像服务器 http://bernieyu.com/2015/06/android-sdk-update-mirror/ http://bernieyu.com/2015/06/android-sdk-update-mirror/#comments Wed, 24 Jun 2015 04:19:30 +0000 http://bernieyu.com/?p=241   >>阅读全文<<]]>
  • 中国科学院开源协会镜像站地址:
    • IPV4/IPV6: http://mirrors.opencas.cn 端口:80
    • IPV4/IPV6: http://mirrors.opencas.org 端口:80
    • IPV4/IPV6: http://mirrors.opencas.ac.cn 端口:80
  • 上海GDG镜像服务器地址:http://sdk.gdgshanghai.com 端口:8000
  • 北京化工大学镜像服务器地址:
    • IPv4: http://ubuntu.buct.edu.cn/ 端口:80
    • IPv4: http://ubuntu.buct.cn/ 端口:80
    • IPv6: http://ubuntu.buct6.edu.cn/ 端口:80
  • 大连东软信息学院镜像服务器地址:http://mirrors.neusoft.edu.cn 端口:80
  •  

    使用方法

    1. 启动 Android SDK Manager ,打开主界面,依次选择『Tools』、『Options…』,弹出『Android SDK Manager – Settings』窗口;
    2. 在『Android SDK Manager – Settings』窗口中,在『HTTP Proxy Server」和「HTTP Proxy Port』输入框内填入上面镜像服务器地址(不包含http://,如下图)和端口,并且选中『Force https://… sources to be fetched using http://…』复选框。设置完成后单击『Close』按钮关闭『Android SDK Manager – Settings』窗口返回到主界面;
    3. 依次选择『Packages』、『Reload』。

     

    转自:http://www.androiddevtools.cn/

     

    ]]>
    http://bernieyu.com/2015/06/android-sdk-update-mirror/feed/ 0
    在Windows下搭建基于nginx的视频直播和点播系统 http://bernieyu.com/2015/06/build-video-live-and-vod-with-nginx-rtmp-on-windows/ http://bernieyu.com/2015/06/build-video-live-and-vod-with-nginx-rtmp-on-windows/#comments Fri, 19 Jun 2015 09:00:27 +0000 http://bernieyu.com/?p=234   >>阅读全文<<]]> 一、软件准备

    由于nginx原生是为linux服务的,因此官方并没有编译好的windows版本可以下载,要在windows上使用nginx,要么下载源码进行编译,要么使用其他人已经编译好的文件。

    而要让nginx支持视频直播和点播,还需要第三方的nginx模块:nginx-rtmp-module

    所幸,已经有大神做好了nginx的编译,而且集成了很多nginx模块,其中就已经包括了nginx-rtmp-module

    下载地址:http://nginx-win.ecsds.eu/,详细说明可参见:Readme nginx-win version.txt

    我下载的是nginx 1.7.11.3 Gryphon这个版本。

    这个网站同时也提供了vcredist的下载(x86x64),以避免运行nginx时出现缺少库的错误。

    另外还要下载 stat.xsl 用于显示当前ngix-rtmp服务状态

    另外还需要下载ffmpeg、ffplay、yamdi:

    总结如下:

    1. nginx 1.7.11.3 Gryphon

    2. stat.xsl

    3. ffmpeg、ffplay

    4. yamdi

    二、Nginx 配置

     1. nginx配置

    worker_processes  1;
    
    error_log  logs/error.log debug;
    
    events {
        worker_connections  1024;
    }
    
    rtmp {
        server {
            listen 1935;
    
            application hls {
                 live on;  #启用rtmp直播
                           #地址为rtmp://[server]:[rtmp_port]/[app]/[stream]
                 hls on;   #启用hls直播
                           #地址为http://[server]:[http_port]/[app]/[stream].m3u8
                           #需要配合下面http段设置使用
                 hls_path nginx-rtmp-module/tmp/app/;
                 hls_fragment 5s;
                 recorder rec {  #启用录制
                   record all manual;  #手动控制录制启停
                   record_suffix _rec.flv;
                   record_path nginx-rtmp-module/tmp/rec/;  #录制保存地址
                   record_unique on;
               }
           }
           application vod2{  #rtmp点播
           		play nginx-rtmp-module/tmp/rec/;    
           }
        }
    }
    
    http {
        server {
            listen      18080;
    
            location /stat {  #服务器状态
                rtmp_stat all;
                rtmp_stat_stylesheet stat.xsl;
            }
    
            location /stat.xsl {
                root nginx-rtmp-module/;
            }
    
            location /control { #控制器
                rtmp_control all;
            }
            
    	location /hls/ {  #hls直播地址
               #server hls fragments
               types{
                 application/vnd.apple.mpegurl m3u8;
                 video/mp2t ts;
               }
               alias nginx-rtmp-module/tmp/app/;
               expires -1;
            }
    
            location /vod/{  #hls点播地址
                alias nginx-rtmp-module/tmp/rec/;
            }
    
            location / {
                root nginx-rtmp-module/test/www/;
            }
        }
    }
    

    三、测试

    1. 启动nginx

    start nginx_1.7.11.3_Gryphon\nginx

    2. 推送rtmp流到nginx-rtmp

    start ffmpeg\ffmpeg -re -i rtmp://live.hkstv.hk.lxdns.com/live/hks -vcodec libx264 -preset:v ultrafast -tune:v zerolatency -acodec copy -f flv rtmp://localhost:1935/hls/mystream -loglevel quiet

    3. rtmp直播

    ffmpeg\ffplay "rtmp://127.0.0.1:1935/hls/mystream"
    

    4. hls 直播

    ffmpeg\ffplay "http://127.0.0.1:18080/hls/mystream.m3u8"

    5. 开始录制

    http://127.0.0.1:18080/control/record/start?app=hls&name=mystream&rec=rec

    6. 停止录制

    http://127.0.0.1:18080/control/record/stop?app=hls&name=mystream&rec=rec

    7. 为rtmp点播文件添加索引,否则文件在播放时进度条不能拖动,假定刚才录制的文件名为mystream-1428384476_rec.flv

    yamdi\yamdi -i nginx_1.7.11.3_Gryphon\nginx-rtmp-module\tmp\rec\mystream-1428384476_rec.flv -o nginx_1.7.11.3_Gryphon\nginx-rtmp-module\tmp\rec\mystream-1428384476_rec_idx.flv

    8. rtmp点播

    ffmpeg\ffplay "rtmp://127.0.0.1:1935/vod2/mystream-1428384476_rec_idx.flv"

    9. 制作hls点播分片文件

    ffmpeg\ffmpeg -i E:\video-nginx\nginx_1.7.11.3_Gryphon\nginx-rtmp-module\tmp\rec\mystream-1428384476_rec.flv -acodec copy -bsf:a h264_mp4toannexb -g 105 -vcodec libx264 -vprofile baseline -bf 0 -bufsize 850k -bsf:v dump_extra -map 0 -f segment -segment_format mpegts -segment_list "E:\video-nginx\nginx_1.7.11.3_Gryphon\nginx-rtmp-module\tmp\rec\mystream-1428384476_rec\mystream-1428384476_rec.m3u8" -segment_time 10 E:\video-nginx\nginx_1.7.11.3_Gryphon\nginx-rtmp-module\tmp\rec\mystream-1428384476_rec\mystream-1428384476_rec-%d.ts

    10. hls 点播

    ffplay "http://127.0.0.1:8080/vod/mystream-1428384476_rec/mystream-1428384476_rec.m3u8"
    ]]>
    http://bernieyu.com/2015/06/build-video-live-and-vod-with-nginx-rtmp-on-windows/feed/ 0
    VPS搭建LNMP过程全记录 http://bernieyu.com/2015/06/build-nginx-mysql-php-full-record/ http://bernieyu.com/2015/06/build-nginx-mysql-php-full-record/#comments Tue, 09 Jun 2015 08:56:47 +0000 http://bernieyu.com/?p=227   >>阅读全文<<]]> 最近有朋友新买一个VPS,让帮忙搭建服务器(Linux + Nginx + MySQL + PHP)。
    本来觉得手到擒来的事,可操作起来却发现有些东西记忆已经模糊了。帮朋友弄好后,赶紧把过程记下来,以备后查。

    1. 更新系统
      • apt-get update
        apt-get upgrade
    2. 安装MySQL
      • apt-get install mysql-server mysql-client

        MySQL 安全设置

        mysql_secure_installation

        过程中会询问是否更改 root密码,是否移除匿名用户,是否禁止root远程登录等。

    3. 安装Nginx
      • apt-get install nginx
        service nginx start

        如果没有service命令,则使用

        /etc/init.d/nginx start

        直接访问IP地址,验证nginx安装是否成功
        20150609154658

    4. 安装PHP
      • apt-get install php5-fpm php5-gd php5-mysql php5-curl

        安装完毕之后,查看PHP的版本,验证安装是否成功 :

        root@vultr:/www# php5-fpm -v
        PHP 5.3.10-1ubuntu3.18 (fpm-fcgi) (built: Apr 17 2015 15:08:33)
        Copyright (c) 1997-2009 The PHP Group
        Zend Engine v2.3.0, Copyright (c) 1998-2012 Zend Technologies
    5. 配置PHP-FPM
      • 编辑/etc/php5/fpm/php.ini
        vi /etc/php5/fpm/php.ini
        cgi.fix_pathinfo=0
        
        error_reporting =E_ALL | E_STRICT
        
        display_errors = On
        
        log_errors = On
        error_log = /var/log/php_error.log
      • 编辑 /etc/php5/fpm/pool.d/www.conf
        vi /etc/php5/fpm/pool.d/www.conf
        user = www-data
        group = www-data
        
        ;listen = 127.0.0.1:9000
        listen = /var/run/php5-fpm.sock
        listen.owner = www-data
        listen.group = www-data
        listen.mode = 0660
        
        pm.status_path = /fpm_status
      • 重启php5-fpm
        service php5-fpm restart
    6. 配置Nginx
      • 编辑/etc/nginx/nginx.conf
        user  www-data;
        worker_processes  4;
        
        error_log  /var/log/nginx/error.log warn;
        pid        /var/run/nginx.pid;
        
        
        events {
            worker_connections  1024;
        }
        
        
        http {
            include       /etc/nginx/mime.types;
            default_type  application/octet-stream;
        
            log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                              '$status $body_bytes_sent "$http_referer" '
                              '"$http_user_agent" "$http_x_forwarded_for"';
        
            access_log  /var/log/nginx/access.log  main;
        
            sendfile        on;
            #tcp_nopush     on;
        
            keepalive_timeout  65;
        
            server_tokens off;
        
            gzip  on;
            gzip_disable "msie6";
            gzip_buffers 4 16K;
            gzip_comp_level 5;
            gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png application/javascript;
            gzip_vary on;
            include /etc/nginx/sites-available/*.conf;
        }
    7. 配置网站
      • 新建/www/test目录
        mkdir /www
        mkdir /www/test
      • 新建index.php
        vi /www/test/index.php
        <?php
        
        phpinfo();
        
        ?>
      • 更改目录权限
        chown -R www-data:www-data /www/test
      • 新建网站配置
        vi /etc/nginx/conf.d/www.test.com.conf
        server {
            listen       80;
            server_name  www.test.com;
        
            access_log /var/log/nginx/www.test.com.access.log main;
            error_log  /var/log/nginx/www.test.com.error.log warn;
        
            error_page  404              /404.html;
            error_page  500 502 503 504  /50x.html;
            location = /50x.html {
                root   /usr/share/nginx/html;
            }
        
            location / {
                root /www/test;
                index  index.html index.htm index.php;
                #WordPress伪静态,不需要可以删除
                if (-f $request_filename/index.html){
                        rewrite (.*) $1/index.html break;
                }
                if (-f $request_filename/index.php){
                        rewrite (.*) $1/index.php;
                }
                if (!-f $request_filename){
                        rewrite (.*) /index.php;
                }
            }
        
            #fpm_status,可通过www.test.com/fpm_status查看fpm状态,添加?full参数可查看详细状态。
            #正式上线时需要注释掉此段
            location ~ ^/(fpm_status)$ {
             access_log off;
             include fastcgi_params;
             fastcgi_pass unix:/var/run/php5-fpm.sock;
             fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            }
        
            location ~ \.php$ {
                proxy_buffers 8 16k;
                proxy_buffer_size 32k;
                root   /www/test;
                # With php5-fpm:
                fastcgi_pass unix:/var/run/php5-fpm.sock;
                fastcgi_index index.php;
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                include fastcgi_params;
            }
        }
        
      • 链接到sites-available
        ln -s /etc/nginx/conf.d/www.test.com.conf /etc/nginx/sites-available/www.test.com.conf
      • 测试nginx配置
        nginx -t

        如果配置文件正常,则显示:

        nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
        nginx: configuration file /etc/nginx/nginx.conf test is successful

        如果报错,则检查配置文件

      • 待一切正常后,重启nginx
        service nginx restart
      • 此时访问www.test.com,会出现PHP运行信息
        20150609164645
      • 访问 www.test.com/fpm_status 或者 www.test.com/fpm_status?full 可以查看fpm状态
    ]]>
    http://bernieyu.com/2015/06/build-nginx-mysql-php-full-record/feed/ 0
    解决Chrome升级到42版本后安全控件不可用的问题 http://bernieyu.com/2015/06/resolve-chrome-update-to-version-42-security-control-not-available/ http://bernieyu.com/2015/06/resolve-chrome-update-to-version-42-security-control-not-available/#comments Tue, 02 Jun 2015 06:27:28 +0000 http://bernieyu.com/?p=221   >>阅读全文<<]]> Chrome升级到最新的42版本后,由于默认停止对NPAPI插件的支持,因此导致种种安全控件不再可用。

    解决方法1:

    使用ie浏览器

    解决方法2:

    回退chrome版本

    解决方法3:

    在Chrome地址栏输入

    chrome://flags/

    在打开的配置页面中启用 NPAPI 插件即可。

    20150602142558 20150602142625

    ]]>
    http://bernieyu.com/2015/06/resolve-chrome-update-to-version-42-security-control-not-available/feed/ 0