#初始化一个centos7系统。需要什么可以去Vagrant镜像仓库找
vagrant init centos/7
#启动虚拟机、
vagrant up
出现如下安装成功:root和vagrant用户密码都是vagrant。
PS C:\Users\admin> vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'centos/7'...
==> default: Matching MAC address for NAT networking...
==> default: Setting the name of the VM: admin_default_1659259753893_11449
==> default: Fixed port collision for 22 => 2222. Now on port 2200.
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
default: Adapter 1: nat
==> default: Forwarding ports...
default: 22 (guest) => 2200 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
default: SSH address: 127.0.0.1:2200
default: SSH username: vagrant
default: SSH auth method: private key
default:
default: Vagrant insecure key detected. Vagrant will automatically replace
default: this with a newly generated keypair for better security.
default:
default: Inserting generated public key within guest...
default: Removing insecure key from the guest if it's present...
default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
default: No guest additions were detected on the base box for this VM! Guest
default: additions are required for forwarded ports, shared folders, host only
default: networking, and more. If SSH fails on this machine, please install
default: the guest additions and repackage the box to continue.
default:
default: This is not an error message; everything may continue to work properly,
default: in which case you may ignore this message.
==> default: Rsyncing folder: /cygdrive/c/Users/admin/ => /vagrant
vagrant ssh
yum install -y vim
vim /etc/ssh/sshd_config
#?+关键字查找。:set nu 分别是:
#38 #PermitRootLogin yes
PermitRootLogin yes
#63 PasswordAuthentication yes
#64 #PermitEmptyPasswords no
#65 #PasswordAuthentication no
PasswordAuthentication yes
hostnamectl set-hostname fox
reboot
#1、卸载旧版本
yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine;
#2、删除安装包
yum remove -y docker-*;
#3、删除镜像/容器等
rm -rf /var/lib/docker;
#4、查询docker安装过的包
yum list installed | grep docker;
#5、设置存储库
yum install -y yum-utils;
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo;
#6、安装Docker引擎
yum install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin;
#7、启动 Docker
systemctl start docker;
#8、测试是否安装成功
docker -v;
docker image;
#9、将Docker 配置为开机启动
systemctl enable docker.service
systemctl enable containerd.service
#10、配置镜像加速器
mkdir -p /etc/docker;
tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://unhyzi6w.mirror.aliyuncs.com"]
}
EOF
systemctl daemon-reload;
systemctl restart docker;
#拉取MySQL5.7镜像
docker pull mysql:5.7;
#停止并卸载mysql
docker stop mysql
docker rm mysql
rm -rf /fox/mysql
#拉取MySQL最新镜像
#docker pull mysql:latest
#查看本地镜像
docker images
#创建实例并启动
docker run -p 3306:3306 --name mysql \
-v /fox/mysql/log:/var/log/mysql \
-v /fox/mysql/data:/var/lib/mysql \
-v /fox/mysql/conf:/etc/mysql \
-e MYSQL_ROOT_PASSWORD=123456 \
--restart=always \
-d mysql:5.7;
#查看MySQL的位置
#whereis mysql
#退出MySQL容器
#exit
#配置文件
cat >>/fox/mysql/conf/my.cnf<<EOF
[client]
default-character-set=utf8
[mysql]
default-character-set=utf8
[mysqld]
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
skip-name-resolve
EOF
#重启mysql
docker restart mysql
#查看启动的镜像
docker ps
#可以通过[容器名字]或者[容器 ID]进入 MySQL 容器
#docker exec -it mysql bash
#查看配置文件是否配置成功
#cat /etc/mysql/my.cnf
#进入MySQL
#mysql -uroot -p123456
#开机自启动
#docker update mysql --restart=always
#下载镜像文件
docker pull redis;
#创建实例并启动
mkdir -p /fox/redis/conf;
touch /fox/redis/conf/redis.conf;
docker run -p 6379:6379 --name redis \
-v /fox/redis/data:/data \
-v /fox/redis/conf/redis.conf:/etc/redis/redis.conf \
--restart=always \
-d redis redis-server /etc/redis/redis.conf;
#查看是否安装成功
docker ps
#Redis持久化配置、重启保留数据
cat >>/fox/redis/conf/redis.conf<<EOF
appendonly yes
EOF
#执行redis-cli命令连接
#docker exec -it redis redis-cli
#开机自启动
#docker update redis --restart=always
# 1、搜索nacos镜像
docker search nacos;
# 2、下载镜像
docker pull nacos/nacos-server:v2.1.0;
# 3、查看本地镜像
docker images;
# 3.1、删除nacos
docker stop nacos
docker rm nacos
# 4、创建临时容器用于拷贝配置文件
docker run -p 8848:8848 \
-e MODE=standalone \
--name nacos \
--restart=always \
-d nacos/nacos-server:v2.1.0
# 5、拷贝nacos配置文件,用于后续的本地挂载
# 5.1、创建文件夹
mkdir -p /fox/nacos/conf
mkdir -p /fox/nacos/logs
mkdir -p /fox/nacos/data
# 5.2、配置文件复制
docker cp nacos:/home/nacos/logs/ /fox/nacos/
docker cp nacos:/home/nacos/conf/ /fox/nacos/
docker cp nacos:/home/nacos/data/ /fox/nacos/
# 6、删除临时的nacos容器,需要先停止,再删除
docker stop nacos
docker rm nacos
# 7、创建容器并设置开机启动,设置本地挂载,配置mysql持久化
docker run -p 8848:8848 \
-v /fox/nacos/logs:/home/nacos/logs \
-v /fox/nacos/conf:/home/nacos/conf \
-v /fox/nacos/data:/home/nacos/data \
-e MODE=standalone \
--name nacos \
--restart=always \
-d nacos/nacos-server:v2.1.0
# 8、修改配置文件
vim /fox/nacos/conf/application.properties
1 # spring
2 server.servlet.contextPath=${SERVER_SERVLET_CONTEXTPATH:/nacos}
3 server.contextPath=/nacos
4 server.port=${NACOS_APPLICATION_PORT:8848}
5 #spring.datasource.platform=${SPRING_DATASOURCE_PLATFORM:""}
6 spring.datasource.platform=mysql
7 nacos.cmdb.dumpTaskInterval=3600
8 nacos.cmdb.eventTaskInterval=10
9 nacos.cmdb.labelTaskInterval=300
10 nacos.cmdb.loadDataAtStart=false
11 db.num=${MYSQL_DATABASE_NUM:1}
12 #db.url.0=jdbc:mysql://${MYSQL_SERVICE_HOST}:${MYSQL_SERVICE_PORT:3306}/${MYSQL_SERVICE_DB_NAME}?${MYSQL_SERVICE_DB_PARAM:characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false}
13 db.url.0=jdbc:mysql://192.168.37.1:3306/nacos_config?${MYSQL_SERVICE_DB_PARAM:characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false}
14 db.url.1=jdbc:mysql://${MYSQL_SERVICE_HOST}:${MYSQL_SERVICE_PORT:3306}/${MYSQL_SERVICE_DB_NAME}?${MYSQL_SERVICE_DB_PARAM:characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false}
15 #db.user=${MYSQL_SERVICE_USER}
16 db.user=root
17 #db.password=${MYSQL_SERVICE_PASSWORD}
18 db.password=123456
19 ### The auth system to use, currently only 'nacos' is supported:
20 nacos.core.auth.system.type=${NACOS_AUTH_SYSTEM_TYPE:nacos}
21
22
23 ### The token expiration in seconds:
24 nacos.core.auth.default.token.expire.seconds=${NACOS_AUTH_TOKEN_EXPIRE_SECONDS:18000}
25
26 ### The default token:
27 nacos.core.auth.default.token.secret.key=${NACOS_AUTH_TOKEN:SecretKey012345678901234567890123456789012345678901234567890123456789}
28
29 ### Turn on/off caching of auth information. By turning on this switch, the update of auth information would have a 15 seconds delay.
30 nacos.core.auth.caching.enabled=${NACOS_AUTH_CACHE_ENABLE:false}
31 nacos.core.auth.enable.userAgentAuthWhite=${NACOS_AUTH_USER_AGENT_AUTH_WHITE_ENABLE:false}
32 nacos.core.auth.server.identity.key=${NACOS_AUTH_IDENTITY_KEY:serverIdentity}
33 nacos.core.auth.server.identity.value=${NACOS_AUTH_IDENTITY_VALUE:security}
34 server.tomcat.accesslog.enabled=${TOMCAT_ACCESSLOG_ENABLED:false}
35 server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D
36 # default current work dir
37 server.tomcat.basedir=
38 ## spring security config
39 ### turn off security
40 nacos.security.ignore.urls=${NACOS_SECURITY_IGNORE_URLS:/,/error,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/v1/auth/**,/v1/console/health/**,/actuator/**,/v1/console/server/**}
41 # metrics for elastic search
42 management.metrics.export.elastic.enabled=false
43 management.metrics.export.influx.enabled=false
44
45 nacos.naming.distro.taskDispatchThreadCount=10
46 nacos.naming.distro.taskDispatchPeriod=200
47 nacos.naming.distro.batchSyncKeyCount=1000
48 nacos.naming.distro.initDataRatio=0.9
49 nacos.naming.distro.syncRetryDelay=5000
50 nacos.naming.data.warmup=true
# 9、重启nacos
docker restart nacos
# 10、创建nacos_config数据库、持久化MySQL