1.使用VirtualBox + Vagrant
分别下载安装后,运行:vagrant init centos7 https://mirrors.ustc.edu.cn/centos-cloud/centos/7/vagrant/x86_64/images/CentOS-7.box
后:vagrant up
登录: vagrant ssh
2.登录后设置虚拟机IP: 查年windows的ipconfig ,找到virtualbox的虚拟网卡网关:如 192.168.56.1 ,则 虚拟机IP可设置为: 192.168.56.10 ,这个IP的设置位置是:c:/users/administrator/VagrantFile中的:config.vm.network "private_network", ip: "192.168.56.10"
修改后,执行: vagrant reload让设置生效。
3.虚拟机网络设置:
如果一直报:Could not resolve host: mirrorlist.centos.org; Unknown error,这一般是网卡没配置好,只要在VagrantFile 里面打开这一行,开启桥接模式:config.vm.network "public_network"
Vagrant (三) - 网络配置 - 简书
4.Docker安装及自启动
安装参考:Docker官方文档
先删除:
sudo yum remove docker \docker-client \docker-client-latest \docker-common \docker-latest \docker-latest-logrotate \docker-logrotate \docker-engine
之后:安装工具:
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
第3步:sudo yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
第4步,启动Docker :
sudo systemctl start docker
第5步:设置Docker自启动:
sudo systemctl enable docker
第6步:镜像加速
阿里云登录 - 欢迎登录阿里云,安全稳定的云计算服务平台
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": ["https://b6qf0f6f.mirror.aliyuncs.com"] } EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
5.Docker 安装 Mysql
一:从Docker hub中拉取mysql :
sudo docker pull mysql:8.0
二:安装
sudo docker run -p 3306:3306 --name mysql
-v /mydata/mysql/log:/var/log/mysql
-v /mydata/mysql/data:/var/lib/mysql
-v /mydata/mysql/conf:/etc/mysql
-e MYSQL_ROOT_PASSWORD=root
-d mysql:8.0
三:启动:docker start mysql 。查看运行中的容器:docker ps 。设置mysql自启动:
sudo docker update mysql --restart=always 查看mysql的日志:docker container logs mysql
四:进入容器:sudo docker exec -it mysql bash
五: 如果MYsql日志报错: mysqld: Error on realpath() on ‘/var/lib/mysql-files’ (Error 2 - No such file or directory): 先删除container :sudo docker container rm mysql
再建 一个文件夹: mkdir mysql-files ,再输入命令:
sudo docker run -p 3306:3306 --name mysql -v /mydata/mysql/log:/var/log/mysql -v /mydata/mysql/data:/var/lib/mysql -v /mydata/mysql/conf:/etc/mysql -v /home/vagrant/mysql-files/:/var/lib/mysql-files -e MYSQL_ROOT_PASSWORD=1234 -d mysql:8.0
解决mysqld: ‘/var/lib/mysql-files‘ (Error 2..._wslynn的博客-CSDN博客
六:如果远程连接时报错:docker Host is not allowed to connect to this mysql server,则先登录mysql容器:docker exec -it mysql bash
后执行:
use mysql;
Grant all privileges on root.* to 'root'@'%'; #执行两次
alter user root identified with mysql_native_password by '1234';
FLUSH PRIVILEGES;