快速部署开发常用软件
环境准备
记录一下工作中常用到的一些软件部署步骤,这里采用虚拟机+Docker的形式部署,方便本地开发的时候连接自己的软件服务。
首先需要下载虚拟机和操作系统,然后创建一个可用的系统,操作步骤参考网址。
虚拟机:下载地址
CentOS:下载地址
系统安装完毕以后,登录进入系统,查看当前网卡的IP地址,使用命令如下:
ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:6c:d4:98 brd ff:ff:ff:ff:ff:ff
inet 192.168.5.128/24 brd 192.168.5.255 scope global noprefixroute dynamic ens33
valid_lft 1496sec preferred_lft 1496sec
inet6 fe80::f3a4:df10:cdd:b310/64 scope link noprefixroute
valid_lft forever preferred_lft forever
找到ens33,可以看到IP地址是:192.168.5.128,后边访问各个软件的时候会用到,大家用自己的就好。
安装Docker
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo systemctl start docker
sudo systemctl enable docker.service
sudo systemctl status docker
sudo docker -v
安装Git
sudo yum install -y git
sudo git --version
安装MySQL
# 拉取mysql镜像
docker pull mysql:8.0.36
# 创建目录
cd ~
mkdir mysql8
cd mysql8
# 运行镜像
docker run -id \
--privileged=true \
--restart=always \
--name c_mysql8 \
-p 3306:3306 \
-v $PWD/conf:/etc/mysql/conf.d \
-v $PWD/logs:/logs \
-v $PWD/data:/var/lib/mysql \
-e MYSQL_ROOT_PASSWORD=123456 \
mysql:8.0.36
# 设置防火墙
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload
# 客户端访问
下载后并安装:https://github.com/webyog/sqlyog-community/wiki/Downloads
地址:192.168.5.128
端口:3306
账户:root
密码:123456
安装Redis
# 拉取mysql镜像
docker pull redis:7.2.4
# 创建目录
cd ~
mkdir redis7
cd redis7
# 运行镜像
docker run -id \
--privileged=true \
--restart=always \
--name c_redis7 \
-p 6379:6379 \
-v $PWD/conf/redis.conf:/usr/local/etc/redis/redis.conf \
-v $PWD/log/redis.log:/var/log/redis.log \
-v $PWD/data:/data \
redis:7.2.4 --requirepass "123456"
# 设置防火墙
firewall-cmd --zone=public --add-port=6379/tcp --permanent
firewall-cmd --reload
# 客户端访问
下载后并安装:https://github.com/lework/RedisDesktopManager-Windows/releases
地址:192.168.5.128
端口:6379
账户:不用填写
密码:123456
安装Nacos
# 拉取Nacos镜像
docker pull nacos/nacos-server:v2.3.0
# 创建目录
cd ~
mkdir nacos2
cd nacos2
# 运行镜像
docker run -id \
--privileged=true \
--restart=always \
--name c_nacos2 \
-p 8848:8848 \
-p 9848:9848 \
-v $PWD/logs:/home/nacos/logs \
-e PREFER_HOST_MODE=hostname \
-e MODE=standalone \
-e NACOS_AUTH_IDENTITY_KEY=serverIdentity \
-e NACOS_AUTH_IDENTITY_VALUE=security \
-e NACOS_AUTH_TOKEN=SecretKey012345678901234567890123456789012345678901234567890123456789 \
-e NACOS_AUTH_ENABLE=true \
-e JVM_XMS=512m \
-e JVM_XMX=512m \
nacos/nacos-server:v2.3.0
# 设置防火墙
firewall-cmd --zone=public --add-port=8848/tcp --permanent
firewall-cmd --zone=public --add-port=9848/tcp --permanent
firewall-cmd --reload
# 浏览器访问
地址:http://192.168.5.128:8848/nacos/#/login
账号:nacos
密码:nacos
安装RocketMQ
准备工作
# 拉取镜像
docker pull apache/rocketmq:5.1.4
docker pull apacherocketmq/rocketmq-dashboard:latest
# 以下是nameserver相关处理
# 创建目录
cd ~
mkdir /usr/local/rocketmq/nameserver/logs -p
mkdir /usr/local/rocketmq/nameserver/bin -p
chmod 777 -R /usr/local/rocketmq/nameserver/*
# 运行镜像并拷贝启动脚本
docker run -d --privileged=true --name rmqnamesrv apache/rocketmq:5.1.4 sh mqnamesrv
docker cp rmqnamesrv:/home/rocketmq/rocketmq-5.1.4/bin/runserver.sh /usr/local/rocketmq/nameserver/bin/runserver.sh
# 修改启动脚本,找到调用calculate_heap_sizes函数的位置注释掉,然后保存
vi /usr/local/rocketmq/nameserver/bin/runserver.sh
# 停止并删除刚才运行镜像
docker stop rmqnamesrv
docker rm rmqnamesrv
# 以下是broker相关处理
# 创建目录
cd ~
mkdir /usr/local/rocketmq/broker/logs -p
mkdir /usr/local/rocketmq/broker/data -p
mkdir /usr/local/rocketmq/broker/conf -p
mkdir /usr/local/rocketmq/broker/bin -p
chmod 777 -R /usr/local/rocketmq/broker/*
# 创建配置
vi /usr/local/rocketmq/broker/conf/broker.conf
内容如下:
brokerClusterName = DefaultCluster
brokerName = broker-a
brokerId = 0
deleteWhen = 04
fileReservedTime = 72
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUSH
autoCreateTopicEnable = true
autoCreateSubscriptionGroup = true
# 运行镜像并拷贝启动脚本
docker run -d --privileged=true --name rmqbroker apache/rocketmq:5.1.4 sh mqbroker
docker cp rmqbroker:/home/rocketmq/rocketmq-5.1.4/bin/runbroker.sh /usr/local/rocketmq/broker/bin/runbroker.sh
# 修改启动脚本,找到调用calculate_heap_sizes函数的位置注释掉,然后保存
vi /usr/local/rocketmq/broker/bin/runbroker.sh
# 停止并删除刚才运行镜像
docker stop rmqbroker
docker rm rmqbroker
编辑配置
vi /usr/local/rocketmq/standalone-rocketmq-5.yaml
version: '3.8'
services:
rmqnamesrv:
image: apache/rocketmq:5.1.4
container_name: rmqnamesrv
ports:
- 9876:9876
restart: always
privileged: true
volumes:
- /usr/local/rocketmq/nameserver/logs:/home/rocketmq/logs
- /usr/local/rocketmq/nameserver/bin/runserver.sh:/home/rocketmq/rocketmq-5.1.4/bin/runserver.sh
environment:
- MAX_HEAP_SIZE=512M
- HEAP_NEWSIZE=256M
command: ["sh","mqnamesrv"]
broker:
image: apache/rocketmq:5.1.4
container_name: rmqbroker
ports:
- 10909:10909
- 10911:10911
restart: always
privileged: true
volumes:
- /usr/local/rocketmq/broker/logs:/home/rocketmq/logs
- /usr/local/rocketmq/broker/store:/home/rocketmq/logs
- /usr/local/rocketmq/broker/conf/broker.conf:/home/rocketmq/broker.conf
- /usr/local/rocketmq/broker/bin/runbroker.sh:/home/rocketmq/rocketmq-5.1.4/bin/runbroker.sh
depends_on:
- 'rmqnamesrv'
environment:
- NAMESRV_ADDR=rmqnamesrv:9876
- MAX_HEAP_SIZE=512M
- HEAP_NEWSIZE=256M
command: ["sh","mqbroker","-c","/home/rocketmq/broker.conf"]
rmqdashboard:
image: apacherocketmq/rocketmq-dashboard:latest
container_name: rmqdashboard
ports:
- 8080:8080
restart: always
privileged: true
depends_on:
- 'rmqnamesrv'
environment:
- JAVA_OPTS= -Xmx256M -Xms256M -Xmn128M -Drocketmq.namesrv.addr=rmqnamesrv:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false
部署运行
# 部署服务
docker compose -f /usr/local/rocketmq/standalone-rocketmq-5.yaml up -d
# 防火墙设置
firewall-cmd --zone=public --add-port=9876/tcp --permanent
firewall-cmd --zone=public --add-port=10909/tcp --permanent
firewall-cmd --zone=public --add-port=10911/tcp --permanent
firewall-cmd --zone=public --add-port=8080/tcp --permanent
firewall-cmd --reload
# 浏览器访问
地址:http://192.168.5.128:8080