存档

‘Linux/Unix’ 分类的存档

Mongodb主从复制和Mongodb主主复制配置

2010年8月27日 liangdi 没有评论

Mongodb在1.6版中增加了Sharding和Replic Sets的支持,很大程度上解决了一些水平扩展和故障转移的问题.
但是在一些小型应用场景主从复制还是能够有效解决问题的,主主复制有用的场景,但是是不被推荐。

Mongodb 主从复制 配置:
单机测试:
建立三个服务器的储存目录

cd /var/mongodb
mkdir -p masterdb
mkdir -p salvedb_1
mkdir -p slavedb_2

启动主服务器和从服务器

#主服务器 监听10000端口
./bin/mongod --dbpath ./masterdb/ --port 10000 --master

#从服务器 这里启动两个从服务器  分别用10001 和 10002 端口  也可以使用 master master-> slave 的设置
./bin/mongod --dbpath ./slavedb_1 --source localhost:10000 --slave --port 10001
./bin/mongod --dbpath ./slavedb_2 --source localhost:10000 --slave --port 10002
#启动后  就会看到有日志 显示 从主服务器复制内容了

阅读全文…

KVM虚拟化在CentOS中的使用

2010年8月20日 liangdi 没有评论

KVM (for Kernel-based Virtual Machine) is a full virtualization solution for Linux on x86 hardware containing virtualization extensions (Intel VT or AMD-V). It consists of a loadable kernel module, kvm.ko, that provides the core virtualization infrastructure and a processor specific module, kvm-intel.ko or kvm-amd.ko. KVM also requires a modified QEMU although work is underway to get the required changes upstream.

Using KVM, one can run multiple virtual machines running unmodified Linux or Windows images. Each virtual machine has private virtualized hardware: a network card, disk, graphics adapter, etc.

The kernel component of KVM is included in mainline Linux, as of 2.6.20.

KVM是红帽大版本6中默认的虚拟化技术,从上述描述中可以看出,KVM有很多优势,作为CentOS的使用者自然也有好处~,而现在的CentOS5.5的内核是2.6.18-194.11.1.el5所以需要安装kvm的内核模块
使用kvm,你的cpu必须支持 vm 技术,否则和 qemu 的效率基本相同
可以用以下代码查看CPU是否支持可以用以下命令检测

        egrep '(vmx|svm)' /proc/cpuinfo
    

如果有输出则支持。
在CentOS中安装

        yum install -y kvm kvm-mod qemu
    

阅读全文…

OpenBSD4.7发布

2010年5月19日 liangdi 1 条评论

OpenBSD 致力于开发一个自由,基于 4.4BSD 的多平台,与 UNIX 兼容的操作系统。我们重点致力于可移植性,标准化,正确性,前瞻的安全性和完整的加密技术。OpenBSD 支持 SVR4(Solaris),FreeBSD,Linux,BSD/OS,SunOS 和 HP-UX 下大多数程序的二进制仿真运行。

发行注记页面:http://www.jp.openbsd.org/zh/47.html
下载列表:http://www.openbsd.org/zh/ftp.html
OpenBSD是一个很优秀的操作系统,通常作为路由器,VPN,防火墙等等.而我本人是用作个人数据服务器.

CentOS5.5发布

2010年5月15日 liangdi 没有评论

两天前刚发了篇日志说CentOS5.5快要发布了,昨天做了个梦发布了,今天真的就发布了 哈哈……

http://www.icentos.net/read-htm-tid-40.html

Centos5.5发布在即

2010年5月13日 liangdi 没有评论

RHEL5.5已经发布了一个多月了,Centos还是没有动静,其间好像只是更新了一些软件包.
不过官方的版本发布注记已经出来了,离正式发布时间也不远了.

http://wiki.centos.org/zh/Manuals/ReleaseNotes/CentOS5.5

官方社区也有帖子说明快了,大家就期待吧 呵呵~~  不过我更期待的是6.0的版本因为内核已经更新到2.6.32了,可以使用很多新的功能!

讨论帖子:http://www.centos.org/modules/newbb/viewtopic.php?topic_id=25548&forum=53

跟我一起写Makefile[pdf] 下载

2010年4月20日 liangdi 2 条评论

熟悉Makefile是linux c/c++程序员的必备技能,
陈 皓的这篇《跟我一起写Makefile》 是一篇学习的好文章

下载: Makefile.pdf (573 K)

原文地址:http://www.icentos.net/read-htm-tid-18.html

CentOS5中安装 chrome(chromium)

2010年3月4日 liangdi 2 条评论

由于Chrome代码使用了比较高的GLibc版本 以及其他软件包的版本比CentOS5的版本要高,所以无法直接安装,
现在已经有人静态编译出了CentOS5可以运行版本http://www.cs.bham.ac.uk/~cxs548/chrome
文件包下载:chrome

我在CentOS5.4中已经能运行
解压后直接运行chrome-wrapper,如果有报错,请安装错误提示的包等,也请你在这里提出来我们一起讨论
centos_chrome
阅读全文…

分类: Linux/Unix 标签: ,

CentOS5.4安装Erlang开发环境

2010年2月1日 liangdi 1 条评论

很早就听说Erlang的大名了,可惜一直没有机会去接触.最近这段时间有看到了她和Ajax Comet之间有一下联系,所以就打算部署起来看看起庐山真面目.
CentOS5.4中编译安装Erlang比较顺利
首先去下载Erlang 的源码包 http://ftp.sunet.se/pub/lang/erlang/download.html

下载解压后直接编译就好了,我下载的是当前最新的 R13B03

./configure --prefix=/usr/local/erlang
make && make install

或者直接

./configure
make && make install

在configure的过程中可能会提示缺少包 curses 解决方法是安装 ncurses-devel

yum install ncurses-devel

没有其他大问题了.

安装好了之后就测试一下吧~

执行/usr/local/erlang/bin/erl

如果你没有设置–prefix 直接执行 erl 就可以了

需要注意一点是 erlang 是用 “. ” 作为语句结束的

现在来执行一下它的Hello World!

在提示符中输入 回车就可以看到执行结果了


[root@liangdi ~]# /usr/local/erlang/bin/erl
Erlang R13B03 (erts-5.7.4) [source] [smp:2:2] [rq:2] [async-threads:0] [hipe] [kernel-poll:false]

Eshell V5.7.4  (abort with ^G)
1> io:format("Hello World!\n").
Hello World!
ok
2>

文章作者:liangdi 最后修改:2010.01.22 转载请注明来自:[自由的心灵]

原文链接:http://liangdi.icentos.net/2010/02/01/install_erlang_with_centos/

分类: Linux/Unix, 编程开发 标签: ,

CentOS 中安装使用 xmms 音乐播放器

2010年1月28日 liangdi 1 条评论

由于CentOS主要应用在服务器上,在桌面应用中有些软件无法用yum安装
现在有一些第三方的软件仓库提供了这个便利 http://rpmrepo.org/RPMforge/
RPMForge 的CentOS软件仓库中 有 xmms mplayer 等很多桌面应用程序
centos xmms
CentOS5 中使用RPMForge 的仓库的方法,

i386 http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.1-1.el5.rf.i386.rpm
x86_64  http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.1-1.el5.rf.x86_64.rpm

下载后安装 你可以在桌面环境下直接双击安装 也可以 在终端下用rpm 命令安装

安装好后便可以用yum 安装rpmforge中的软件了
我们先搜索一下 xmms的软件包

[root@liangdi ~]# yum search xmms
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * rpmforge: fr2.rpmfind.net
======================================================================= Matched: xmms =======================================================================
xmms.i386 : Media player for X which resembles Winamp
xmms-devel.i386 : Static libraries and header files for Xmms plug-in development.
xmms-mp3.i386 : XMMS plugin for mp3 playback.
xmms-skins.i386 : Skins for the xmms multimedia player.
albumart.noarch : Downloads album cover images semi-automatically from the Internet
audacious.i386 : Graphical media player similar to xmms
kderadiostation.i386 : Tool which presents you a list of internet streaming radio stations
libmodplug.i386 : MOD music file playing library
libmodplug-devel.i386 : Header files, libraries and development documentation for libmodplug.
ximian-artwork.i386 : Default Style for Ximian Desktop
xmms-aac.i386 : X MultiMedia System input plugin to play AAC files
xmms-crossfade.i386 : Crossfade output plugin for XMMS
xmms-musepack.i386 : X MultiMedia System input plugin to play musepack (mpc) files
xmms-wma.i386 : X MultiMedia System input plugin to play Windows Media Audio files
xosd.i386 : Displays transparent text on your screen like the OSD of TVs

阅读全文…

Pthread 编程练习 二 线程同步

2010年1月24日 liangdi 没有评论

线程的同步, 发生在多个线程共享相同内存的时候, 这时要保证每个线程在每个时刻看到的共享数据是一致的. 如果每个线程使用的变量都是其他线程不会使用的(read & write), 或者变量是只读的, 就不存在一致性问题. 但是, 如果两个或两个以上的线程可以read/write一个变量时, 就需要对线程进行同步, 以确保它们在访问该变量时, 不会得到无效的值, 同时也可以唯一地修改该变量并使它生效.

最初在学习线程的时候,教程中举了一个售票的例子,就是多个窗口(多线程) 同时销售100张票(共享相同的变量)的问题
我们看看没有处理线程同步的代码

#include <stdio.h>
#include <unistd.h>
#include <pthread.h>

int giCounts = 100;
void thread_a_func(void);
void thread_b_func(void);
void thread_c_func(void);

int main(){
	pthread_t ltThreadIDa,ltThreadIDb,ltThreadIDc;
	if(pthread_create(&ltThreadIDa,NULL,(void *)thread_a_func,NULL)!=0)
	{
		printf("create thread a error!\n");
	}
	if(pthread_create(&ltThreadIDb,NULL,(void *)thread_b_func,NULL)!=0)
	{
		printf("create thread b error!\n");
	}
	if(pthread_create(&ltThreadIDc,NULL,(void *)thread_c_func,NULL)!=0)
	{
		printf("create thread b error!\n");
	}
	while(giCounts > 0){
		sleep(1);
	}
}

void thread_a_func(void){
	while(1){
			if(giCounts > 0) {
				usleep(1000); //处理售票事务
				printf("1号台卖出票号:%d\n",giCounts--);
			}
			usleep(1000);
	}
}

void thread_b_func(void){
	while(1){
			if(giCounts > 0) {
				usleep(1000); //处理售票事务
				printf("2号台卖出票号:%d\n",giCounts--);
			}
			usleep(1000);
	}
}

void thread_c_func(void){
	while(1){
			if(giCounts > 0) {
				usleep(1000); //处理售票事务
				printf("3号台卖出票号:%d\n",giCounts--);
			}
			usleep(1000);
	}
}

阅读全文…