西维蜀黍

【OpenWrt】小米路由器mini刷OpenWRT

刷小米官方开发版ROM

从http://www.miwifi.com/miwifi_download.html ,下载并刷入小米官方开发版ROM。

刷SSH以获得root权限

刷入小米官方开发版ROM(miwifi_r1cm_firmware_2e9b9_2.21.109.bin)后,获取SSH权限(期间需要下载一个miwifi_ssh.bin工具包,并通过U盘写入路由器)。

刷OpenWrt

下载OpenWrt

从downloads.openwrt.org,下载最新的OpenWrt ROM,当前(2019.1.29)最新的OpenWrt版本为18.06.1。

下载地址:https://downloads.openwrt.org/releases/18.06.1/targets/ramips/mt7620/openwrt-18.06.1-ramips-mt7620-miwifi-mini-squashfs-sysupgrade.bin。

scp 以将.bin到路由器

刷入镜像

使用 mtd 刷入镜像

mtd -r write /tmp/openwrt|pandorabox|lede.bin firmware

如遇以下报错,改 firmwareOS1 即可。

Could not open mtd device: firmware
Can't open device for writing!

到这里,等待刷入镜像,路由器自动重启,过一会才能登录。

注意!!!当系统安装完成后, LEDE 的指示灯是红色的,我在刷完之后,以为路由器显示红色指示灯,是因为成砖了,折腾了半天(事实上已经OpenWrt安装完成了)

而且刷完系统默认不开启无线网络,需要用网线连接到 LAN 口。

总结一句,千万注意刷完后,别管路由器的灯。而直接用网线将PC与路由器相连。

  ...


【Network】C10K问题与高性能网络编程入门

C10K 问题

C10K是服务器应用领域很古老很出名的一个问题,大意是说单台服务器要同时支持并发 10K 量级的连接。

  ...


【Linux】I/O轮询技术

轮询(poll)技术

下文将介绍Linux中的四种轮询技术,分别是:

  • read
  • select
  • poll
  • epoll

read 轮询技术对应于同步非阻塞I/O模型,每次轮询只能获知一个I/O操作对应的状态,轮询操作由用户负责。

select、poll、epoll 轮询技术对应于I/O多路复用(I/O Multiplexing),每次轮询可检测多个I/O操作的状态,轮询(poll)操作由操作系统负责(而用户线程调用对应的轮询函数时会被阻塞)。

注意:

  • 以下这些轮询技术都分别对应一种逻辑上的轮询方法(Function)。而每一种轮询方法,内核都会以系统调用(本质是一个或一系列的C语言函数)的形式提供给用户线程进行调用;
  • 轮询技术仅仅描述了当用户已经发起I/O操作后,从“用户线程获取这些I/O操作是否已经完成”的过程;
  • 这些轮询技术对应的轮询方法都会阻塞用户线程。换句话说,若所有监听的 fd 对应的I/O操作在很长时间内都没有完成,在这段时间内,这些轮询方法都不会返回控制流给用户线程。
  ...


【Java】关键字 - finally

[例子1] final 的意义

    public static int test1() {
        int i = 0;
        try {
            System.out.println("try"); //1
            return i;
        } finally {
            System.out.println("finally"); //2
        }
    }
// 执行结果
try
finally
  ...


【Nginx】Nginx学习

初探Nginx架构

nginx在启动后,在unix系统中会以daemon的方式在后台运行,后台进程包含一个master进程和多个worker进程。我们也可以手动地关掉后台模式,让nginx在前台运行,并且通过配置让nginx取消master进程,从而可以使nginx以单进程方式运行。很显然,生产环境下我们肯定不会这么做,所以关闭后台模式,一般是用来调试用的,在后面的章节里面,我们会详细地讲解如何调试nginx。所以,我们可以看到,nginx是以多进程的方式来工作的,当然nginx也是支持多线程的方式的,只是我们主流的方式还是多进程的方式,也是nginx的默认方式。nginx采用多进程的方式有诸多好处,所以我就主要讲解nginx的多进程模式吧。

  ...


【Node.js】Node的模块定义和使用

模块定义和使用

在模块中, 上下文提供 require() 方法来引入外部模块。 对应引入的功能, 上下文提供了 exports对象用于导出当前模块的方法或者变量,并且它是唯一导出的出口。在模块中,还存在 一个module对象,它代表模块自身,而exports是module的属性。在Node中,一个文件就是一个 模块,将方法挂载在exports对象上作为属性即可定义导出的方式:

  ...


【Linux】ln - 硬链接与软链接

背景

在介绍链接的概念之前,我们需要先Unix/Linux文件系统和硬盘储存的基础概念。

  ...


【Distributed System】分布式系统的数据一致性(Data Consistency)

什么是数据一致性(Data Consistency)

**数据一致性(Data Consistency)**其实是数据库系统中的概念。我们可以简单地把一致性理解为正确性或者完整性。

数据库事务(Database Transaction)

我们知道,在数据库系统中通常用事务来保证数据的一致性和完整性。

数据库事务,核心是数据库ACID(原子性、一致性、隔离性和持久性)属性。即对于一个数据库事务中所有的逻辑处理操作,只有这些作用在数据库上的逻辑处理操作全部都成功时,对数据库的修改才会永久更新到数据库中。若存在任何一个操作失败,对于在此之前的所有逻辑操作都会失效(即该事务被回滚)。

  ...


【Distributed System】分布式事务 - 三阶段提交协议(Three-phase Commit Protocol)

三阶段提交协议(Three-phase Commit Protocol)

In computer networking and databases, the three-phase commit protocol (3PC) is a distributed algorithm which lets all nodes in a distributed system agree to commit a transaction. It is a more failure-resilient refinement of the two-phase commit protocol (2PC).

  ...


【Distributed System】分布式事务 - 两阶段提交协议(Two-phase Commit Protocol)

The two-phase commit (2PC) protocol should not be confused with the two-phase locking (2PL) protocol, a concurrency control protocol.

两阶段提交协议(Two-phase Commit Protocol,2PC)

In transaction processing, databases, and computer networking, the two-phase commit protocol (2PC) is a type of atomic commitment protocol (ACP). It is a distributed algorithm that coordinates all the processes that participate in a distributed atomic transaction on whether to commit or abort (roll back) the transaction (it is a specialized type of consensus protocol). The protocol achieves its goal even in many cases of temporary system failure (involving either process, network node, communication, etc. failures), and is thus widely used.

However, it is not resilient to all possible failure configurations, and in rare cases, manual intervention is needed to remedy an outcome. To accommodate recovery from failure (automatic in most cases) the protocol’s participants use logging of the protocol’s states. Log records, which are typically slow to generate but survive failures, are used by the protocol’s recovery procedures. Many protocol variants exist that primarily differ in logging strategies and recovery mechanisms. Though usually intended to be used infrequently, recovery procedures compose a substantial portion of the protocol, due to many possible failure scenarios to be considered and supported by the protocol.

In a “normal execution” of any single distributed transaction (i.e., when no failure occurs, which is typically the most frequent situation), the protocol consists of two phases:

  1. The prepare phase (or voting phase), in which a coordinator process attempts to prepare all the transaction’s participating processes (named participants, cohorts, or workers) to take the necessary steps for either committing or aborting the transaction and to vote,
    • either “Yes”: commit (if the transaction participant’s local portion execution has ended properly),
    • or “No”: abort (if a problem has been detected with the local portion), and
  2. The commit phase, in which, based on voting of the participants, the coordinator decides whether to commit (only if all have voted “Yes”) or abort the transaction (otherwise), and notifies the result to all the participants. The participants then follow with the needed actions (commit or abort) with their local transactional resources (also called recoverable resources; e.g., database data) and their respective portions in the transaction’s other output (if applicable).
  ...