设置root密码

sudo passwd root
******

开启密码登录

vi /etc/ssh/sshd_config
...
PasswordAuthentication yes
PermitRootLogin yes
...

报存并退出vi重启sshd

sudo service sshd restart

安装docker

sudo yum -y install -y yum-utils
sudo yum-config-manager -y  --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo yum -y install docker

安装nginx

sudo yum -y install pcre-devel zlib-devel openssl openssl-devel
sudo yum -y install epel-release
sudo yum -y install nginx
sudo yum -y install nginx-all-modules.noarch

设置nginx自启动

systemctl enable nginx && systemctl start nginx

nginx配置

https配置

		ssl_certificate /mydata/nginx/keys/www.xuexibisai.com.pem;
        ssl_certificate_key /mydata/nginx/keys/www.xuexibisai.com.key;
        ssl_session_cache shared:SSL:1m;
        ssl_session_timeout  5m;
		ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
		ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
        ssl_prefer_server_ciphers on;

切记:有的网站下载pem文件问题,只有当前域名证书没有上级的证书,导致很多浏览器无法访问解决办法就是:把ca_bundle.crt内容全部复制追加certificate.crt后面,然后将crt转成pem文件openssl x509 -in ca.crt -out ca.pem -outform PEM

http集群

待续

tcp端口代理负载均衡

在nginx.conf文件最后加入

stream {
	upstream tcpBalance {
		server www.xuexibisai.com:9681 weight=5;
		server www.xuexibisai.com:9682 weight=5;
	}
	server {
		listen 9696;
		proxy_connect_timeout 20s;
		proxy_timeout 5m;
		proxy_pass tcpBalance;
	}
}

nginx打印post消息日志

log_format main escape=json '{ "@timestamp": "$time_iso8601", "remoteaddr": "$remote_addr", "costime": "$request_time", "realtime": "$upstream_response_time", "status": $status, "request": "$request", "dm": "$request_body" }';
access_log  /var/log/nginx/access.log  main;

安装docker

sudo yum -y install -y yum-utils
sudo yum-config-manager -y  --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum -y install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo yum -y install docker

设置docker自启动

systemctl enable docker && systemctl start docker

修改docker基础配置

vi /etc/docker/daemon.json
...
#镜像服务器
"registry-mirrors": ["https://bfkszez0.mirror.aliyuncs.com"],
#域名解析服务器
"dns": ["8.8.8.8"],
#日志配置
"log-driver":"json-file",
"log-opts":{"max-size":"1500m","max-file":"100"}
...

创建docker网关

作用容器可以在不知道宿主机ip的情况下使用192.168.0.1来访问宿主机

docker network create -d bridge --subnet 192.168.0.0/24 --gateway 192.168.0.1 mygateway

docker安装mysql

单机版本

docker run --restart=always -d -p 3306:3306 --privileged=true -v /mydata/mysql/log:/var/log/mysql -v /mydata/mysql/data:/var/lib/mysql -v /mydata/mysql/conf:/etc/mysql/conf.d -e MYSQL_ROOT_PASSWORD="123456" --name mysql mysql:5.7.15

主从版本

参考文章操作https://blog.csdn.net/u012643122/article/details/125899829

mysql安装特别注意点

有些docker的mysql镜像的my.cnf文件和my.cnf.d目录配置文件在/etc目录下,不在/etc/mysql目录下,对应命令需要修改
先在宿主机新建文件/mydata/mysql/conf/my.cnf,文件内容如下

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/8.0/en/server-configuration-defaults.html
[mysqld]
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
#
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed, experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M

# Remove leading # to revert to previous value for default_authentication_plugin,
# this will increase compatibility with older clients. For background, see:
# https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_default_authentication_plugin
# default-authentication-plugin=mysql_native_password
skip-host-cache
skip-name-resolve
datadir=/var/lib/mysql
socket=/var/run/mysqld/mysqld.sock
secure-file-priv=/var/lib/mysql-files
user=mysql

pid-file=/var/run/mysqld/mysqld.pid
[client]
socket=/var/run/mysqld/mysqld.sock

!includedir /etc/mysql/conf.d/

然后创建mysql容器

docker run --restart=always -d -p 3306:3306 --privileged=true -v /mydata/mysql/log:/var/log/mysql -v /mydata/mysql/data:/var/lib/mysql -v /mydata/mysql/conf/my.cnf:/etc/my.cnf -v /mydata/mysql/conf/my.cnf.d:/etc/my.cnf.d -e MYSQL_ROOT_PASSWORD="123456" --name mysql mysql:8.0

友情提示:my.cnf文件内容路径如何获取?可以创建一个挂载任何数据卷的mysql容器(docker run -d -p 3306:3306 --name mysql mysql:8.0),然后docker exec命令进入查看my.cnf到底在哪个路径,并使用docker cp命令将my.cnf文件拷贝到宿主机

docker安装redis

设置密码:

docker run --restart=always --log-opt max-size=100m --log-opt max-file=2 -p 6379:6379 --name redis -v /mydata/redis/redis.conf:/etc/redis/redis.conf -v /mydata/redis/data:/data -d redis redis-server /etc/redis/redis.conf  --appendonly yes  --requirepass 123456

不要密码:

docker run --restart=always --log-opt max-size=100m --log-opt max-file=2 -p 6379:6379 --name redis -v /mydata/redis/redis.conf:/etc/redis/redis.conf -v /mydata/redis/data:/data -d redis redis-server /etc/redis/redis.conf

docker安装rabbitmqmqtt

安装rabbitmq

docker run --restart=always -d --name rabbitmq -e RABBITMQ_DEFAULT_USER=myname -e RABBITMQ_DEFAULT_PASS=123456 -p 1883:1883 -p 15672:15672 -p 15674:15674 -p 5672:5672 rabbitmq:management

开启mqtt:

docker exec rabbitmq /bin/sh -c "rabbitmq-plugins enable rabbitmq_mqtt;rabbitmq-plugins enable rabbitmq_web_mqtt;"

rabbitmq连接地址http://宿主机ip:5672
mqtt连接地址:http://宿主机ip:1883
rabbitmq管理界面:http://宿主机ip:15672

docker安装rabbitmq和emqx

安装rabbitmq:

docker run --restart=always -d --name rabbitmq -e RABBITMQ_DEFAULT_USER=myname -e RABBITMQ_DEFAULT_PASS=123456 -p 15672:15672 -p 15674:15674 -p 5672:5672 rabbitmq:management

安装emqx:

docker run -d --name emqx -p 1883:1883 -p 18083:18083 -p 8083:8083 --restart=always emqx/emqx:latest

支持微信小程序websocket

docker exec -it -uroot emqx bash
echo "listeners.ws.default.websocket.fail_if_no_subprotocol = false" >> ./etc/emqx.conf

emqx管理界面:http://宿主机ip:18083
emqx默认账号密码admin/public

docker安装rocketmq

安装nameserver

docker run -d --restart=always --name rocket-namesrv -p 9876:9876 -v /mydata/rocketmq/namesrv/logs:/root/logs -v /mydata/rocketmq/namesrv/store:/root/store -e "MAX_POSSIBLE_HEAP=100000000" rocketmqinc/rocketmq sh mqnamesrv 

新建配置

vi /mydata/rocketmq/broker/conf/broker.conf
# 所属集群名称,如果节点较多可以配置多个
brokerClusterName = DefaultCluster
#broker名称masterslave使用相同的名称,表明他们的主从关系
brokerName = broker-a
#0表示Master,大于0表示不同slave
brokerId = 0
#表示几点做消息删除动作,默认是凌晨4点
deleteWhen = 04
#在磁盘上保留消息的时长,单位是小时
fileReservedTime = 48
#有三个值:SYNC_MASTER,ASYNC_MASTER,SLAVE;同步异步表示Master和Slave之间同步数据的机制
brokerRole = ASYNC_MASTER
#刷盘策略取值为:ASYNC_FLUSH,SYNC_FLUSH表示同步刷盘和异步刷盘;SYNC_FLUSH消息写入磁盘后才返回成功状态,ASYNC_FLUSH不需要
flushDiskType = ASYNC_FLUSH
# 设置broker节点所在服务器的ip地址
brokerIP1 = 192.168.0.1
# 磁盘使用达到95%之后,生产者写入消息报错 CODE: 14 DESC: service not available now, maybe disk full
diskMaxUsedSpaceRatio=95

安装broker:

docker run -d  --restart=always --name rmqbroker --link rocket-namesrv:namesrv -p 10911:10911 -p 10909:10909 -v  /mydata/rocketmq/broker/logs:/root/logs -v  /mydata/rocketmq/broker/store:/root/store -v /mydata/rocketmq/broker/conf/broker.conf:/opt/rocketmq-4.4.0/conf/broker.conf -e "NAMESRV_ADDR=namesrv:9876" -e "MAX_POSSIBLE_HEAP=200000000" rocketmqinc/rocketmq sh mqbroker -c /opt/rocketmq-4.4.0/conf/broker.conf 

docker安装nacos2

下载nacos压缩包可能需要参考里面的默认配置文件和sql文件):
https://github.com/alibaba/nacos/releases/download/2.2.1/nacos-server-2.2.1.zip

单机版

新增配置

vi /mydata/nacos/conf/application.properties
...
### 修改数据库配置start(如果不需要mysql,将下面配置全部注释即可):
spring.datasource.platform=mysql
spring.sql.init.platform=mysql
db.num=1
db.url.0=jdbc:mysql://192.168.0.1:3306/nacos-config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
db.user.0=root
db.password.0=123456
### 修改数据库配置end(如果不需要mysql,将上面配置全部注释即可):
...
### 一定要改这个:
nacos.core.auth.plugin.nacos.token.secret.key=M6vLzgEfg0Tt7nsHgGh84Pb64dXdeKp2C
...

创建数据库nacosconfig(如果不需要mysql,则无需执行):

docker exec mysql /bin/sh -c "mysql -uroot -p123456 -e "create database nacos-config default character set utf8 collate utf8_bin""

运行nacos自带的sql(如果不需要mysql,则无需执行):

docker cp /mydata/nacos/conf/mysql-schema.sql mysql:/home/nacos_config.sql
docker exec mysql /bin/sh -c "mysql -uroot -p123456 -e "source /home/nacos_config.sql""

安装nacos

docker run -d --name nacos -p 8848:8848 -p 9848:9848 -p 9849:9849 -e MODE=standalone -v /mydata/nacos/logs/:/home/nacos/logs -v /mydata/nacos/conf/:/home/nacos/conf/ --restart=always nacos/nacos-server:v2.2.1

客户端访问地址:
nacos连接地址:server-addr: 宿主机ip:8848
nacos管理界面:http://宿主机ip:8848/nacos
nacos默认账号密码:nacos/nacos

集群

集群版只比单机版多个cluster.conf配置文件,其他都一样

新增配置application.properties参考单机版,省略):

vi /mydata/nacos/conf/application.properties

新增配置cluster.conf:

vi /mydata/nacos/conf/cluster.conf
192.168.0.1:8848
192.168.0.1:8858

安装nacos1

docker run -d --name nacos1 -p 8848:8848 -p 9848:9848 -p 9849:9849 -v /mydata/nacos1/logs/:/home/nacos/logs -v /mydata/nacos1/conf/:/home/nacos/conf/ --restart=always nacos/nacos-server:v2.2.1

安装nacos2

docker run -d --name nacos2 -p 8858:8848 -p 9858:9848 -p 9859:9849 -v /mydata/nacos2/logs/:/home/nacos/logs -v /mydata/nacos2/conf/:/home/nacos/conf/ --restart=always nacos/nacos-server:v2.2.1

客户端访问地址:
nacos连接地址:server-addr: 宿主机ip:8848,宿主机ip:8858
nacos1管理界面:http://宿主机ip:8848/nacos
nacos2管理界面:http://宿主机ip:8858/nacos
nacos默认账号密码:nacos/nacos

原文地址:https://blog.csdn.net/u012643122/article/details/133869648

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任

如若转载,请注明出处:http://www.7code.cn/show_28398.html

如若内容造成侵权/违法违规/事实不符,请联系代码007邮箱:suwngjj01@126.com进行投诉反馈,一经查实,立即删除

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注