一、nginx
#--------------------------------------------------------------------- # 小衍2.0 nginx 部署 #--------------------------------------------------------------------- 1、生成过渡容器用于复制文件到宿主机 拷贝 /opt/ng 整个目录 nginx.conf已经跟实际目录及文件匹配,如更改目录路径需同时更改nginx.conf文件 ------------------------------------------------------------------------- 2、运行容器:无代理 docker run -itd -e TZ="Asia/Shanghai" --restart=always \ --log-opt max-size=10m --log-opt max-file=3 \ --network host \ --name ng \ -v /opt/ng/conf/nginx.conf:/etc/nginx/nginx.conf \ -v /opt/ng/conf/conf.d:/etc/nginx/conf.d \ -v /opt/ng/log:/var/log/nginx \ -v /opt/ng/html:/usr/share/nginx/html \ -d nginx:latest ------------------------------------------------------------------------- 3、运行容器:有代理 docker run -itd -e TZ="Asia/Shanghai" --restart=always \ --log-opt max-size=10m --log-opt max-file=3 \ -p 9080:80 \ -p 9443:443 \ --name ng \ -v /opt/ng/conf/nginx.conf:/etc/nginx/nginx.conf \ -v /opt/ng/conf/conf.d:/etc/nginx/conf.d \ -v /opt/ng/log:/var/log/nginx \ -v /opt/ng/html:/usr/share/nginx/html \ -d nginx:latest -------------------------------------------------------------------------------
二、pg
************************在用20230207更新************************** -------特别关注:FATAL ERROR 是因为外网的恶意扫描导致------- 1、新建目录,过程注意确认目录pg及其子目录权限为1001: mkdir -p /opt/pg/data mkdir -p /opt/pg/conf.rep mkdir -p /opt/pg/conf.pg mkdir -p /opt/pg/conf.d chown -R 1001:1001 /opt/pg [root@pg-0 /]# ll /root/pg total 0 drwxr-xr-x 5 1001 1001 42 Dec 12 19:53 pg_0_data 2、6台ECS依次建立目录和添加IP与主机名对应关系,实质为修改/etc/host文件: hostnamectl set-hostname pg-6 echo '172.16.242.173 pg-1' >> /etc/hosts echo '172.16.93.160 pg-2' >> /etc/hosts echo '172.16.101.89 pg-3' >> /etc/hosts echo '172.16.93.161 pg-4' >> /etc/hosts echo '172.16.101.90 pg-5' >> /etc/hosts echo '172.16.242.172 pg-6' >> /etc/hosts hostnamectl set-hostname pg-1 hostnamectl set-hostname pg-2 hostnamectl set-hostname pg-3 hostnamectl set-hostname pg-4 hostnamectl set-hostname pg-5 hostnamectl set-hostname pg-6 3、运行pg(必须映射4个文件夹) docker run -detach --restart always --name pg \ --log-opt max-size=10m --log-opt max-file=3 \ --net=host \ --env REPMGR_PARTNER_NODES=pg-1,pg-2,pg-3,pg-4,pg-5,pg-6 \ --env REPMGR_NODE_NAME=pg-1 \ --env REPMGR_NODE_NETWORK_NAME=pg-1 \ --env REPMGR_PRIMARY_HOST=pg-1 \ --env REPMGR_PASSWORD=\ --env POSTGRESQL_POSTGRES_PASSWORD=\ --env POSTGRESQL_USERNAME=x*y* \ --env POSTGRESQL_PASSWORD=\ --env POSTGRESQL_DATABASE=t* \ -v /opt/pg/data:/bitnami/postgresql/ \ -v /opt/pg/conf.rep/:/opt/bitnami/repmgr/conf/ \ -v /opt/pg/conf.pg/:/opt/bitnami/postgresql/conf/ \ -v /opt/pg/conf.d/:/opt/bitnami/postgresql/conf/conf.d/ \ bitnami/postgresql-repmgr:latest docker ps docker run -detach --restart always --name pg \ --log-opt max-size=10m --log-opt max-file=3 \ --net=host \ --env REPMGR_PARTNER_NODES=pg-1,pg-2,pg-3,pg-4,pg-5,pg-6 \ --env REPMGR_NODE_NAME=pg-6 \ --env REPMGR_NODE_NETWORK_NAME=pg-6 \ --env REPMGR_PRIMARY_HOST=pg-1 \ --env REPMGR_PASSWORD=\ --env POSTGRESQL_POSTGRES_PASSWORD=\ --env POSTGRESQL_USERNAME=x*y* \ --env POSTGRESQL_PASSWORD=\ --env POSTGRESQL_DATABASE=t* \ -v /opt/pg/data:/bitnami/postgresql/ \ -v /opt/pg/conf.rep/:/opt/bitnami/repmgr/conf/ \ -v /opt/pg/conf.pg/:/opt/bitnami/postgresql/conf/ \ -v /opt/pg/conf.d/:/opt/bitnami/postgresql/conf/conf.d/ \ bitnami/postgresql-repmgr:latest docker ps 4、运行pgpool 注:生成pgpool之前需要先 pg数据库中新建用户:x*y* docker exec -it pg /bin/bash psql -U postgres postgres-# CREATE USER x*y* WITH PASSWORD 'E***9'; docker run -detach --restart always --name pgpool \ --log-opt max-size=10m --log-opt max-file=3 \ --env PGPOOL_BACKEND_NODES=0:pg-1:5432,1:pg-2:5432,2:pg-3:5432,3:pg-4:5432,4:pg-5:5432,5:pg-6:5432 \ --env PGPOOL_SR_CHECK_USER=x*y* \ --env PGPOOL_SR_CHECK_PASSWORD=\ --env PGPOOL_ENABLE_LDAP=no \ --env PGPOOL_POSTGRES_USERNAME=postgres \ --env PGPOOL_POSTGRES_PASSWORD=\ --env PGPOOL_ADMIN_USERNAME=admin \ --env PGPOOL_ADMIN_PASSWORD=\ --add-host=pg-1:172.16.242.173 \ --add-host=pg-2:172.16.93.160 \ --add-host=pg-3:172.16.101.89 \ --add-host=pg-4:172.16.93.161 \ --add-host=pg-5:172.16.101.90 \ --add-host=pg-6:172.16.242.172 \ -p 9999:5432 \ bitnami/pgpool:latest docker ps docker logs -f pgpool 5、pg数据备份 进入pg docker: docker exec -it pg /bin/bash 转到映射目录: cd /bitnami/postgresql 执行bash命令备份数据库t*: pg_dump -U postgres -d t* -f dump0206.sql 在映射目录/opt/pg/data中可以看到备份文件:dump0206.sql 6、pg数据恢复 将备份文件dump20230206.sql拷贝到在容器外映射目录:/opt/pg/data 进入pg docker: docker exec -it pg /bin/bash 在docker内,从bash命令转到psql命令状态: psql -U postgres 然后输入密码 新建立数据库t*: postgres=# CREATE DATABASE t*; 退出psql,回到bash界面: postgres=# \q 转到容器内映射目录,目录有备份文件:dump0206.sql cd /bitnami/postgresql 将恢复写入数据库,在bash命令界面: psql -d t* -U postgres -f dump0206.sql 7、pg常用操作 docker logs -f pg docker logs -f pgpool docker exec -it pg /bin/bash docker exec -it pgpool /bin/bash 使用指定用户和IP端口登陆pg: psql -h 172.16.227.246 -p 5432 -U postgres -W 各种操作命令 postgres-# h 数据操作帮助 postgres-# ? 常用命令帮助 postgres=# \l 列出数据库 postgres=# \du 列出用户 postgres-# CREATE USER x*y* WITH PASSWORD 'E***'; 新建用户 postgres=# \q 从psql命令状态返回bash命令状态 postgres=# \c ttlock 切换到t*数据库 postgres=# \d 查看当前schema中所有的表 # 1、centos下客户端进入:(需要安装psql客户端软件) psql -h pg-0 -U postgres postgres=# CREATE DATABASE t*; #新建用户 docker stop pgpool docker start pgpool docker logs -f pgpool docker stop pgpool docker rm pgpool docker stop pg docker rm pg
三、redis cluster
#--------------------------------------------------------------------- # 小衍2.0 redis cluster部署 #--------------------------------------------------------------------- 生成master容器: docker run -itd -e TZ="Asia/Shanghai" --restart=always \ --log-opt max-size=10m --log-opt max-file=3 \ --name rs \ --net host \ -v /opt/rs:/data \ redis:6.0 --cluster-enabled yes --cluster-config-file rs.conf --requirepass "E**" --appendonly yes --port 6379 进入容器bash: docker exec -it rs /bin/bash 建立集群: redis-cli -a E**** --cluster create 172.16.227.246:6379 172.16.227.236:6379 172.16.227.216:6379 --cluster-replicas 0 查看集群全部节点: cluster nodes 1aecce3f10c44b51cbae1af8b53027c07d9a71f3 172.16.227.216:6379@16379 master 3 connected 10923-16383 3c0bda76ddd448628e99dc4c0313a9f42060c2ea 172.16.227.236:6379@16379 master 2 connected 5461-10922 46fc1cf0ba490661f1ea137c6f10d22598c79283 172.16.227.246:6379@16379 master 1 connected 0-5460 为主节点挂上从节点: ------------------------------------------------------------------------------------------------- redis-cli -a E** --cluster add-node 172.16.242.172:6379 172.16.227.246:6379 --cluster-slave --cluster-master-id 46fc1cf0ba490661f1ea137c6f10d22598c79283 redis-cli -a E** --cluster add-node 172.16.101.90:6379 172.16.227.236:6379 --cluster-slave --cluster-master-id 3c0bda76ddd448628e99dc4c0313a9f42060c2ea redis-cli -a E** --cluster add-node 172.16.101.89:6379 172.16.227.216:6379 --cluster-slave --cluster-master-id 1aecce3f10c44b51cbae1af8b53027c07d9a71f3 说明:把6382节点加入到6379节点的集群中,并且当做node_id为 117457eab5071954faab5e81c3170600d5192270 的从节点。如果不指定 --cluster-master-id 会随机分配到任意一个主节点。 ------------------------------------------------------------------------------------------------- 删除节点: redis-cli -a E** --cluster del-node 172.16.242.173:6379 96dc749c9bdc0903aa241551cb8edeef63a3a975 redis-cli -a E** --cluster del-node 172.16.101.89:6379 1329f9745241783328c47e09b6f89128825a2f01 redis-cli -a E** --cluster del-node 172.16.93.160:6379 cbd67d58d9a31b17ec20e280867b7516239ea425 redis-cli -a E** --cluster del-node 172.16.242.172:6379 6ce24abafaa15c8df3e59bea9269ef01dc5f15f1 redis-cli -a E** --cluster del-node 172.16.101.90:6379 60f2a8a88417f743c1bd81f13804218ae01ecd79 redis-cli -a E** --cluster del-node 172.16.93.161:6379 6a3ec0294f278acac8cb4a33622971760a96415e 查看集群主节点: redis-cli -a E** --cluster info 172.16.227.246:6379 redis-cli -a E** --cluster info 172.16.227.236:6379 redis-cli -a E** --cluster info 172.16.227.216:6379 从容器bash进入redis数据库命令状态: redis-cli -a E** 直接进入redis数据库命令状态: docker exec -it rs redis-cli -a E** 选择连接的redis ip和端口: redis-cli -h 127.0.0.1 -p 6379 输入 auth [redis密码] 查找key: keys [key规则] 删除key: del [key] docker ps docker logs -f rs docker stop rs docker rm rs cd /opt rm -rf rs docker ps ll
标签:opt,部署,172.16,--,pg,conf,2023,docker,2.0 From: https://www.cnblogs.com/pearlcity/p/17107343.html