docker部署redis
【摘要】 一、安装docker1、把yum源更新[root@localhost ~]# yum update -y2、下载docker一些依赖包[root@localhost ~]# yum install -y yum-utils device-mapper-persistent-data lvm23、把docker官方源下载下来[root@localhost ~]# yum-config-mana...
一、安装docker
1、把yum源更新
[root@localhost ~]# yum update -y
2、下载docker一些依赖包
[root@localhost ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
3、把docker官方源下载下来
[root@localhost ~]# yum-config-manager \--add-repo \https://download.docker.com/linux/centos/docker-ce.repo ##docker官方源
yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo ##阿里源
4、安装docker
[root@localhost ~]# yum list docker-ce --showduplicates | sort -r && yum install docker-ce -y
5、重启 docker
[root@localhost ~]# systemctl restart docker
[root@localhost ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
拓展:
docker version |head -n2
docker version |head -n13 |tail -n3
#服务状态
docker status docker |head -n3
二、安装redis
1、查找reddis
[root@localhost ~]# docker search redis
2、安装reddis并修改配置文件重启 redis
[root@localhost ~]# docker pull redis ##pull redis
Using default tag: latest
latest: Pulling from library/redis
07aded7c29c6: Pull complete
1a5d64c027a4: Pull complete
189d72810950: Pull complete
b85aac102f7d: Pull complete
fe1bca69301e: Pull complete
fd69789c2b06: Pull complete
Digest: sha256:c98f0230b5f1831f4f5dd764c4ea8ef11d3e3a1a3593278eb952373d97c82b27
Status: Downloaded newer image for redis:latest
docker.io/library/redis:latest
[root@localhost ~]# docker images ##查看镜像列表
mkdir /usr/local/docker
REPOSITORY TAG IMAGE ID CREATED SIZE
redis latest 5d89766432d0 6 days ago 105MB
cd /usr/local/docker
[root@localhost ~]#
[root@localhost ~]# mkdir /usr/local/docker
[root@localhost ~]# cd /usr/local/docker
[root@localhost docker]# yum -y install wget
[root@localhost docker]#wget http://download.redis.io/redis-stable/redis.conf ##下载配置文件
[root@localhost docker]#sed -i 's/bind127.0.0.1/#bind127.0.0.1/g' /usr/local/docker/redis.conf && sed -i 's/protected-mode yes/protected-mode no/g' /usr/local/docker/redis.conf ##修改配置文件
sed -i 's/^#requirepass.*/requirepass Huawei@123/g' redis.conf #密码设置为Huawei@123
[root@localhost docker]#docker run -itd -p 6379:6379 --name redis-test -v /usr/local/docker/redis.conf:/etc/redis/redis.conf -v /usr/local/docker/data:/data redis redis-server /etc/redis/redis.conf ##配置文件加入到docker里面
[root@localhost docker]# docker start redis-test ##重启docker
[root@localhost docker]# docker exec -it redis-test bash ##进入redis
root@326ac72d2228:/data# redis-cli -h 192.168.73.182 -p 6379 -a Huawei@123 ##远程登陆redis
192.168.73.182:6379> ping
PONG
192.168.73.182:6379>
网站利用redis进行缓存服务
修改配置文件
[root@node1 config]# ll
total 32
-rwxrwxrwx 1 root root 8868 Oct 9 10:21 config_global_default.php
-rw-r--r-- 1 apache apache 4615 Oct 9 12:57 config_global.php
-rwxrwxrwx 1 root root 1663 Oct 9 10:21 config_ucenter_default.php
-rw-r--r-- 1 apache apache 539 Oct 9 10:23 config_ucenter.php
-rwxrwxrwx 1 root root 1 Oct 9 10:21 index.htm
[root@node1 config]# pwd
/var/www/html/config
[root@node1 config]# vim config_global.php
18 $_config['memory']['prefix'] = 'oh0Ztl_';
20 $_config['memory']['redis']['server'] = '192.168.30.56'; ##redis主机ip
21 $_config['memory']['redis']['port'] = 6379;
22 $_config['memory']['redis']['pconnect'] = 1;
23 $_config['memory']['redis']['timeout'] = '0';
24 $_config['memory']['redis']['requirepass'] = '123456'; ##设置的密码
25 $_config['memory']['redis']['serializer'] = 1;
26 $_config['memory']['redis']['db'] = 1;
[root@node1 config]# systemctl restart httpd
[root@node1 config]#
[root@node1 config]# yum -y install php-devel
[root@node1 config]# yum -y install gcc make
[root@node1 config]# wget http://pecl.php.net/get/redis-4.3.0.tgz
[root@node1 config]# mv redis-4.3.0.tgz ..
[root@node1 config]#cd ..
[root@node1 html]# pwd
/var/www/html/
[root@node1 html]# tar -zxvf redis-4.3.0.tgz
[root@node1 html]# cd redis-4.3.0
[root@node1 html]# phpize
[root@node1 html]# ./configure --with-php-config=/bin/php-config ##配置phpredis环境变量
[root@node1 html]# make
[root@node1 html]#make install
[root@node1 html]#vim /etc/php.ini
extension="redis.so"
[root@node1 html]#systemctl restart php-fpm
[root@node1 html]#systemctl restart httpd
参考:https://www.php.cn/php-weizijiaocheng-392756.html
参考:https://github.com/redis/redis/blob/6.0/redis.conf
实用博客参考链接:
https://i4t.com/ ##一个大佬写的好东西
https://www.freesion.com/ ##虚拟化操作社区
https://www.kubernetes.org.cn/ #k8s中文社区
http://huangrukun.xyz/ #大黄的博客
https://www.cnblogs.com/Skybiubiu ##博客园
https://www.sysit.cn/blog/sysit ##运维笔记大佬
https://oldqiang.com/page/2 ##老男孩强哥
https://search.gitee.com/?skin=rec&type=repository&q=web%E6%9E%B6%E6%9E%84 ##gitt
https://www.oschina.net/project/tag/406/paas ##开源中国
https://www.myhomeabc.com/ ##使用浏览器
https://www.php.cn/course/list/3/type/99.html ##PHP中文网
https://www.liuyixiang.com/ ##小想的博客
https://www.server-world.info/en/note?os=CentOS_7&p=samba&f=1 ##服务器搭建
https://www.cnblogs.com/shenjianping/p/14697278.html ##nfs测试
https://blog.star-chen.com/ ##docker博客
https://forum.huawei.com/enterprise/zh/thread-689221.html ##华为官方论坛
【声明】本内容来自华为云开发者社区博主,不代表华为云及华为云开发者社区的观点和立场。转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息,否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)