1.2 redis

day07笔记 Linux

推荐的歌: 浪子回头

去年回顾

mariadb
1.yum安装
yum install mariadb-server mariadb -y
2.yum安装好之后,启动服务端,只有通过yum安装的软件才可以用systemctl
systemctl start mariadb
3.数据库初始化
4.mysql -uroot -p

redis
1.源码包安装redis
2.指定了/opt/redis/工作目录
3.启动redis服务端
redis-server redis.conf
4.redis.conf软件的配置文件作用?
给这个软件,指定开放/关闭一些功能
改redis端口
改redis密码
redis的安全模式
bind参数,指定redis启动的ip地址

杀死redis服务的方法
1.kill pid
2.pkill redis-server 根据服务名 杀死进程,可以杀死所有有关redis-server

1.在linux服务器上安装软件
分好几种:
-yum安装
-配置yum源,配置163,清华,阿里云的yum源
-清空yum缓存
-生成新的yum缓存
-源码安装
-下载软件的源码压缩包
-解压缩,切换目录
-释放makefile,编译,编译安装
-rpm软件包安装

远程连接工具 xshell( ssh root@ip )
mac同学 ssh root@ip

今年所学

redis发布订阅

三个角色,提供的redis命令
1.发布者
publish 频道 消息 给频道发消息
2.订阅者
SUBSCRIBE 频道 订阅频道
PSUBSCRIBE 频道* 支持模糊匹配的订阅
3.频道
channel 频道名 自定义

redis持久化之RDB
1.在配置文件中添加参数,开启rdb功能
redis.conf 写入
port 6379
daemonize yes
logfile /data/6379/redis.log
dir /data/6379
dbfilename s15.rdb
save 900 1 #rdb机制 每900秒 有1个修>改记录
save 300 10 #每300秒 10个修改
记录
save 60 10000 #每60秒内 10000修>改记录
2.开启redis服务端,测试rdb功能
redis-server redis.conf

redis持久化之aof
1.开启aof功能,在redis.conf中添加参数
port 6379
daemonize yes
logfile /data/6379/redis.log
dir /data/6379
appendonly yes
appendfsync everysec
2.启动redis服务端,指定aof功能,测试持久化数据

redis不重启之rdb数据切换到aof数据
1.准备rdb的redis服务端
redis-server s15-redis.conf (注明这是在rdb持久化模式下)

2.切换rdb到aof
redis-cli 登录redis,然后通过命令,激活aof持久化
127.0.0.1:6379> CONFIG set appendonly yes #用命令激活aof持久化(临时生效,注意写入到配置文件)
OK
127.0.0.1:6379>
127.0.0.1:6379>
127.0.0.1:6379> CONFIG SET save "" #关闭rdb持久化

2.5 将aof操作,写入到配置文件,永久生效,下次重启后生效
port 6379
daemonize yes
logfile /data/6379/redis.log
dir /data/6379

#dbfilename   s15.rdb
#save 900 1  
#save 300 10 
#save 60  10000 
appendonly yes
appendfsync everysec

3.测试aof数据持久化 ,杀掉redis,重新启动
kill
redis-server s15-redis.conf

4.写入数据,检查aof文件

redis的主从同步

1.检查redis数据库信息,主从状态的命令
redis-cli -p 6379 info 检查数据库信息
redis-cli -p 6379 info replication 检查数据库主从信息

1.准备三个redis配置文件,通过端口的区分,启动三个redis数据库实例,然后配置主从复制
redis-6379.conf
port 6379
daemonize yes
pidfile /data/6379/redis.pid
loglevel notice
logfile "/data/6379/redis.log"
dbfilename dump.rdb
dir /data/6379

redis-6380.conf

通过命令快速生成配置文件

sed "s/6379/6380/g" redis-6379.conf > redis-6380.conf
slaveof 127.0.0.1 6379 #指明主库的身份ip 和端口

redis-6381.conf

通过命令快速生成配置文件

sed "s/6379/6381/g" redis-6379.conf > redis-6381.conf
slaveof 127.0.0.1 6379

2.启动三个数据库实例,检测redis主从同步方案

3.redis主从赋值,故障手动切换,
1.杀死6379的主库实例
kill 主库

2.手动切换主从身份
    1.登录 redis-6380 ,通过命令,去掉自己的从库身份,等待连接
        slaoveof no one  
    2.登录redis-6381 ,通过命令,生成新的主任
        slaveof 127.0.0.1 6380  

3.测试新的主从数据同步

redis哨兵
1.什么是哨兵呢?保护redis主从集群,正常运转,当主库挂掉之后,自动的在从库中挑选新的主库,进行同步

2.redis哨兵的安装配置
1. 准备三个redis数据库实例(三个配置文件,通过端口区分)
[root@localhost redis-4.0.10]# redis-server redis-6379.conf
[root@localhost redis-4.0.10]# redis-server redis-6380.conf
[root@localhost redis-4.0.10]# redis-server redis-6381.conf
2.准备三个哨兵,准备三个哨兵的配置文件(仅仅是端口的不同26379,26380,26381)
-rw-r--r-- 1 root root 227 Jan 2 18:44 redis-sentinel-26379.conf
port 26379
dir /var/redis/data/
logfile "26379.log"

    sentinel monitor s15master 127.0.0.1 6379 2

    sentinel down-after-milliseconds s15master 30000

    sentinel parallel-syncs s15master 1

    sentinel failover-timeout s15master 180000
    daemonize yes


-rw-r--r--  1 root root    227 Jan  2 18:45 redis-sentinel-26380.conf
    快速生成配置文件
    sed "s/26379/26380/g" redis-sentinel-26379.conf >  redis-sentinel-26380.conf 
-rw-r--r--  1 root root    227 Jan  2 18:46 redis-sentinel-26381.conf
    sed "s/26379/26381/g" redis-sentinel-26379.conf >  redis-sentinel-26381.conf 

3.添加后台运行参数,使得三个哨兵进程,后台运行

[root@localhost redis-4.0.10]# echo "daemonize yes" >> redis-sentinel-26379.conf
[root@localhost redis-4.0.10]# echo "daemonize yes" >> redis-sentinel-26380.conf
[root@localhost redis-4.0.10]# echo "daemonize yes" >> redis-sentinel-26381.conf

4.启动三个哨兵
    1003  redis-sentinel redis-sentinel-26379.conf 
    1007  redis-sentinel redis-sentinel-26380.conf 
    1008  redis-sentinel redis-sentinel-26381.conf 
    
5.检查哨兵的通信状态
redis-cli -p 26379  info sentinel 
查看结果如下之后,表示哨兵正常
    [root@localhost redis-4.0.10]# redis-cli -p 26379  info sentinel 
    # Sentinel
    sentinel_masters:1
    sentinel_tilt:0
    sentinel_running_scripts:0
    sentinel_scripts_queue_length:0
    sentinel_simulate_failure_flags:0
    master0:name=s15master,status=ok,address=127.0.0.1:6381,slaves=2,sentinels=3

6.杀死一个redis主库,6379节点,等待30s以内,检查6380和6381的节点状态
kill 6379主节点
redis-cli -p 6380 info replication 
redis-cli -p 6381 info replication 
如果切换的主从身份之后,(原理就是更改redis的配置文件,切换主从身份)

7.恢复6379节点的数据库,查看是否将6379添加为新的slave身份

redis-cluster安装配置
1.准备6个redis数据库实例,准备6个配置文件redis-{7000....7005}配置文件
-rw-r--r-- 1 root root 151 Jan 2 19:26 redis-7000.conf
-rw-r--r-- 1 root root 151 Jan 2 19:27 redis-7001.conf
-rw-r--r-- 1 root root 151 Jan 2 19:27 redis-7002.conf
-rw-r--r-- 1 root root 151 Jan 2 19:27 redis-7003.conf
-rw-r--r-- 1 root root 151 Jan 2 19:27 redis-7004.conf
-rw-r--r-- 1 root root 151 Jan 2 19:27 redis-7005.conf

2.启动6个redis数据库实例
[root@localhost s15rediscluster]# redis-server redis-7000.conf
[root@localhost s15rediscluster]# redis-server redis-7001.conf
[root@localhost s15rediscluster]# redis-server redis-7002.conf
[root@localhost s15rediscluster]# redis-server redis-7003.conf
[root@localhost s15rediscluster]# redis-server redis-7004.conf
[root@localhost s15rediscluster]# redis-server redis-7005.conf

3.配置ruby语言环境,脚本一键启动redis-cluster
1.下载ruby语言的源码包,编译安装
wget https://cache.ruby-lang.org/pub/ruby/2.3/ruby-2.3.1.tar.gz
2.解压缩
./configure --prefix=/opt/ruby/ 释放makefile
make && make install 编译且安装
3.下载安装ruby操作redis的模块包
wget http://rubygems.org/downloads/redis-3.3.0.gem

4.配置ruby的环境变量
echo $PATH

vim /etc/profile
写入最底行
PATH=$PATH:/opt/ruby/bin/
读取文件
source /etc/profile 

5.通过ruby的包管理工具去安装redis包,安装后会生成一个redis-trib.rb这个命令
一键创建redis-cluster 其实就是分配主从关系 以及 槽位分配 slot槽位分配
/opt/redis-4.0.10/src/redis-trib.rb create --replicas 1 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005

6.检查节点主从状态
redis-cli -p 7000  info replication 

7.向redis集群写入数据,查看数据流向
redis-cli -p 7000    #这里会将key自动的重定向,放到某一个节点的slot槽位中
set  name  s15 
set  addr shahe  

nginx 入门学习

web服务器软件

windows
IIS服务器
linux
nginx

apache 收费

lighthttp 

公司的技术栈
收费版技术栈
apache web服务器 + java + tomcat应用服务器 + oracle + memcached + redhat 企业版linux + svn(代码管理工具)

开源的技术栈(路飞学城)
nginx(负载均衡) + python(virtualenv) +
uwsgi (python的应用服务器,启动了10个进程处理django drf 请求)

  • mysql (阿里云的rds主从复制)
    +redis的主从赋值
    +git
    +vue前端代码服务器
    +linux(阿里云的centos7)

curl -I 网站域名 可以查看网站的响应头信息 查看网站用了什么服务器

1.yum解决编译nginx所需的依赖包,之后你的nginx就不会报错了

yum install gcc patch libffi-devel python-devel  zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel openssl openssl-devel -y

2.安装配置nginx软件,下载源代码
wget -c https://nginx.org/download/nginx-1.12.0.tar.gz
3.解压缩源码,编译且安装
tar -zxvf nginx-1.12.0.tar.gz
切换源码目录
./configure --prefix=/opt/nginx112/
make && make install
4.进入nginx的工作目录
cd /opt/ngin112/

5.查看gninx的工作目录
[root@localhost nginx112]# ls
conf 配置文件目录
html 网页根目录,你的index.html就放在这里,然后通过域名访问 pythonav.cn/index.html html/index.html
logs 日志
sbin 存放nginx可执行命令的

6.定制自己的nginx网站
修改/opt/nginx112/html/index.html 这是nginx网页根文件,清空内容写入自己的html标签

7.启动nginx服务器
/opt/nginx112/sbin/nginx 直接回车执行

8.检查nginx服务端口
ps -ef|grep nginx

9.通过windows访问nginx web服务
浏览器 访问http://192.168.13.79

猜你喜欢

转载自www.cnblogs.com/zzy7372/p/10210848.html