2

我创建了一个基于 ubuntu/trusty64 的基本 vagrant box。

当我“流浪”机器并下一次“流浪 ssh”进入它时,一切都很好。

下一步是安装最新的 mysql 5.7,这就是我所做的:

wget http://dev.mysql.com/get/mysql-apt-config_0.7.3-1_all.deb
sudo dpkg -i mysql-apt-config_0.7.3-1_all.deb
sudo apt-get update
sudo apt-get install -y mysql-server

所以它会下载配置等...接下来会出现一个“交互式”外壳,要求我在哪里输入密码并重复。

MySql 5.7 已成功安装在我的机器上......但是:

我希望它在“vagrant up”期间安装,这就是我修改 Vagrantfile 的原因:

config.vm.provision :shell, path: "bootstrap.sh"

在 bootstrap.sh 我添加了内容:

wget http://dev.mysql.com/get/mysql-apt-config_0.7.3-1_all.deb
sudo dpkg -i mysql-apt-config_0.7.3-1_all.deb
sudo apt-get update
sudo apt-get install -y mysql-server

这完全失败了......在控制台中我可以阅读它尝试配置 mysql 5.5 及其依赖项。

但为什么?

如果有人可以帮助解决这个问题,我将非常感激。

谢谢和问候!

更新错误信息

==> default: There are no enabled repos.
==> default:  Run "yum repolist all" to see the repos you have.
==> default:  You can enable repos with yum-config-manager --enable <repo>
==> default: sudo: yum-config-manager: command not found
==> default: There are no enabled repos.
==> default:  Run "yum repolist all" to see the repos you have.
==> default:  You can enable repos with yum-config-manager --enable <repo>
==> default: mysqld: unrecognized service
The SSH command responded with a non-zero exit status. Vagrant
assumes that this means the command failed. The output for this command
should be in the log above. Please read the output to determine what
went wrong.
4

1 回答 1

1

vagrant 安装 5.5 而不是 5.7 的原因是因为ubuntu/trusty版本可能是 ubuntu 14.04,ubuntu 14.04 的默认 mysql 版本是 mysql 5.5。

下面是一个自动安装mysql 5.7的vagrant文​​件,不过我这里配置了centos6。随意更改操作系统并将其设置为 ubuntu/trusty。做就是了

mysql57_config.vm.box = 'ubuntu/trusty64'

指示:

mkdir mysql-5-7

cd mysql-5-7

一旦你在 mysql-5-7 目录中添加这两个文件,Vagrantfile然后bootstrap.sh文件

流浪文件

    # -*- mode: ruby -*-
# vi: set ft=ruby :

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure(2) do |config|
  # The most common configuration options are documented and commented below.
  # For a complete reference, please see the online documentation at
  # https://docs.vagrantup.com.

  # Every Vagrant development environment requires a box. You can search for
  # boxes at https://atlas.hashicorp.com/search.
  config.vm.box = "centos/7"
  config.vm.hostname = "mysql57"
  config.vm.provision "shell", path: "bootstrap.sh"
  config.vm.define "mysql57" do |mysql57|
  end

  # Disable automatic box update checking. If you disable this, then
  # boxes will only be checked for updates when the user runs
  # `vagrant box outdated`. This is not recommended.
  # config.vm.box_check_update = false

  # Create a forwarded port mapping which allows access to a specific port
  # within the machine from a port on the host machine. In the example below,
  # accessing "localhost:8080" will access port 80 on the guest machine.
  # config.vm.network "forwarded_port", guest: 80, host: 8080

  # Create a private network, which allows host-only access to the machine
  # using a specific IP.
  config.vm.network "private_network", ip: "192.168.33.10"

  # Create a public network, which generally matched to bridged network.
  # Bridged networks make the machine appear as another physical device on
  # your network.
  # config.vm.network "public_network"

  # Share an additional folder to the guest VM. The first argument is
  # the path on the host to the actual folder. The second argument is
  # the path on the guest to mount the folder. And the optional third
  # argument is a set of non-required options.
  # config.vm.synced_folder "../data", "/vagrant_data"

  # Provider-specific configuration so you can fine-tune various
  # backing providers for Vagrant. These expose provider-specific options.
  # Example for VirtualBox:
  #
  # config.vm.provider "virtualbox" do |vb|
  #   # Display the VirtualBox GUI when booting the machine
  #   vb.gui = true
  #
  #   # Customize the amount of memory on the VM:
  #   vb.memory = "1024"
  # end
  #
  # View the documentation for the provider you are using for more
  # information on available options.

  # Define a Vagrant Push strategy for pushing to Atlas. Other push strategies
  # such as FTP and Heroku are also available. See the documentation at
  # https://docs.vagrantup.com/v2/push/atlas.html for more information.
  # config.push.define "atlas" do |push|
  #   push.app = "YOUR_ATLAS_USERNAME/YOUR_APPLICATION_NAME"
  # end

  # Enable provisioning with a shell script. Additional provisioners such as
  # Puppet, Chef, Ansible, Salt, and Docker are also available. Please see the
  # documentation for more information about their specific syntax and use.
  # config.vm.provision "shell", inline: <<-SHELL
  #   sudo apt-get update
  #   sudo apt-get install -y apache2
  # SHELL
end

引导程序

sudo yum install -y wget
wget https://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm
sudo yum install -y mysql57-community-release-el7-8.noarch.rpm
sudo yum -y update
sudo yum -y install mysql-server
sudo systemctl start mysqld
sudo systemctl enable mysqld
MYSQL_TEMP_PWD=`sudo cat /var/log/mysqld.log | grep 'A temporary password is generated' | awk -F'root@localhost: ' '{print $2}'`
mysqladmin -u root -p`echo $MYSQL_TEMP_PWD` password 'Passw0rd!'
cat << EOF > .my.cnf
[client]
user=root
password=Passw0rd!
EOF

现在请运行以下命令: vagrant up vagrant ssh

您在连接到mysql的机器上的那些:连接到mysql并提供以下凭据~~ user: root password: Passw0rd!

在 /etc/sudoers (或 /etc/sudoers.d 如果包含)中的某个地方,您必须拥有

vagrant ALL=(ALL) NOPASSWD:ALL
Defaults:vagrant !requiretty

没有它,vagrant ssh(没有 tty)会神秘地失败。

如果您使用的是 MacOS,请关闭防火墙并查看它是否有效?

于 2016-07-29T17:14:10.217 回答