1、安装编译依赖的环境
yum install gcc gcc-c++ make -y
2、远程挂载
[root@localhost ~]# mkdir /abc
[root@localhost ~]# mount.cifs //192.168.100.7/JB /abc/
[root@localhost abc]# cd /abc/rpm/
3、解压安装包
tar zxvf redis-5.0.7.tar.gz -C /opt/
4、编译并安装
cd /opt/redis-5.0.7/
make
make PREFIX=/usr/local/redis/ install
5、建立软连接
ln -s /usr/local/redis/bin/* /usr/local/bin/
6、执行启动脚本
cd /opt/redis-5.0.7/utils/
./install_server.sh
一直回车
在Please select the redis executable path [/usr/local/bin/redis-server]后,
添加路径:/usr/local/redis/bin/redis-server
7、查看端口服务开启状态
[root@localhost utils]# netstat -natp | grep 6379
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 50863/redis-server
8、修改Redis配置文件
vim /etc/redis/6379.conf
70/ #bind 127.0.0.1 //注释掉,Redis中的bind选项默认监听所有网卡
89/ protected-mode no //关闭保护模式
93/ port 6379 //监听端口,默认开启
137/ daemonize yes //以独立进程启动,默认开启
700/ appendonly yes //开启aof持久化
833/ cluster-enabled yes //开启群集功能
841/ cluster-config-file nodes-6379.conf //群集名称文件设置
847/ cluster-node-timeout 15000 //群集超时时间设置
9、重启服务
/etc/init.d/redis_6379 restart
1、导入key文件
gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
gpg: directory `/root/.gnupg' created
gpg: new configuration file `/root/.gnupg/gpg.conf' created
gpg: WARNING: options in `/root/.gnupg/gpg.conf' are not yet active during this run
gpg: keyring `/root/.gnupg/secring.gpg' created
gpg: keyring `/root/.gnupg/pubring.gpg' created
gpg: requesting key D39DC0E3 from hkp server keys.gnupg.net
gpg: /root/.gnupg/trustdb.gpg: trustdb created
gpg: key D39DC0E3: public key "Michal Papis (RVM signing)
gpg: no ultimately trusted keys found
gpg: Total number processed: 1
gpg: imported: 1 (RSA: 1)
2、安装rvm
curl -sSL https://get.rvm.io | bash -s stable
[root@master ~]# curl -sSL https://get.rvm.io | bash -s stable
Downloading https://github.com/rvm/rvm/archive/1.29.9.tar.gz
Downloading https://github.com/rvm/rvm/releases/download/1.29.9/1.29.9.tar.gz.asc
gpg: Signature made Wed 10 Jul 2019 04:31:02 PM CST using RSA key ID 39499BDB
gpg: Can't check signature: No public key
GPG signature verification failed for '/usr/local/rvm/archives/rvm-1.29.9.tgz' - 'https://github.com/rvm/rvm/releases/download/1.29.9/1.29.9.tar.gz.asc'! Try to install GPG v2 and then fetch the public key:
gpg2 --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
or if it fails:
command curl -sSL https://rvm.io/mpapis.asc | gpg2 --import -
command curl -sSL https://rvm.io/pkuczynski.asc | gpg2 --import -
In case of further problems with validation please refer to https://rvm.io/rvm/security执行脚本:
[root@master ~]# vim abc.sh
#!/usr/bin/env bash
shopt -s extglob
set -o errtrace
set -o errexit
set -o pipefail
rvm_install_initialize()
{
DEFAULT_SOURCES=(github.com/rvm/rvm bitbucket.org/mpapis/rvm)
BASH_MIN_VERSION="3.2.25"
if
[[ -n "${BASH_VERSION:-}" &&
"$(\printf "%b" "${BASH_VERSION:-}\n${BASH_MIN_VERSION}\n" | LC_ALL=C \sort -t"." -k1,1n -k2,2n -k3,3n | \head -n1)" != "${BASH_MIN_VERSION}"
]]
then
echo "BASH ${BASH_MIN_VERSION} required (you have $BASH_VERSION)"
exit 1
fi
export HOME PS4
export rvm_trace_flag rvm_debug_flag rvm_user_install_flag rvm_ignore_rvmrc rvm_prefix rvm_path
PS4="+ \${BASH_SOURCE##\${rvm_path:-}} : \${FUNCNAME[0]:+\${FUNCNAME[0]}()} \${LINENO} > "
}
log() { printf "%b\n" "$*"; }
debug(){ [[ ${rvm_debug_flag:-0} -eq 0 ]] || printf "%b\n" "$*" >&2; }
warn() { log "WARN: $*" >&2 ; }
fail() { fail_with_code 1 "$*" ; }
fail_with_code() { code="$1" ; shift ; log "\nERROR: $*\n" >&2 ; exit "$code" ; }
rvm_install_commands_setup()
{
\which which >/dev/null 2>&1 || fail "Could not find 'which' command, make sure it's available first before continuing installation."
\which grep >/dev/null 2>&1 || fail "Could not find 'grep' command, make sure it's available first before continuing installation."
if
[[ -z "${rvm_tar_command:-}" ]] && builtin command -v gtar >/dev/null
then
rvm_tar_command=gtar
elif
${rvm_tar_command:-tar} --help 2>&1 | GREP_OPTIONS="" \grep -- --strip-components >/dev/null
then
rvm_tar_command="${rvm_tar_command:-tar}"
else
case "$(uname)" in
(OpenBSD)
log "Trying to install GNU version of tar, might require sudo password"
if (( UID ))
then sudo pkg_add -z gtar-1
else pkg_add -z gtar-1
fi
rvm_tar_command=gtar
;;
(Darwin|FreeBSD|DragonFly) # it's not possible to autodetect on OSX, the help/man does not mention all flags
rvm_tar_command=tar
;;
(SunOS)
case "$(uname -r)" in
(5.10)
log "Trying to install GNU version of tar, might require sudo password"
if (( UID ))
then
if \which sudo >/dev/null 2>&1
then sudo_10=sudo
elif \which /opt/csw/bin/sudo >/dev/null 2>&1
then sudo_10=/opt/csw/bin/sudo
else fail "sudo is required but not found. You may install sudo from OpenCSW repository (https://www.opencsw.org/about)"
fi
pkginfo -q CSWpkgutil || $sudo_10 pkgadd -a $rvm_path/config/solaris/noask -d https://get.opencsw.org/now CSWpkgutil
sudo /opt/csw/bin/pkgutil -iy CSWgtar -t https://mirror.opencsw.org/opencsw/unstable
else
pkginfo -q CSWpkgutil || pkgadd -a $rvm_path/config/solaris/noask -d https://get.opencsw.org/now CSWpkgutil
/opt/csw/bin/pkgutil -iy CSWgtar -t https://mirror.opencsw.org/opencsw/unstable
fi
rvm_tar_command=/opt/csw/bin/gtar
;;
(*)
rvm_tar_command=tar
;;
esac
esac
builtin command -v ${rvm_tar_command:-gtar} >/dev/null ||
fail "Could not find GNU compatible version of 'tar' command, make sure it's available first before continuing installation."
fi
if
[[ " ${rvm_tar_options:-} " != *" --no-same-owner "* ]] &&
$rvm_tar_command --help 2>&1 | GREP_OPTIONS="" \grep -- --no-same-owner >/dev/null
then
rvm_tar_options="${rvm_tar_options:-}${rvm_tar_options:+ }--no-same-owner"
fi
}
usage()
{
printf "%b" "
Usage
rvm-installer [options] [action]
Options
[[--]version]
The version or tag to install. Valid values are:
latest - The latest tagged version.
latest-minor - The latest minor version of the current major version.
latest- - The latest minor version of version x.
latest-. - The latest patch version of version x.y.
.. - Major version x, minor version y and patch z.
[--]branch
The name of the branch from which RVM is installed. This option can be used
with the following formats for :
/
If account is rvm or mpapis, installs from one of the following:
https://github.com/rvm/rvm/archive/master.tar.gz
https://bitbucket.org/mpapis/rvm/get/master.tar.gz
Otherwise, installs from:
https://github.com//rvm/archive/master.tar.gz
/
If account is rvm or mpapis, installs from one of the following:
https://github.com/rvm/rvm/archive/.tar.gz
https://bitbucket.org/mpapis/rvm/get/.tar.gz
Otherwise, installs from:
https://github.com//rvm/archive/.tar.gz
[/]
Installs the branch from one of the following:
https://github.com/rvm/rvm/archive/.tar.gz
https://bitbucket.org/mpapis/rvm/get/.tar.gz
[--]source
[root@master ~]# chmod +x abc.sh
[root@master ~]# ./abc.sh
Downloading https://github.com/rvm/rvm/archive/master.tar.gz
Creating group 'rvm'
Installing RVM to /usr/local/rvm/
Installation of RVM in /usr/local/rvm/ is almost complete:
* First you need to add all users that will be using rvm to 'rvm' group,
and logout - login again, anyone using rvm will be operating with `umask u=rwx,g=rwx,o=rx`.
* To start using RVM you need to run `source /etc/profile.d/rvm.sh`
in all your open shell windows, in rare cases you need to reopen all shell windows.
* Please do NOT forget to add your users to the rvm group.
The installer no longer auto-adds root or users to the rvm group. Admins must do this.
Also, please note that group memberships are ONLY evaluated at login time.
This means that users must log out then back in before group membership takes effect!
Thanks for installing RVM
Please consider donating to our open collective to help us maintain RVM.
Donate: https://opencollective.com/rvm/donate
4、执行环境变量
source /etc/profile.d/rvm.sh
5、列出ruby可以安装的版本
[root@master ~]# rvm list known
Warning, new version of rvm available '1.29.9', you are using older version '1.29.9-next'.
You can disable this warning with: echo rvm_autoupdate_flag=0 >> ~/.rvmrc
You can enable auto-update with: echo rvm_autoupdate_flag=2 >> ~/.rvmrc
You can update manually with: rvm get VERSION (e.g. 'rvm get stable')
# MRI Rubies
[ruby-]1.8.6[-p420]
[ruby-]1.8.7[-head] # security released on head
[ruby-]1.9.1[-p431]
[ruby-]1.9.2[-p330]
[ruby-]1.9.3[-p551]
[ruby-]2.0.0[-p648]
[ruby-]2.1[.10]
[ruby-]2.2[.10]
[ruby-]2.3[.8]
[ruby-]2.4[.9]
[ruby-]2.5[.7]
[ruby-]2.6[.5]
[ruby-]2.7[.0-preview3]
ruby-head
# for forks use: rvm install ruby-head-
# JRuby
jruby-1.6[.8]
jruby-1.7[.27]
jruby-9.1[.17.0]
jruby[-9.2.9.0]
jruby-head
# Rubinius
rbx-1[.4.3]
rbx-2.3[.0]
rbx-2.4[.1]
rbx-2[.5.8]
rbx-3[.107]
rbx-4[.7]
rbx-head
# TruffleRuby
truffleruby[-19.3.0]
# Opal
opal
# Minimalistic ruby implementation - ISO 30170:2012
mruby-1.0.0
mruby-1.1.0
mruby-1.2.0
mruby-1.3.0
mruby-1[.4.1]
mruby-2.0.1
mruby-2[.1.0]
mruby[-head]
# Ruby Enterprise Edition
ree-1.8.6
ree[-1.8.7][-2012.02]
# Topaz
topaz
# MagLev
maglev-1.0.0
maglev-1.1[RC1]
maglev[-1.2Alpha4]
maglev-head
# Mac OS X Snow Leopard Or Newer
macruby-0.10
macruby-0.11
macruby[-0.12]
macruby-nightly
macruby-head
# IronRuby
ironruby[-1.1.3]
ironruby-head
6、安装Ruby2.4.1版本
[root@master ~]# rvm install 2.4.1
7、使用Ruby2.4.1版本
[root@192 ~]# rvm use 2.4.1
Using /usr/local/rvm/gems/ruby-2.4.1
8、再次安装Redis
[root@192 ~]# gem install redis
Fetching redis-4.1.3.gem
Successfully installed redis-4.1.3
Parsing documentation for redis-4.1.3
Installing ri documentation for redis-4.1.3
Done installing documentation for redis after 2 seconds
1 gem installed
9、每台服务器上都再添加两块网卡
(1)主服务器上
[root@192 ~]# service network restart //重启网卡
Restarting network (via systemctl): [ 确定 ]
[root@192 ~]# ifconfig //查看IP地址
ens33: flags=4163
inet 192.168.35.142 netmask 255.255.255.0 broadcast 192.168.35.255
inet6 fe80::d4e2:ef9e:6820:145a prefixlen 64 scopeid 0x20
ether 00:0c:29:01:82:fd txqueuelen 1000 (Ethernet)
RX packets 485360 bytes 146260201 (139.4 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 572433 bytes 68275761 (65.1 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ens36: flags=4163
inet 192.168.35.172 netmask 255.255.255.0 broadcast 192.168.35.255
inet6 fe80::4491:a202:f26f:fade prefixlen 64 scopeid 0x20
ether 00:0c:29:01:82:07 txqueuelen 1000 (Ethernet)
RX packets 153 bytes 21058 (20.5 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 29 bytes 4629 (4.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ens37: flags=4163
inet 192.168.35.173 netmask 255.255.255.0 broadcast 192.168.35.255
inet6 fe80::587f:2d4a:6019:27e9 prefixlen 64 scopeid 0x20
ether 00:0c:29:01:82:11 txqueuelen 1000 (Ethernet)
RX packets 295 bytes 33091 (32.3 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 231 bytes 30828 (30.1 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10
loop txqueuelen 1 (Local Loopback)
RX packets 98 bytes 7964 (7.7 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 98 bytes 7964 (7.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4099
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:14:39:99 txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
(2)从服务器上
[root@master ~]# service network restart
Restarting network (via systemctl): [ 确定 ]
[root@master ~]# ifconfig
ens33: flags=4163
inet 192.168.35.149 netmask 255.255.255.0 broadcast 192.168.35.255
inet6 fe80::b81a:9df:a960:45ac prefixlen 64 scopeid 0x20
ether 00:0c:29:92:6b:52 txqueuelen 1000 (Ethernet)
RX packets 594051 bytes 165651737 (157.9 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 707747 bytes 84935411 (81.0 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ens36: flags=4163
inet 192.168.35.135 netmask 255.255.255.0 broadcast 192.168.35.255
inet6 fe80::cc8d:9d04:c0df:3210 prefixlen 64 scopeid 0x20
ether 00:0c:29:92:6b:5c txqueuelen 1000 (Ethernet)
RX packets 1110 bytes 117822 (115.0 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 228 bytes 33104 (32.3 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
ens37: flags=4163
inet 192.168.35.174 netmask 255.255.255.0 broadcast 192.168.35.255
inet6 fe80::5c1b:c8a6:1115:4edc prefixlen 64 scopeid 0x20
ether 00:0c:29:92:6b:66 txqueuelen 1000 (Ethernet)
RX packets 169 bytes 18748 (18.3 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 30 bytes 4744 (4.6 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10
loop txqueuelen 1 (Local Loopback)
RX packets 86 bytes 6920 (6.7 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 86 bytes 6920 (6.7 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4099
inet 192.168.122.1 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:26:50:cb txqueuelen 1000 (Ethernet)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
规划:
master(主)
192.168.35.142
192.168.35.172
192.168.35.173
slave(从)
192.168.35.149
192.168.35.135
192.168.35.174
9、创建集群
redis-cli --cluster create 192.168.35.142:6379 192.168.35.172:6379 192.168.35.173:6379 192.168.35.149:6379 192.168.35.135:6379 192.168.35.174:6379 --cluster-replicas 1
>>> Performing hash slots allocation on 6 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica 192.168.35.135:6379 to 192.168.35.142:6379
Adding replica 192.168.35.174:6379 to 192.168.35.172:6379
Adding replica 192.168.35.149:6379 to 192.168.35.173:6379
M: 1251e787ecacee2fd0f1a1941216ffb29eb46e2b 192.168.35.142:6379
slots:[0-5460] (5461 slots) master
M: 1251e787ecacee2fd0f1a1941216ffb29eb46e2b 192.168.35.172:6379
slots:[5461-10922] (5462 slots) master
M: 1251e787ecacee2fd0f1a1941216ffb29eb46e2b 192.168.35.173:6379
slots:[10923-16383] (5461 slots) master
S: a6e5c8e120877501cf7443200f8a8fad55b2f8f2 192.168.35.149:6379
replicates 1251e787ecacee2fd0f1a1941216ffb29eb46e2b
S: a6e5c8e120877501cf7443200f8a8fad55b2f8f2 192.168.35.135:6379
replicates 1251e787ecacee2fd0f1a1941216ffb29eb46e2b
S: a6e5c8e120877501cf7443200f8a8fad55b2f8f2 192.168.35.174:6379
replicates 1251e787ecacee2fd0f1a1941216ffb29eb46e2b
Can I set the above configuration? (type 'yes' to accept): yes
>>> Nodes configuration updated
>>> Assign a different config epoch to each node
>>> Sending CLUSTER MEET messages to join the cluster
Waiting for the cluster to join
>>> Performing Cluster Check (using node 192.168.35.142:6379)
M: 1251e787ecacee2fd0f1a1941216ffb29eb46e2b 192.168.35.142:6379
slots:[0-16383] (16384 slots) master
1 additional replica(s)
S: a6e5c8e120877501cf7443200f8a8fad55b2f8f2 192.168.35.135:6379
slots: (0 slots) slave
replicates 1251e787ecacee2fd0f1a1941216ffb29eb46e2b
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
10、验证
(1)从主节点计入数据库写数据
[root@localhost ~]# redis-cli -h 192.168.35.142 -p 6379
192.168.35.142:6379> set age 20
OK
192.168.35.142:6379> get age
"20"
(2)从另一节点查看数据信息
[root@localhost ~]# redis-cli -h 192.168.35.172 -p 6379
192.168.35.172:6379> keys *
1) "age"
192.168.35.172:6379> get age
"20"
(3)再从另一节点查看数据信息
[root@localhost ~]# redis-cli -h 192.168.35.173 -p 6379
192.168.35.173:6379> keys *
1) "age"
192.168.35.173:6379> get age
"20"