hadoop生态搭建(3节点)-14.redis配置
# ==================================================================规划
node1 redis:7000 7001 192.168.6.131
node2 redis:7002 7003 192.168.6.132
node3 redis:7004 7005 192.168.6.133
# ==================================================================安装 redis
yum install -y gcc g++ gcc-c++ make tar -zxvf ~/redis-4.0.10.tar.gz cd ~/redis-4.0.10 make && make install PREFIX=/usr/local/redis-4.0.10 rm -r ~/redis-4.0.10.tar.gz
# 环境变量
# ==================================================================node1 node2 node3
vi /etc/profile # 在export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL下添加 export JAVA_HOME=/usr/java/jdk1.8.0_111 export ZOOKEEPER_HOME=/usr/local/zookeeper-3.4.12 export HADOOP_HOME=/usr/local/hadoop-2.7.6 export MYSQL_HOME=/usr/local/mysql export HBASE_HOME=/usr/local/hbase-1.2.4 export HIVE_HOME=/usr/local/hive-2.1.1 export SCALA_HOME=/usr/local/scala-2.12.4 export KAFKA_HOME=/usr/local/kafka_2.12-0.10.2.1 export FLUME_HOME=/usr/local/flume-1.8.0 export SPARK_HOME=/usr/local/spark-2.3.0 export STORM_HOME=/usr/local/storm-1.1.0 export ERLANG_HOME=/usr/local/erlang export RABBITMQ_HOME=/usr/local/rabbitmq_server-3.7.5 export MONGODB_HOME=/usr/local/mongodb-3.4.5 export REDIS_HOME=/usr/local/redis-4.0.10 export RUBY_HOME=/usr/local/ruby-2.5.1 export PATH=$PATH:$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$ZOOKEEPER_HOME/bin:$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$MYSQL_HOME/bin:$HBASE_HOME/bin:$HIVE_HOME/bin:$SCALA_HOME/bin:$KAFKA_HOME/bin:$FLUME_HOME/bin:$SPARK_HOME/bin:$SPARK_HOME/sbin:$STORM_HOME/bin:$ERLANG_HOME/bin:$RABBITMQ_HOME/ebin:$RABBITMQ_HOME/sbin:$MONGODB_HOME/bin:$REDIS_HOME/bin:$RUBY_HOME/bin export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar export HADOOP_INSTALL=$HADOOP_HOME export HADOOP_MAPRED_HOME=$HADOOP_HOME export HADOOP_COMMON_HOME=$HADOOP_HOME export HADOOP_HDFS_HOME=$HADOOP_HOME export YARN_HOME=$HADOOP_HOME export HADOOP_COMMON_LIB_NATIVE_DIR=$HADOOP_HOME/lib/native
# ==================================================================node1
# 使环境变量生效 source /etc/profile # 查看配置结果 echo $REDIS_HOME cp /root/redis-4.0.10/redis.conf $REDIS_HOME/redis.conf
# ==================================================================node1
vi $REDIS_HOME/redis.conf # 根据本机所在的IP或hostname bind node1 # redis后台运行 daemonize yes # pidfile文件 pidfile /usr/local/redis-4.0.10/redis_6379.pid # aof日志开启 有需要就开启,它会每次写操作都记录一条日志 appendonly yes scp -r $REDIS_HOME node2:/usr/local/ scp -r $REDIS_HOME node3:/usr/local/ mkdir -p $REDIS_HOME/redis_cluster/7000 mkdir -p $REDIS_HOME/redis_cluster/7001 vi $REDIS_HOME/redis_cluster/7000/redis.conf # 端口根据对应的文件夹配置端口 7000,7001,7002,7003,7004,7005 port 7000 # 根据本机所在的IP或hostname配置 node1 node2 node3 bind node1 # redis后台运行 daemonize yes # pidfile文件对应7000,7001,7002,7003,7004,7005 pidfile /usr/local/redis-4.0.10/redis_cluster/redis_7000.pid # 开启集群 cluster-enabled yes # 集群的配置 配置文件首次启动自动生成 7000,7001,7002,7003,7004,7005 cluster-config-file /usr/local/redis-4.0.10/redis_cluster/nodes_7000.conf # 请求超时 默认15秒,可自行设置 cluster-node-timeout 15000 # aof日志开启 有需要就开启,它会每次写操作都记录一条日志 appendonly yes vi $REDIS_HOME/redis_cluster/7001/redis.conf # 端口根据对应的文件夹配置端口 7000,7001,7002,7003,7004,7005 port 7001 # 根据本机所在的IP或hostname配置 node1 node2 node3 bind node1 # redis后台运行 daemonize yes # pidfile文件对应7000,7001,7002,7003,7004,7005 pidfile /usr/local/redis-4.0.10/redis_cluster/redis_7001.pid # 开启集群 cluster-enabled yes # 集群的配置 配置文件首次启动自动生成 7000,7001,7002,7003,7004,7005 cluster-config-file /usr/local/redis-4.0.10/redis_cluster/nodes_7001.conf # 请求超时 默认15秒,可自行设置 cluster-node-timeout 15000 # aof日志开启 有需要就开启,它会每次写操作都记录一条日志 appendonly yes
# ==================================================================node2 node3
# 使环境变量生效 source /etc/profile # 查看配置结果 echo $REDIS_HOME
# ==================================================================node2
mkdir -p $REDIS_HOME/redis_cluster/7002 mkdir -p $REDIS_HOME/redis_cluster/7003 vi $REDIS_HOME/redis_cluster/7002/redis.conf # 端口根据对应的文件夹配置端口 7000,7001,7002,7003,7004,7005 port 7002 # 根据本机所在的IP或hostname配置 node1 node2 node3 bind node2 # redis后台运行 daemonize yes # pidfile文件对应7000,7001,7002,7003,7004,7005 pidfile /usr/local/redis-4.0.10/redis_cluster/redis_7002.pid # 开启集群 cluster-enabled yes # 集群的配置 配置文件首次启动自动生成 7000,7001,7002,7003,7004,7005 cluster-config-file /usr/local/redis-4.0.10/redis_cluster/nodes_7002.conf # 请求超时 默认15秒,可自行设置 cluster-node-timeout 15000 # aof日志开启 有需要就开启,它会每次写操作都记录一条日志 appendonly yes vi $REDIS_HOME/redis_cluster/7003/redis.conf # 端口根据对应的文件夹配置端口 7000,7001,7002,7003,7004,7005 port 7003 # 根据本机所在的IP或hostname配置 node1 node2 node3 bind node2 # redis后台运行 daemonize yes # pidfile文件对应7000,7001,7002,7003,7004,7005 pidfile /usr/local/redis-4.0.10/redis_cluster/redis_7003.pid # 开启集群 cluster-enabled yes # 集群的配置 配置文件首次启动自动生成 7000,7001,7002,7003,7004,7005 cluster-config-file /usr/local/redis-4.0.10/redis_cluster/nodes_7003.conf # 请求超时 默认15秒,可自行设置 cluster-node-timeout 15000 # aof日志开启 有需要就开启,它会每次写操作都记录一条日志 appendonly yes
# ==================================================================node3
mkdir -p $REDIS_HOME/redis_cluster/7004 mkdir -p $REDIS_HOME/redis_cluster/7005 vi $REDIS_HOME/redis_cluster/7004/redis.conf # 端口根据对应的文件夹配置端口 7000,7001,7002,7003,7004,7005 port 7004 # 根据本机所在的IP或hostname配置 node1 node2 node3 bind node3 # redis后台运行 daemonize yes # pidfile文件对应7000,7001,7002,7003,7004,7005 pidfile /usr/local/redis-4.0.10/redis_cluster/redis_7004.pid # 开启集群 cluster-enabled yes # 集群的配置 配置文件首次启动自动生成 7000,7001,7002,7003,7004,7005 cluster-config-file /usr/local/redis-4.0.10/redis_cluster/nodes_7004.conf # 请求超时 默认15秒,可自行设置 cluster-node-timeout 15000 # aof日志开启 有需要就开启,它会每次写操作都记录一条日志 appendonly yes vi $REDIS_HOME/redis_cluster/7005/redis.conf # 端口根据对应的文件夹配置端口 7000,7001,7002,7003,7004,7005 port 7005 # 根据本机所在的IP或hostname配置 node1 node2 node3 bind node3 # redis后台运行 daemonize yes # pidfile文件对应7000,7001,7002,7003,7004,7005 pidfile /usr/local/redis-4.0.10/redis_cluster/redis_7005.pid # 开启集群 cluster-enabled yes # 集群的配置 配置文件首次启动自动生成 7000,7001,7002,7003,7004,7005 cluster-config-file /usr/local/redis-4.0.10/redis_cluster/nodes_7005.conf # 请求超时 默认15秒,可自行设置 cluster-node-timeout 15000 # aof日志开启 有需要就开启,它会每次写操作都记录一条日志 appendonly yes
# 开启集群
# ==================================================================node1 node2 node3
# 复制src目录中的redis-trib.rb 到/usr/local/redis/bin目录 cp ~/redis-4.0.10/src/redis-trib.rb $REDIS_HOME/bin scp -r ~/redis-4.0.10/src/redis-trib.rb node2:$REDIS_HOME/bin scp -r ~/redis-4.0.10/src/redis-trib.rb node3:$REDIS_HOME/bin
# https://cache.ruby-lang.org/pub/ruby/2.5/ruby-2.5.1.tar.gz
# https://rubygems.org/pages/download
# https://rubygems.org/gems/redis/versions/4.0.0
# ==================================================================安装 ruby
#yum -y install wget #wget http://cache.ruby-lang.org/pub/ruby/2.5/ruby-2.5.1.tar.gz tar -zxvf ~/ruby-2.5.1.tar.gz -C /usr/local/ cd /usr/local/ruby-2.5.1 ./configure make && make install ln -s $REDIS_HOME/bin/ruby /usr/bin/ruby ln -s $REDIS_HOME/bin/gem /usr/bin/gem ruby -v cd ~ # 缺少zlib依赖,需要安装zlib库 yum install zlib-devel cd $RUBY_HOME/ext/zlib ruby extconf.rb vi Makefile top_srcdir =../.. make && make install cd ~ # 缺少openssl库,安装openssl库 yum install openssl-devel cd $RUBY_HOME/ext/openssl ruby extconf.rb vi Makefile top_srcdir =../.. make && make install cd ~ tar -zxvf ~/rubygems-2.7.7.tgz -C /usr/local/ cd /usr/local/rubygems-2.7.7 ruby setup.rb cd ~ gem install -l redis-4.0.0.gem scp -r ~/ruby-2.5.1.tar.gz node2:~/ scp -r ~/ruby-2.5.1.tar.gz node3:~/ scp -r ~/rubygems-2.7.7.tgz node2:~/ scp -r ~/rubygems-2.7.7.tgz node3:~/ scp -r ~/redis-4.0.0.gem node2:~/ scp -r ~/redis-4.0.0.gem node3:~/ rm -r ~/ruby-2.5.1.tar.gz rm -r ~/rubygems-2.7.7.tgz rm -r ~/redis-4.0.0.gem
# ==================================================================node2 node3
tar -zxvf ~/ruby-2.5.1.tar.gz -C /usr/local/ cd /usr/local/ruby-2.5.1 ./configure make && make install ln -s $REDIS_HOME/bin/ruby /usr/bin/ruby ln -s $REDIS_HOME/bin/gem /usr/bin/gem ruby -v # 缺少zlib依赖,需要安装zlib库 cd ~ yum install zlib-devel cd $RUBY_HOME/ext/zlib ruby extconf.rb vi Makefile top_srcdir =../.. make && make install # 缺少openssl库,安装openssl库 cd ~ yum install openssl-devel cd $RUBY_HOME/ext/openssl ruby extconf.rb vi Makefile top_srcdir =../.. make && make install cd ~ tar -zxvf ~/rubygems-2.7.7.tgz -C /usr/local/ cd /usr/local/rubygems-2.7.7 ruby setup.rb cd ~ gem install -l redis-4.0.0.gem rm -r ~/ruby-2.5.1.tar.gz rm -r ~/rubygems-2.7.7.tgz rm -r ~/redis-4.0.0.gem
shutdown -h now
# 快照 redis集群前
# 启动
# ==================================================================node1 $REDIS_HOME/bin/redis-server $REDIS_HOME/redis_cluster/7000/redis.conf $REDIS_HOME/bin/redis-server $REDIS_HOME/redis_cluster/7001/redis.conf # ==================================================================node2 $REDIS_HOME/bin/redis-server $REDIS_HOME/redis_cluster/7002/redis.conf $REDIS_HOME/bin/redis-server $REDIS_HOME/redis_cluster/7003/redis.conf # ==================================================================node3 $REDIS_HOME/bin/redis-server $REDIS_HOME/redis_cluster/7004/redis.conf $REDIS_HOME/bin/redis-server $REDIS_HOME/redis_cluster/7005/redis.conf # 查看进程 ps -ef | grep redis # 查看端口 # netstat -tnlp | grep redis # ==================================================================node1 # $REDIS_HOME/bin/redis-trib.rb create --replicas 1 node1:7000 node1:7001 node2:7002 node2:7003 node3:7004 node3:7005 $REDIS_HOME/bin/redis-trib.rb create --replicas 1 192.168.6.131:7000 192.168.6.131:7001 192.168.6.132:7002 192.168.6.132:7003 192.168.6.133:7004 192.168.6.133:7005 # $REDIS_HOME/bin/redis-trib.rb check node1:7001 $REDIS_HOME/bin/redis-trib.rb check 192.168.6.131:7001 # (-c 制定集群模式,-h 制定ip -p 制定端口号) # ./redis-cli -c -h -p # $REDIS_HOME/bin/redis-cli -c -h node1 -p 7001 $REDIS_HOME/bin/redis-cli -c -h 192.168.6.131 -p 7001 # 查看集群信息 cluster info # 查看节点列表 cluster nodes # 关闭集群 # $REDIS_HOME/bin/redis-cli -c -h node1 -p 7001 shutdown $REDIS_HOME/bin/redis-cli -c -h 192.168.6.131 -p 7001 shutdown shutdown -h now # 快照 redis集群
# ==================================================================认证
# 启动 # ==================================================================node1 $REDIS_HOME/bin/redis-server $REDIS_HOME/redis_cluster/7000/redis.conf $REDIS_HOME/bin/redis-server $REDIS_HOME/redis_cluster/7001/redis.conf # ==================================================================node2 $REDIS_HOME/bin/redis-server $REDIS_HOME/redis_cluster/7002/redis.conf $REDIS_HOME/bin/redis-server $REDIS_HOME/redis_cluster/7003/redis.conf # ==================================================================node3 $REDIS_HOME/bin/redis-server $REDIS_HOME/redis_cluster/7004/redis.conf $REDIS_HOME/bin/redis-server $REDIS_HOME/redis_cluster/7005/redis.conf # 查看进程 ps -ef | grep redis # 增加认证,是每一个节点的密码必须都一致,如果不一致,切换的时候就会出现没有权限登问题,而且必须登陆进每一个节点设置一次认证才可以。 $REDIS_HOME/bin/redis-cli -c -h 192.168.6.131 -p 7000 > config set masterauth Redis*123456 > config set requirepass Redis*123456 > exit $REDIS_HOME/bin/redis-cli -c -h 192.168.6.131 -p 7001 > config set masterauth Redis*123456 > config set requirepass Redis*123456 > exit $REDIS_HOME/bin/redis-cli -c -h 192.168.6.132 -p 7002 > config set masterauth Redis*123456 > config set requirepass Redis*123456 > exit $REDIS_HOME/bin/redis-cli -c -h 192.168.6.132 -p 7003 > config set masterauth Redis*123456 > config set requirepass Redis*123456 > exit $REDIS_HOME/bin/redis-cli -c -h 192.168.6.133 -p 7004 > config set masterauth Redis*123456 > config set requirepass Redis*123456 > exit $REDIS_HOME/bin/redis-cli -c -h 192.168.6.133 -p 7005 > config set masterauth Redis*123456 > config set requirepass Redis*123456 > exit # 每个节点(-a Redis*123456 就是刚才所设置的密码,用于认证) $REDIS_HOME/bin/redis-cli -h 192.168.6.131 -p 7000 -c -a Redis*123456 > config rewrite > exit $REDIS_HOME/bin/redis-cli -h 192.168.6.131 -p 7001 -c -a Redis*123456 > config rewrite > exit $REDIS_HOME/bin/redis-cli -h 192.168.6.132 -p 7002 -c -a Redis*123456 > config rewrite > exit $REDIS_HOME/bin/redis-cli -h 192.168.6.132 -p 7003 -c -a Redis*123456 > config rewrite > exit $REDIS_HOME/bin/redis-cli -h 192.168.6.133 -p 7004 -c -a Redis*123456 > config rewrite > exit $REDIS_HOME/bin/redis-cli -h 192.168.6.133 -p 7005 -c -a Redis*123456 > config rewrite > exit $REDIS_HOME/bin/redis-cli -c -h 192.168.6.131 -p 7000 -a Redis*123456 shutdown $REDIS_HOME/bin/redis-cli -c -h 192.168.6.131 -p 7001 -a Redis*123456 shutdown $REDIS_HOME/bin/redis-cli -c -h 192.168.6.132 -p 7002 -a Redis*123456 shutdown $REDIS_HOME/bin/redis-cli -c -h 192.168.6.132 -p 7003 -a Redis*123456 shutdown $REDIS_HOME/bin/redis-cli -c -h 192.168.6.133 -p 7004 -a Redis*123456 shutdown $REDIS_HOME/bin/redis-cli -c -h 192.168.6.133 -p 7005 -a Redis*123456 shutdown # 再次启动 # ==================================================================node1 $REDIS_HOME/bin/redis-server $REDIS_HOME/redis_cluster/7000/redis.conf $REDIS_HOME/bin/redis-server $REDIS_HOME/redis_cluster/7001/redis.conf # ==================================================================node2 $REDIS_HOME/bin/redis-server $REDIS_HOME/redis_cluster/7002/redis.conf $REDIS_HOME/bin/redis-server $REDIS_HOME/redis_cluster/7003/redis.conf # ==================================================================node3 $REDIS_HOME/bin/redis-server $REDIS_HOME/redis_cluster/7004/redis.conf $REDIS_HOME/bin/redis-server $REDIS_HOME/redis_cluster/7005/redis.conf $REDIS_HOME/bin/redis-cli -h 192.168.6.131 -p 7000 -c -a Redis*123456 #查看所有key > keys * > set key value > get key > keys * > exit $REDIS_HOME/bin/redis-cli -c -h 192.168.6.131 -p 7000 -a Redis*123456 shutdown $REDIS_HOME/bin/redis-cli -c -h 192.168.6.131 -p 7001 -a Redis*123456 shutdown $REDIS_HOME/bin/redis-cli -c -h 192.168.6.132 -p 7002 -a Redis*123456 shutdown $REDIS_HOME/bin/redis-cli -c -h 192.168.6.132 -p 7003 -a Redis*123456 shutdown $REDIS_HOME/bin/redis-cli -c -h 192.168.6.133 -p 7004 -a Redis*123456 shutdown $REDIS_HOME/bin/redis-cli -c -h 192.168.6.133 -p 7005 -a Redis*123456 shutdown shutdown -h now # 快照 redis集群认证
# ==================================================================单机启动
# 指定配置文件启动 Redis客户端连接指定Redis Server
$REDIS_HOME/bin/redis-server $REDIS_HOME/redis.conf
#连接指定Redis Server
$REDIS_HOME/bin/redis-cli -h node1
# 设置:set key1 value1
# 获取:get key1
# 关闭客户端
# $REDIS_HOME/bin/redis-cli -p 6379 shutdown