Vagrant Box - 使用apt安装MySql 5.7

时间:2016-07-29 16:42:09

标签: mysql ubuntu vagrant vagrantfile mysql-5.7

我创建了一个基于ubuntu / trusty64的基本流浪盒。

当我“迷惑”机器和下一个“流浪汉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

所以它下载配置等...接下来出现“交互式”shell,我要求输入密码并重复。

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及其依赖项。

但为什么?

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

谢谢和问候!

UPDATE 错误消息

==> 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.

1 个答案:

答案 0 :(得分: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 =&#39; ubuntu / trusty64&#39;

<强> 说明:

  

mkdir mysql-5-7

     

cd mysql-5-7

进入mysql-5-7目录后,添加这两个文件Vagrantfilebootstrap.sh文件

<强> Vagrantfile

    # -*- 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

<强> bootstrap.sh

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
没有它,流浪汉ssh(没有tty)神秘失败。

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