首页 > 大数据 > 数据分析 > centos8安装和配置redis服务
操作系统:centos8.0
redis:6.0.7
安装redis:
官网获得redis6.0.7的安装包:redis-6.0.7.tar.gz,redis 官网:
centos8服务器上执行
tar -zxf redis-6.0.7.tar.gz
cd redis-6.0.7/
make
make PREFIX=/usr/local/redis install
cp redis.conf /usr/local/redis/
注意:这里redis被安装在目录/usr/local/redis下面,redis.conf我也拷贝到这个目录下面了,如果安装目录和配置文件目录不一样的话,下面做redis.service配置文件的时候调用路径会不一样。
配置redis服务和开机启动
1.修改redis.conf配置文件中的两项:
daemonize yes # 以后台守护进程方式启动
supervised systemd # 可以跟systemd进程进行交互
2.创建配置文件:/usr/lib/systemd/system/redis.service
# example systemd service unit file for redis-server # # In order to use this as a template for providing a redis service in your # environment, _at the very least_ make sure to adapt the redis configuration # file you intend to use as needed (make sure to set "supervised systemd"), and # to set sane TimeoutStartSec and TimeoutStopSec property values in the unit"s # "[Service]" section to fit your needs. # # Some properties, such as User= and Group=, are highly desirable for virtually # all deployments of redis, but cannot be provided in a manner that fits all # expectable environments. Some of these properties have been commented out in # this example service unit file, but you are highly encouraged to set them to # fit your needs. # # Please refer to systemd.unit(5), systemd.service(5), and systemd.exec(5) for # more information. [Unit] Description=Redis data structure server Documentation=documentation #Before=your_application.service another_example_application.service #AssertPathExists=/var/lib/redis [Service] #ExecStart=/usr/local/bin/redis-server --supervised systemd --daemonize yes ## Alternatively, have redis-server load a configuration file: ExecStart=/usr/local/bin/redis-server /usr/local/redis/redis.conf ExecStop=/usr/local/bin/redis-cli shutdown Restart=always LimitNOFILE=10032 NoNewPrivileges=yes #OOMScoreAdjust=-900 #PrivateTmp=yes #Type=notify # 注意 notify 会失败,换成 forking 方式启动,让主进程复制一个子进程的方式执行 Type=forking #TimeoutStartSec=100 #TimeoutStopSec=100 UMask=0077 #User=root #Group=root #WorkingDirectory=/var/lib/redis [Install] WantedBy=multi-user.target
3.执行指令:
systemctl enable redis
测试验证:
systemctl start redis
redis-cli -h 127.0.0.1 -p 6379
systemctl stop redis
redis-cli -h 127.0.0.1 -p 6379
重启服务器,再验证一下开机启动。
国内的话建议修改yum源为阿里云,修改方法参考: CentOS 8修改yum源为国内源;
1.添加EPEL仓库
在CentOS或Red Hat系统中,需要先添加EPEL仓库
#添加EPEL仓库sudo yum install epel-release#更新yum源sudo yum update
2.安装
yum install redis
3.启动
systemctl start redis
4.设置开机自启
systemctl enable redis
5.修改配置
打开
/etc/redis.conf
文件。
1)允许远程连接
找到下面这一行,注释掉:
bind 127.0.0.1
改为:
#bind 127.0.0.1
2)启用密码
找到
# requirepass foobared
一行,删除前面的
#
注释,然后将
foobared
改为你自己的密码。
requirepass your_password
6.开放端口
如果启用了防火墙,redis默认端口
6379
需要进行开放,开放端口参考:
CentOS开放端口的方法 。
sudo firewall-cmd --add-port=6379/tcp --permanent sudo firewall-cmd --reloadsystemctl restart redis
7.测试远程连接
telnet id 6379
能连接说明没问题。
集群
redis集群创建执行
./redis-trib.rb create --replicas 1 XXXX:PORT1 XXXX:PORT2 ....
注意:iptables 放开,如果有安全组,也要放开这两个端口
3 使用vim 编辑 /etc/profile ,在文件的末尾添加以下语句,
vi /etc/profile
#set redis-cli cluster
export REDIS_HOME=/usr/local/redis
export PATH=$PATH:$REDIS_HOME/bin
source /etc/profile
redis-cli --cluster help
create host1:port1 ... hostN:portN
--cluster-replicas <arg>
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/25469263/viewspace-2719248/,如需转载,请注明出处,否则将追究法律责任。