利用keepalived构建高可用MySQL-HA

没有评论

2012 年 03 月 29 日 at 下午 8:31分类:MySQL | NoSQL

本来是找相关Redis的HA方案的,结果找到这篇文章,发现很不错,记录下,方便下次查找

地址:点击查看

上篇文章说配置Redis的主从问题,但我现在想要配置Redis的master-master模式,然后借用keepalived来实现故障自动转移的功能,
但是配置了Redis的相关参数之后,根本就不能达到我想要的目的,不知道是什么原因,看了网上很多的文章,都出现了类似的情况。估计是
Redis现在还不支持这个功能吧 期待高手。

参考资料:
1、http://blog.csdn.net/doraeimo/article/details/7029832
2、http://baike.baidu.com/view/4175422.htm

redis 分布式,主从同步

一条评论

2012 年 03 月 27 日 at 上午 9:37分类:NoSQL

redis和memcache比较像的,memcache可以实现服务器的集群,redis肯定也是可以的。下面在一台机,实现redis主从复制。
1,copy一下redis.conf,生成一个从机的配置

cp /usr/local/redis/redis.conf /usr/local/redis/redis_slave.conf

2,修改主服务器的配置redis.conf

bind 127.0.0.1

3,修改从服务器的配置redis_slave.conf

pidfile /usr/local/redis/var/redis_slave.pid

port 6380

bind 127.0.0.1

logfile /usr/local/redis/var/redis_slave.log

dbfilename dump_slave.rdb

slaveof 127.0.0.1 6379

4,启动主服务器,从服务器

redis-server /usr/local/redis/redis.conf

redis-server /usr/local/redis/redis_slave.conf

查看一下,redis.log文件会有以下内容

[3774] 27 Jun 12:53:32 * The server is now ready to accept connections on port 10002

[3774] 27 Jun 12:53:32 - 0 clients connected (0 slaves), 539568 bytes in use

[3774] 27 Jun 12:53:32 * Connecting to MASTER...

[3772] 27 Jun 12:53:32 - Accepted 127.0.0.1:33237

[3772] 27 Jun 12:53:32 * Slave ask for synchronization

[3772] 27 Jun 12:53:32 * Starting BGSAVE for SYNC

[3772] 27 Jun 12:53:32 * Background saving started by pid 3775

[3774] 27 Jun 12:53:32 * MASTER <-> SLAVE sync started: SYNC sent

[3775] 27 Jun 12:53:32 * DB saved on disk

[3772] 27 Jun 12:53:33 * Background saving terminated with success

[3772] 27 Jun 12:53:33 * Synchronization with slave succeeded

[3774] 27 Jun 12:53:33 * MASTER <-> SLAVE sync: receiving 333 bytes from master

[3774] 27 Jun 12:53:33 * MASTER <-> SLAVE sync: Loading DB in memory

[3774] 27 Jun 12:53:33 * MASTER <-> SLAVE sync: Finished with success

查看一下

root@ubuntu:/usr/local/redis# ps -e|grep redis

3774 ? 00:00:00 redis-server

4148 ? 00:00:00 redis-server

5,测试结果

//连接主服务器
[root@localhost var]# redis-cli -h 127.0.0.1 -p 6379
redis 127.0.0.1:6379> set fbbin binbin
OK
redis 127.0.0.1:6379> get fbbin
"binbin"
redis 127.0.0.1:6379> exit
========================================
//连接从服务器
[root@localhost var]# redis-cli -h 127.0.0.1 -p 6380
redis 127.0.0.1:6380> get fbbin
"binbin"
redis 127.0.0.1:6380> exit

OVER

windows 安装 mongodb 并添加到服务列表中

没有评论

2012 年 03 月 24 日 at 下午 3:53分类:NoSQL

准备工作:
到官方下载合适的版本 http://www.mongodb.org/downloads
这里用的是mongodb windows 32bit(我本机是32的OS) 版
解压mongodb到D:\mongodb\ 目录,同时在mongodb目录中新建目录db(用于存放数据)和目录logs(存放日志),那么mongodb目录中就应该有了这些文件,如图:

在D:\mongodb\logs\ 目录下新建一个mongodb.log 用于记录安装日志,那么都准备好了,开始安装吧~

安装步骤:

1.开始–运行–cmd

2.cd D:\mongodb\bin\

3. D:\mongodb\bin>mongod –logpath D:\mongodb\logs\mongodb.log –logappend –dbpath D:\mongodb\db –directoryperdb –serviceName MongoDB –install

参数不明白的可以使用命令:D:\mongodb\bin>mongod -h

如图:

如果安装成功,则显示下面文字

all output going to: D:\mongodb\logs\MongoDB.log
Creating service MongoDB.
Service creation successful.
Service can be started from the command line via ‘net start “MongoDB”‘.

安装成功后可以到windows服务中找到mongodb服务开启或者在cmd中执行命令net start MongoDB,这样mongodb服务就启动了,mongodb的默认端口是27017

服务启动后可以执行几个简单的命令测试下:

OVER!!

CentOS6.1+Nginx1.1.12+PHP5.3.9+Redis2.4.5+Memcache及相关扩展安装脚本

一条评论

2012 年 03 月 19 日 at 下午 8:16分类:WEB开发

#!/bin/sh
#Date:2012-01-12 02:00:00
#Description:版本针对32位系统,操作系统为CentOS6.0
#基本路径设置

BASE_PATH="/usr/local/webserver"

#复制yum更新文件#####################################################################
#rm -rf /var/cache/yum
#cp -R yum /var/cache/
#安装依赖库和开发工具#################################################################
yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel zlib zlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-devel ncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5 krb5-devel libidn libidn-devel openssl openssl-devel openldap openldap-devel nss_ldap openldap-clients openldap-servers
#安装Nginx库#########################################################################
yum -y install pcre-devel  zlib-devel
#安装PHP库###########################################################################
yum -y install gd-devel libjpeg-devel libpng-devel freetype-devel libxml2-devel curl-devel freetype-devel
#安装MySQL库#########################################################################
yum -y install bison gcc gcc-c++ autoconf automake zlib* libxml* ncurses-devel libtool-ltdl-devel*
#安装cmake###########################################################################
cd /home/soft
tar -zxvf cmake-2.8.7.tar.gz
cd cmake-2.8.7
./configure
gmake
gmake install
#添加MYSQL用户#######################################################################
/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql mysql
#创建安装目录########################################################################
mkdir -p $BASE_PATH/mysql/data
#设置binlog#########################################################################
mkdir $BASE_PATH/mysql/mysql-bin
chown -R mysql:mysql $BASE_PATH/mysql/mysql-bin
#目录授权############################################################################
chown -R mysql:mysql $BASE_PATH/mysql/data
# 添加MYSQL用户######################################################################
cd /home/soft
MAKE_RUN=$(($(more /proc/cpuinfo | grep processor | wc -l) + 1))
tar -zxvf mysql-5.5.20.tar.gz
cd mysql-5.5.20
cmake \
    -DCMAKE_INSTALL_PREFIX=$BASE_PATH/mysql/\
    -DMYSQL_DATADIR=$BASE_PATH/mysql/data/\
    -DEXTRA_CHARSETS=all\
    -DDEFAULT_CHARSET=utf8\
    -DDEFAULT_COLLATION=utf8_general_ci\
    -DSYSCONFDIR=/etc/\
    -DWITH_DEBUG=0
make -j ${MAKE_RUN}
make install
#初始化权限表#######################################################################
rm -f /etc/my.cnf
cd /home/soft
cp my.cnf /etc/my.cnf
cd $BASE_PATH/mysql
./scripts/mysql_install_db --user=mysql
#开启mysql##########################################################################
$BASE_PATH/mysql/bin/mysqld_safe &
#设置数据库配置######################################################################
rm -f /etc/rc.d/init.d/mysql
cp $BASE_PATH/mysql/support-files/mysql.server  /etc/rc.d/init.d/mysql
chmod 700 /etc/rc.d/init.d/mysql
chkconfig --add mysql
chkconfig --level 345 mysql on
chkconfig --list mysql
#设置环境变量#######################################################################
echo "export PATH=$PATH:$BASE_PATH/mysql/bin">>/etc/profile
source /etc/profile
#更改密码###########################################################################
/etc/init.d/mysql restart
$BASE_PATH/mysql/bin/mysqladmin -uroot password root
mysql -uroot -proot
Grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option;
flush privileges;
exit;

###################################################################################
###################################################################################
#安装libiconv扩展###################################################################
cd /home/soft
tar -zxvf libiconv-1.14.tar.gz
cd libiconv-1.14
./configure --prefix=/usr/local/
make
make install
#安装libmcrypt扩展###################################################################
cd /home/soft
tar -zxvf libmcrypt-2.5.8.tar.gz
cd libmcrypt-2.5.8
./configure
make
make install
/sbin/ldconfig 
cd libltdl
./configure --enable-ltdl-install
make
make install
#安装mhash扩展######################################################################
cd /home/soft
tar -zxvf mhash-0.9.9.9.tar.gz
cd mhash-0.9.9.9
./configure
make
make install
#加载软连接#########################################################################
ln -s /usr/local/lib/libmcrypt.la /usr/lib/libmcrypt.la
ln -s /usr/local/lib/libmcrypt.so /usr/lib/libmcrypt.so
ln -s /usr/local/lib/libmcrypt.so.4 /usr/lib/libmcrypt.so.4
ln -s /usr/local/lib/libmcrypt.so.4.4.8 /usr/lib/libmcrypt.so.4.4.8
ln -s /usr/local/lib/libmhash.a /usr/lib/libmhash.a
ln -s /usr/local/lib/libmhash.la /usr/lib/libmhash.la
ln -s /usr/local/lib/libmhash.so /usr/lib/libmhash.so
ln -s /usr/local/lib/libmhash.so.2 /usr/lib/libmhash.so.2
ln -s /usr/local/lib/libmhash.so.2.0.1 /usr/lib/libmhash.so.2.0.1
ln -s /usr/local/bin/libmcrypt-config /usr/bin/libmcrypt-config
#安装mcrypt扩展######################################################################
cd /home/soft
tar -zxvf mcrypt-2.6.8.tar.gz
cd mcrypt-2.6.8
/sbin/ldconfig
./configure
make
make install
#增加软连接 ,防止出现make: *** [ext/phar/phar.php] 错误 127############################
ln -s /usr/local/bin/libiconv.so /usr/bin/libiconv.so
ln -s /usr/local/bin/libiconv.so.2 /usr/bin/libiconv.so.2
ln -s $BASE_PATH/mysql/lib/libmysqlclient.so /usr/lib/libmysqlclient.so
ln -s $BASE_PATH/mysql/lib/libmysqlclient.so.18  /usr/lib/libmysqlclient.so.18
#添加www组和www用户##################################################################
/usr/sbin/groupadd www
/usr/sbin/useradd -g www www
mkdir -p /var/log/nginx
chmod +w /var/log/nginx
chown -R www:www /var/log/nginx
mkdir -p /hotdoc/www
chmod +w /hotdoc/www
chown -R www:www /hotdoc/www
#安装PHP#############################################################################
cd /home/soft
tar -zxvf php-5.3.9.tar.gz
cd php-5.3.9
./configure --prefix=$BASE_PATH/php/\
    --with-config-file-path=$BASE_PATH/php/etc/\
    --with-iconv-dir=/usr/local/\
    --with-freetype-dir\
    --with-mysql=$BASE_PATH/mysql/\
    --with-mysqli=$BASE_PATH/mysql/bin/mysql_config\
    --with-jpeg-dir\
    --with-png-dir\
    --with-zlib\
    --with-mhash\
    --enable-sockets\
    --enable-ftp\
    --with-libxml-dir\
    --enable-xml\
    --disable-rpath\
    --enable-safe-mode\
    --enable-bcmath\
    --enable-shmop\
    --enable-sysvsem\
    --enable-inline-optimization\
    --with-curl\
    --with-curlwrappers\
    --enable-mbregex\
    --enable-mbstring\
    --with-mcrypt\
    --with-gd\
    --enable-gd-native-ttf\
    --with-openssl\
    --with-mhash\
    --enable-pcntl\
    --enable-sockets\
    --with-ldap\
    --with-ldap-sasl\
    --enable-fpm\
    --with-xmlrpc\
    --enable-zip\
    --enable-soap\
    --without-pear

make ZEND_EXTRA_LIBS='-liconv'
make install
cd /home/soft
cp php.ini $BASE_PATH/php/etc/php.ini
echo "export PATH=$PATH:$BASE_PATH/php/bin">>/etc/profile
source /etc/profile
cd /home/soft
rm -f $BASE_PATH/php/etc/php-fpm.conf
cp php-fpm.conf $BASE_PATH/php/etc/php-fpm.conf
#检查语法是否正确
$BASE_PATH/php/sbin/php-fpm -t
#出现NOTICE: configuration file $BASE_PATH/php/etc/php-fpm.conf test is successful 测试成功
$BASE_PATH/php/sbin/php-fpm &
#安装PHP常用扩展#####################################################################
cd /home/soft/php-5.3.9
cp ./sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm 
chmod 700 /etc/init.d/php-fpm 
chkconfig --add php-fpm 
chkconfig --level 345 php-fpm on
chkconfig --list php-fpm

#安装libevent-2.0.16-stable.tar.gz###################################################
cd /home/soft
tar -zxvf libevent-2.0.16-stable.tar.gz
cd libevent-2.0.16-stable
./configure --prefix=/usr/
make
make install
#安装Memcached#######################################################################
cd /home/soft
tar -zxvf memcached-1.4.10.tar.gz
cd memcached-1.4.10
./configure --with-libevent=/usr
make
make install
ln -s /usr/lib/libevent* /usr/lib/
/usr/local/bin/memcached -d -l 127.0.0.1 -p 11211 -u nobody -m 200 -c 1024 -P /tmp/memcached.pid
#设置自动启动#########################################################################
rm -f /etc/init.d/memcached
cd /home/soft
cp memcached /etc/init.d/memcached
chmod 711 /etc/init.d/memcached
chkconfig --add memcached
chkconfig --level  345  memcached  on
chkconfig --list memcached
#安装MemcahePHP的扩展#################################################################
cd /home/soft
tar -zxvf memcache-3.0.6.tgz
cd memcache-3.0.6
$BASE_PATH/php/bin/phpize
./configure --with-php-config=$BASE_PATH/php/bin/php-config --with-zlib-dir --enable-memcache
make
make install
# 安装ZEND扩展
cd /home/soft
tar -zxvf ZendGuardLoader-php-5.3-linux-glibc23-i386.tar.gz
cd ZendGuardLoader-php-5.3-linux-glibc23-i386
mkdir -p $BASE_PATH/php/lib/php/extensions/Zend
cp -R php-5.3.x $BASE_PATH/php/lib/php/extensions/Zend/
#安装Xcache
cd /home/soft
tar -zxvf xcache-1.3.2.tar.gz
cd xcache-1.3.2
$BASE_PATH/php/bin/phpize
./configure --with-php-config=$BASE_PATH/php/bin/php-config --enable-xcache --enable-xcache-assembler
make
make install
# 安装Redis服务端 
cd /home/soft
tar -zxvf redis-2.4.5.tar.gz
cd redis-2.4.5
make
make PREFIX=$BASE_PATH/redis install
# 设置Redis服务端
cd /home/soft
rm -f /etc/redis/redis.conf
rm -rf /etc/redis/
mkdir /etc/redis
mkdir -p /var/lib/redis
cp redis.conf /etc/redis/redis.conf
# 防止Redis脚本在重启或停止报错
echo "vm.overcommit_memory = 1" >> /etc/sysctl.conf
sysctl -p
# 设置自动启动
cd /home/soft
rm -f /etc/init.d/redis
cp redis /etc/init.d/redis

# 启动Redis
chmod 755 /etc/init.d/redis
chkconfig --add redis
chkconfig --level 345 redis on
chkconfig --list redis
# 安装PHPRedis扩展
cd /home/soft
tar -zxvf phpredis-2.1.3.tar.gz
cd phpredis
#根据PHP实际安装路径进行设置
$BASE_PATH/php/bin/phpize
./configure -with-php-config=$BASE_PATH/php/bin/php-config
make
make install

mkdir -p /var/local/webserver/nginx/logs
chmod +w /var/local/webserver/nginx/logs
chown -R www:www /var/local/webserver/nginx/logs

# 安装pcre-8.21
cd /home/soft
tar zxf pcre-8.21.tar.gz
cd pcre-8.21
./configure 
make
make install

# 安装Nginx
cd /home/soft
tar zxf nginx-1.1.12.tar.gz
cd nginx-1.1.12
./configure \
    --user=www\
    --group=www\
    --prefix=$BASE_PATH/nginx\
    --sbin-path=$BASE_PATH/nginx/sbin/nginx\
    --conf-path=$BASE_PATH/nginx/conf/nginx.conf\
    --with-http_stub_status_module\
    --with-http_ssl_module\
    --with-pcre\
    --lock-path=/var/run/nginx.lock\
    --pid-path=/var/run/nginx.pid
make
make install
cd /home/soft
mv $BASE_PATH/nginx/conf/nginx.conf $BASE_PATH/nginx/conf/nginx.conf.old
cp nginx.conf $BASE_PATH/nginx/conf/
cp -R vhosts $BASE_PATH/nginx/conf/
rm -f $BASE_PATH/nginx/conf/fastcgi_params
cp fastcgi_params $BASE_PATH/nginx/conf/fastcgi_params
#自动启动
cd /home/soft
rm -f /etc/init.d/nginx
cp nginx /etc/init.d/
chmod 711 /etc/init.d/nginx
chkconfig --add nginx
chkconfig  --level  345  nginx  on
#开启防火墙
/sbin/iptables -I INPUT -p tcp --dport 80 -j ACCEPT
/sbin/iptables -I INPUT -p tcp --dport 433 -j ACCEPT
/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT
/etc/rc.d/init.d/iptables save
/etc/init.d/iptables restart

#重启所有服务器
/etc/init.d/nginx restart
/etc/init.d/php-fpm restart
/etc/init.d/mysql restart
/etc/init.d/memcached restart
/etc/init.d/redis restart

原文地址:http://www.cnblogs.com/wk0423/archive/2012/01/17/2325050.html