1. 分布式redis部署笔记
配置文件
master节点配置 ```conf port 7001 daemonize yes protected-mode no
cluster-enabled yes
dir /opt/redis/7001
cluster-config-file nodes-7001.conf
pidfile /opt/redis/redis-7001.pid logfile /opt/redis/redis-7001.log appendonly yes bind 172.16.224.169 requirepass 123456 slave-read-only no node节点配置
conf
node 1
port 7002 daemonize yes protected-mode no
cluster-enabled yes
dir /opt/redis/7002 cluster-config-file nodes-7002.conf pidfile /opt/redis/redis-7002.pid logfile /opt/redis/redis-7002.log
appendonly yes
bind 172.16.224.169
replicaof 172.16.224.169 7001
slaveof 172.16.224.169 7001 masterauth 123456
node 2
port 7003 daemonize yes protected-mode no
cluster-enabled yes
dir /opt/redis/7003 cluster-config-file nodes-7003.conf pidfile /opt/redis/redis-7003.pid logfile /opt/redis/redis-7003.log appendonly yes bind 172.16.224.169 slaveof 172.16.224.169 7001 masterauth 123456
```
启动和关闭脚本
```bash
启动脚本 start.sh
./src/redis-server /opt/redis/7001/redis.conf & ./src/redis-server /opt/redis/7002/redis.conf & ./src/redis-server /opt/redis/7003/redis.conf &
./src/redis-server /opt/redis/7004/redis.conf &
关闭脚本 stop.sh
echo "正在关闭redis-server..." ps -ef | grep redis | grep -v grep | awk '{print $2}' | xargs kill -9 ps -ef |grep redis sleep echo "正在删除redis的nodes文件..." for ((i=7001;i<=7004;i++)) do rm -rf /opt/redis/${i}/nodes-${i}.conf rm -rf /opt/redis/${i}/dump.rdb rm -rf /opt/redis/${i}/appendonly.aof echo "删除700${i}目录下的nodes文件" done
```
2. docker相关
镜像源和启动相关
配置镜像位置
/etc/docker/daemon.json
具体配置如下所示
```json { "log-driver": "json-file", "log-opts": { "max-size": "512m", "max-file": "3" },"registry-mirrors": ["https://registry.docker-cn.com","https://hub.atomgit.com"] } ``` 目前国内镜像安全原因很多不能用,需要在网上随时寻找新的地址
- 修改启动
systemctl daemon-realod
systemctl restart docker
拉取镜像和启动服务(以mysql为例)
- 拉取镜像
docker pull msyql:5.7
版本根据需要拉取 - 查看镜像
docker images
- 启动镜像
docker run --name mysql -p 4399:3306 -e MYSQL_ROOT_PASSWORD='yourpassword' -d mysql:5.7
- --name 指定镜像启动名称
- -p 端口映射 4399服务器端口 3306容器端口
- -d 后台启动
- 修改密码和设置所有客户端可以连接的配置(默认值指定ip连接) ```bash
进入容器
docker ps
找到对于的 id
docker exec -it [CONTAINER ID] bash
访问数据库
mysql -u root -p
输入密码
修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new_password';
设置所有客户端可以访问 host 任意ip访问 也可以设置为指定ip访问 根据需求来
USE mysql; UPDATE user SET Host = '%' WHERE User = 'root';
设置指定ip访问
GRANT ALL PRIVILEGES ON . TO 'root'@'youripaddress' IDENTIFIED BY 'password' WITH GRANT OPTION;
多个ip重复执行上面这个操作 如何是连续的ip段可以用通配符 比如
GRANT ALL PRIVILEGES ON . TO 'root'@'192.168.1.%' IDENTIFIED BY 'password' WITH GRANT OPTION;
刷新
FLUSH PRIVILEGES;
退出mysql
exit
退出容器
exit ```