设置root密码
sudo passwd root
******
开启密码登录
vi /etc/ssh/sshd_config
...
PasswordAuthentication yes
PermitRootLogin yes
...
报存并退出vi,重启sshd
sudo service sshd restart
安装docker
#安装前先移除系统可能自带的妖魔鬼怪
sudo yum -y remove containerd.io docker-buildx-plugin docker-compose-plugin docker-ce podman-docker docker-ce-cli
#yum管理工具=yum-config-manager
sudo yum -y install -y yum-utils
#sudo yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
#千万不要使用阿里云的地址,阿里云的镜像已经将docker用podman进行了狸猫换太子,实际安装的是podman-docker,无法使用idea的ssh进行连接。
#删除所有名字带docker的源:cd /etc/yum.repos.d 然后rm -f yum.repos.d目录下的源(文件名)
sudo yum-config-manager -y --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum clean all
sudo yum makecache
sudo yum -y install docker-ce docker-ce-cli containerd.io
可能遇到的问题:
更换成官方仓库后运行sudo yum install docker-ce失败,提示"404 for https://download.docker.com/inux/centos/docker-ce.re/repodata/repomd.xml
解决办法:
curl -I https://download.docker.com
看看能否正常访问docker官网,如果不能就去解决网络问题,如果能,继续下面步骤:
sudo yum clean all
sudo yum makecache
#如果makecache报错,则重新clean all再makecache,直到不报错为止。
sudo yum install docker-ce docker-ce-cli containerd.io
#最后这个安装命令如果失败,就多试几次,因为网络不稳定有时候下载不下来。
安装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安装rabbitmq和mqtt
安装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名称,master和slave使用相同的名称,表明他们的主从关系
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
...
创建数据库nacos-config(如果不需要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文章来源:https://www.toymoban.com/news/detail-724408.html
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://www.toymoban.com/news/detail-724408.html
到了这里,关于centos或aws linux部署java应用,环境搭建shell的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!