夜雨,断魂

人生能有多少天是按照自己的想法去活着

redis主从同步

【redis主从同步】

redis数据库一般走的都是单线程,如果CPU有多核心的话就浪费,因此在同一个环境中一般都多装几个实例

rpm -ivh tcl-8.5.7-6.el6.x86_64.rpm

tar -zxf redis-3.0.3.tar.gz

cd redis

make

make test

make PREFIX=/usr/local/redis install

cd /usr/local/redis

cp /root/redis-3.0.3/redis.conf .

vi redis.conf

# By default Redis does not run as a daemon. Use 'yes' if you need it.

# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.

daemonize yes

cd /usr/local/redis 进入 redis 安装目录

./bin/redis-server ./redis.conf 开启 redis 服务

./bin/redis-cli -h localhost -p 6379 连接 Redis 数据库

cd /usr/local/redis/

cd ..

cp -r redis/ redis-slave/

vim redis-slave/redis.conf

pidfile=/usr/local/redis-slave/redis.pid

port 6380

dir /usr/local/redis-slave

slaveof 127.0.0.1 6379 主服务器 IP 主服务器端口号

masterauth 123456 主服务器密码

分别启动主从服务器 启动从服务器的时候用 -p  指定端口号                    】

实验  pkill  redis   &&   netstat  -anpt  |  grep  :6379

cd /usr/local/   &&   cp  -a  redis/  redis-6380   &&   cd   redis-6380/   &&   rm  -rf  dump.rdb  &&   cd  ..  &&   cd  redis  &&  rm  -rf  dump.rdb   &&   cd  /usr/local/redis-6380/  

vim  redis.conf   

1.(搜索pidfile  默认路径是redis.pid 修改为/var/run/redis-6380.pid  修改端口为6380

2. 搜索dir 修改持久化保存方案路径为/usr/local/redis-6380

3. 第205行取消注释并将masterrip  masterport删除修改为10.10.10.11 6379

4. 取消masterauthmaster服务器的密码的注释并将master  password修改为123

集群化:在数据库里有中间键,在redis里不用

/usr/local/redis/bin/redis-server  /usr/local/redis/redis.conf (启动第一个)   &&   /usr/local/redis-6380/bin/redis-server /usr/local/redis-6380/redis.conf  (启动第二个)

/usr/local/redis/bin/redis-cli   -h  10.10.10.5  -p  6379  -h指定当前地址 -p指定端口)  &&  keys  *  dump文件已删所以都是空的)   &&   set  zhangsan  123   &&   get   zhangsan exit退出)   &&   /usr/local/redis/bin/redis-cli   -h  10.10.10.5  -p  6380   &&  keys  *  (主从同步  注意配置文件中如果设置密码为123,需要auth  123验证 )

 

 

 

 

Redis + Mysql

对于运维来说如果搭建这个服务的话,搭建apache+PHPfpm+mysql+redis   apachephpfpm要结合,为php安装redis的扩展模块,php默认是没有redis支持的。然后将数据库密码告诉给开发,将redisIP地址和密码告诉给开发  。redismysql不需要进行联立,是通过代码进行偶合的

注意:mysqlredis不需要进行联立

yum -y install gcc*

eject

yum -y install *

一、配置基本网站

vim /etc/nginx/conf.d/default.conf

server {

listen 80;

server_name www.xdl.com;

location / {

root /www/;

index index.php index.html index.htm;

}

location ~ \.php$ {

root /www/;

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php;

fastcgi_param SCRIPT_FILENAME /www/$fastcgi_script_name;

include fastcgi_params;

}

}

修改 FPM 配置:

sed -i 's/apache/nginx/g' /etc/php-fpm.d/www.conf

开启服务

service php-fpm start

service mysqld start

mkdir /www

chown -R nginx:nginx /www/

service nginx start

授权

mysqladmin -uroot password 123

测试

vim /www/index.php

<?php

phpinfo();

?>

二、安装 redis

rpm -ivh tcl-8.5.7-6.el6.x86_64.rpm

tar -zxf redis-3.0.3.tar.gz

cd redis

make

make test

make PREFIX=/usr/local/redis install

cd /usr/local/redis

cp /root/redis-3.0.3/redis.conf .

vi redis.conf

# By default Redis does not run as a daemon. Use 'yes' if you need it.

# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.

daemonize yes

cd /usr/local/redis 进入 redis 安装目录

./bin/redis-server ./redis.conf 开启 redis 服务

./bin/redis-cli -h localhost -p 6379 连接 Redis 数据库

三、安装 php 扩展

unzip phpredis-master.zip

cd phpredis-master

phpize 检测模块

./configure –with-php-config=/usr/bin/php-config

make && make install

vim /etc/php.ini 末尾加

extension=redis.so

/etc/init.d/php-fpm restart  service php-fpm restart

mysql -u root -p123456

create database mytest;

use mytest;

use mytest;

CREATE TABLE test (id int NOT NULL AUTO_INCREMENT, name char(8) DEFAULT NULL, PRIMARY KEY (id)) ENGINE=InnoDB

AUTO_INCREMENT=10 DEFAULT CHARSET=utf8;

mysql> INSERT INTO test VALUES (1,'a1'),(2,'a2'),(3,'a3'),(4,'a4'),(5,'a5');

mysql> select * from mytest.test;

vim /www/1.php

<?php

$redis = new Redis();

$redis->connect('127.0.0.1',6379) or die ("could net connect redis server");

$query = "select * from test limit 4";

for ($key = 1; $key < 4; $key++)

{

if (!$redis->get($key))

{

$connect = mysql_connect('127.0.0.1','root','123456');

mysql_select_db(mytest);

$result = mysql_query($query);

while ($row = mysql_fetch_assoc($result))

{

$redis->set($row['id'],$row['name']);

}

$myserver = 'mysql';

break;

}

else

{

$myserver = "redis";

$data[$key] = $redis->get($key);

}

}

echo $myserver;

echo "<br>";

for ($key = 1; $key < 4; $key++)

{

echo "number is <b><font color=#FF0000>$key</font></b>";

echo "<br>";

echo "name is <b><font color=#FF0000>$data[$key]</font></b>";

echo "<br>";

}

?>                                                                            

Next Post

Previous Post

5 Comments

  1. buy hydroxychloroquine sulphate 2021年6月22日

    Hello, Neat post. There is an issue along with your
    web site in web explorer, would test this? IE nonetheless is the market chief and
    a good component of other folks will omit your magnificent writing due to this problem. http://hydroxychloroquined.online/

  2. IQoption one night stand method forex 2021年6月22日

    This is my first time visit at here and i am actually impressed to read everthing
    at alone place.

  3. compare tadalafil viagra and levitra 2021年6月22日

    Good day I am so glad I found your website, I really found you by mistake,
    while I was researching on Google for something else,
    Regardless I am here now and would just like to say thank
    you for a tremendous post and a all round entertaining blog (I also love the
    theme/design), I don’t have time to go through it all at
    the minute but I have saved it and also added in your RSS feeds, so when I have time I will be back to read
    more, Please do keep up the superb work. http://cleckleyfloors.com/

  4. deposit poker idn 2021年6月22日

    WOW just what I was searching for. Came here by searching for deposit pulsa idn poker

Leave a Reply

© 2021 夜雨,断魂

ICP备案号: 京ICP备19038630号

版权所有@ 王力翔

耗时 2.327 秒 | 查询 45 次 | 内存 20.74 MB