docker内安装软件
- 安装nginx
拉取镜像
拉取镜像docker pull nginx
创建挂载目录mkdir -p /home/nginx/conf
mkdir -p /home/nginx/log
mkdir -p /home/nginx/html
生成容器docker run --name nginx -p 9001:80 -d nginx
将容器nginx.conf文件复制到宿主机docker cp nginx:/etc/nginx/nginx.conf /home/nginx/conf/nginx.conf
将容器conf.d文件夹下内容复制到宿主机docker cp nginx:/etc/nginx/conf.d /home/nginx/conf/conf.d
将容器中的html文件夹复制到宿主机docker cp nginx:/usr/share/nginx/html /home/nginx/
Docker 创建Nginx容器docker run -p 80:80 -p 443:443 --name nginx -v /home/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v /home/nginx/conf/conf.d:/etc/nginx/conf.d -v /home/nginx/log:/var/log/nginx -v /home/nginx/html:/usr/share/nginx/html --restart=always -d nginx:latest
- 安装PostgreSQL
拉取镜像docker pull postgres
创建挂载目录mkdir -p /home/postgresql/data
创建容器docker run --name postgresql --privileged -e POSTGRES_PASSWORD='XXXXXX' -p 5432:5432 -v /home/postgresql/data:/var/lib/postgresql/data --restart=always -d postgres
- 安装Sql server
拉取镜像
docker pull mcr.microsoft.com/mssql/server:2022-latest
创建容器
docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=RF@831017" -p 1400:1433 --name sql-server2022 -h sql-server2022 --restart=always -d mcr.microsoft.com/mssql/server:2022-latest
- 安装Redis
拉取镜像docker pull redis
redis配置目录创建与设置mkdir -p /home/redis/conf
touch /home/redis/conf/redis.conf
echo "appendonly yes" >> /home/redis/conf/redis.conf
创建容器docker run -p 6379:6379 --name redis -v /home/redis/data:/data -v /home/redis/conf/redis.conf:/etc/redis/redis.conf -e REDIS_PASSWORD=yourpassword --restart=always -d redis
- 安装RabbitMQ
拉取镜像docker pull rabbitmq
创建容器docker run --restart=always -d --hostname nyuwa-rabbit --name rabbit -p 15672:15672 -p 5672:5672 rabbitmq
进入容器docker exec -it rabbit /bin/bash
安装管理插件rabbitmq-plugins enable rabbitmq_management
安装延时队列插件
下载rabbitmq_delayed_message_exchange
下载地址:https://www.rabbitmq.com/community-plugins.html
docker cp rabbitmq_delayed_message_exchange-3.12.0.ez rabbit:/plugins
docker exec -it rabbit /bin/bash
rabbitmq-plugins enable rabbitmq_delayed_message_exchange
docker restart rabbit
- 安装Consul
拉取镜像docker pull hashicorp/consul
创建容器docker run -d -p 8500:8500 -p 8600:8600/udp -v /home/consul/data:/consul/data -v /home/consul/config:/consul/config --restart=always --name=consul hashicorp/consul agent -server -ui -node=server-1 -bootstrap-expect=1 -client=0.0.0.0
开启ACL
在/home/consul/config目录下创建acl.json文件
{
"acl": {
"enabled": true,
"default_policy": "deny",
"enable_token_persistence": true,
"tokens": {
"master": "00000000-0000-0000-0000-000000000000"
}
}
}
把00000000-0000-0000-0000-000000000000换成自己创建的GUID,重启consul容器。
也可以创建配置文件
server = true,
ui_config = {
enabled = true
},
bootstrap_expect = 3,
data_dir = "/consul/data",
datacenter = "dc1",
primary_datacenter= "dc1",
node_name = "node1_feng",
client_addr = "0.0.0.0",
bind_addr = "0.0.0.0",
start_join = ["1.140.130.11"],
acl = {
enabled = true
default_policy = "deny"
down_policy = "extend-cache"
enable_token_persistence = true
tokens{
master = "7ccf8dcf-770b-44bc-a3bd-ee7d07df1b86"
}
}
docker run -d -p 8500:8500 -p 8300:8300 -p 8301:8301 -p 8302:8302 -p 8600:8600/udp -v /home/consul/data:/consul/data -v /home/consul/config:/consul/config --restart=always --name=consul hashicorp/consul agent -config-file=/consul/config/agent.hcl -advertise=0.0.0.0
-advertise=0.0.0.0换成公网ip
在Policies新建Policy
服务发现策略
node_prefix "" {
policy = "read"
}
service_prefix "" {
policy = "read"
}
# 安全性低, 所有节点和服务名都可以暴露,基本等同于Master Token
node_prefix "" { policy = "read" }
service_prefix "" { policy = "read" }
# 仅开放相关node和service的可读权限
node "xxxxx" { policy = "read" }
service "xxxxx" { policy = "read" }
服务注册策略
service_prefix "" {
policy = "write"
}
配置读取策略
key_prefix "" {
policy = "read"
}
配置写入策略
key_prefix "" {
policy = "write"
}