Skip to content

Instantly share code, notes, and snippets.

@ericzhong
ericzhong / Kafka 部署.md
Last active November 24, 2017 10:06
Kafka 部署

环境

CentOS 7.3
zookeeper-3.4.6 (该部署省略)

单机方式

@ericzhong
ericzhong / Zookeeper 部署和使用.md
Last active November 24, 2017 10:07
Zookeeper 部署和使用

安装

环境

CentOS 7.3
zookeeper-3.4.6
java-1.8.0-openjdk
@ericzhong
ericzhong / memcached 高可用集群.md
Last active November 24, 2017 10:07
memcached 高可用集群

方案

memcached 机器 N 台:m1、m2、...、mN

memcached 备份机 1 台:mbackup

magent 两台:用 keepalived 做 HA,两者的启动参数完全相同,即 N 台 memcached + 1 台备份。

如果任意一台 magent 宕机,会马上切换到另一台。

@ericzhong
ericzhong / bash_sample.sh
Created October 18, 2017 09:43
Bash 样板
#!/bin/bash
announce () {
[[ $verbose -eq 1 ]] && echo "$@"
[[ ! -z $logfile ]] && echo "$@" >> "$logfile"
}
usage()
{
@ericzhong
ericzhong / libevent2-signal.c
Created October 18, 2017 08:00
libevent2 信号处理
/*
gcc -I/usr/local/Cellar/libevent/2.1.8/include/ -L/usr/local/Cellar/libevent/2.1.8/lib/ -levent libevent2-signal.c
kill -s USR1 <PID>
*/
#include <stdio.h>
#include <signal.h>
#include <event2/event.h>
void cb_func(evutil_socket_t fd, short events, void *arg)
@ericzhong
ericzhong / libevent2-server.c
Created October 17, 2017 12:10
libevent2 回显服务器
/*
brew install libevent
gcc -I/usr/local/Cellar/libevent/2.1.8/include/ -L/usr/local/Cellar/libevent/2.1.8/lib/ -levent libevent2-server.c
server$ ./a.out
client$ telnet 127.0.0.1 8000
*/
#include <event2/listener.h>
#include <event2/bufferevent.h>
@ericzhong
ericzhong / libevent2_timer.c
Last active October 16, 2017 05:49
libevent 定时器
/*
brew install libevent
gcc -I/usr/local/Cellar/libevent/2.1.8/include/ -L/usr/local/Cellar/libevent/2.1.8/lib/ -levent libevent2_timer.c
*/
#include <stdlib.h>
#include <stdio.h>
#include <sys/time.h>
#include <event2/event.h>
@ericzhong
ericzhong / counter.java
Created May 27, 2017 03:10
多线程安全的计数
import java.util.Random;
class Counter implements Runnable {
static int n=0;
public static void main(String[] args) {
Runnable r = new Counter();
Thread t1 = new Thread(r, "Thread 1");
Thread t2 = new Thread(r, "Thread 2");
t1.start();
@ericzhong
ericzhong / MultiThread.java
Last active May 27, 2017 03:02
多线程
import java.util.Random;
class PrintChar implements Runnable {
private String ch;
PrintChar(String str) {
this.ch=str.substring(0,1);
}
public void run() {
class ListMetaClass(type):
def __new__(cls, name, bases, attrs):
attrs['times'] = lambda self, n: self*n
return type.__new__(cls, name, bases, attrs)
class MyList(list, metaclass=ListMetaClass):
pass
l = MyList([1,2,3])
print(l.times(2))