I need to create a new Laravel project and I need to use Mongo DB as a database server. Following the Homestead documentation I added this in my Homeasted.yaml file:
mongodb: true
From what I see in the logs the mongo database is created:
homestead-7: Running: script: Creating Mongo Database: homestead
But after this I received this message:
homestead-7: Running: script: Creating Mongo Database: homestead
homestead-7: MongoDB shell version v3.6.3
homestead-7: connecting to: mongodb://127.0.0.1:27017/homestead
homestead-7: 2019-06-03T10:01:52.103+0000 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused
homestead-7: 2019-06-03T10:01:52.104+0000 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
homestead-7: connect#src/mongo/shell/mongo.js:251:13
homestead-7: #(connect):1:6
homestead-7: exception: connect failed
The SSH command responded with a non-zero exit status.
From what I found on the internet it can be that the mongo service is not started. I restarted the box without provisioning this time but with the same result. Command:
vagrant#homestead:~$ mongo
Also, I found some solutions that involve changing of some files on an Ubutu O.S but in my case it will not work because the box will start as a fresh instance.
Any idea how to fix this? Thanks in advance!
Laravel version: 5.8.
Homestead: 8.4.0
MongoDB shell: v3.6.3
LATER EDIT
After the VM has started I executed this command:
sudo apt-get install mongodb
After installation I can execute the "mongo" command:
MongoDB shell version v3.6.3
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.6.3
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
http://docs.mongodb.org/
Questions? Try the support group
http://groups.google.com/group/mongodb-use
Strange, so actually Mongo DB isn't installed?! Even if I added the flag. Now I need to figure how to add it every time when the VM is started.
I managed to fix my problem after hours of searching so I will post the fix.
Because I didn't find anything that could help me I started to check the Homestead scripts in order to understand how Mongo is installed and in homestead.rb I found this line:
# Install MongoDB If Necessary
if settings.has_key?('mongodb') && settings['mongodb']
config.vm.provision 'shell' do |s|
s.name = 'Installing MongoDb'
s.path = script_dir + '/install-mongo.sh'
end
end
So I searched were "install-mongo.sh" is called and I found this condition:
if [ -f /home/vagrant/.mongo ]
then
echo "MongoDB already installed."
exit 0
fi
So Mongo DB is not installed every time only if the "/home/vagrant/.mongo" file doesn't exist. At this point I realized that maybe Mongo failed to be installed but this file was written.
So the solution was to destroy the Vagrant box and recreate it from scratch:
vagrant destroy
vagrant up --provision
In Homestead.yaml under features: add -mongodb: true
and run vagrant reload --provision, that is same as what #NicuVlad has suggested but little bit easier.
Related
I upgraded laravel/homestead box to version 11.1.0. Then a surprising happened: My DBs disappeared. How? I have no idea.
But then when I tried to reinstall the databases using Homestead.yaml, it did not work eventhough I added the list of databases in Homestead.yaml.
Here the what I did in Homestead.yaml:
databases:
- db00
- db01
Then I ran "vagrant provision" but nothing changed in MySQL. "show databases;" displayed default tables only.
Then I activated the features:
features:
- mysql: true
- mariadb: false
Then I ran "vagrant provision" and it worked. I had both databases (db00 and db01) in MySQL.
Here are the problems:
Based on laravel/homestead documentation for laravel v8.x, there is no feature option for mysql. That caused the following error during provisioning:
homestead: Invalid feature: mysql
homestead: Ignoring feature: mariadb because it is set to false
Once I added the option "- mysql" to the Homestead.yaml, I received the following errors for MariaDB
homestead: Running: script: Creating MySQL / MariaDB Database: db00
homestead: We didn't find a PID for mariadb, skipping $DB creation
homestead: Running: script: Creating MySQL / MariaDB Database: db01
homestead: We didn't find a PID for mariadb, skipping $DB creation
Now here my question: What is going on? Without the feature option "- mysql" no database is created; no matter if I define the list under the databases. Once I add it, things work, databases are generated however, I get error that the feature is not valid. Also it is not included in the documentation.
Where am I going wrong? or if anyone has an explanation or a better solution?
The answers to both of your questions is: because the documention is a bit misleading
For your first question, mysql is technically not an optional feature since is installed by default. However, as of v11.3.0 in order to provision custom databases it must be listed under the features section in the Homestead.yaml:
features:
- mysql: true
due to only running the provisioning script if mysql is specifically enabled:
https://github.com/laravel/homestead/blob/v11.3.0/scripts/homestead.rb
For your second question, the error message is displayed due to the way that the create-mysql.sh script was implemented in v11.0.0:
https://github.com/laravel/homestead/blob/v11.0.0/scripts/create-mysql.sh
if [ -z "$mariadb" ]
then
# Skip Creating MariaDB database
echo "We didn't find a PID for mariadb, skipping \$DB creation"
else
mysql -e "CREATE DATABASE IF NOT EXISTS \`$DB\` DEFAULT CHARACTER SET utf8mb4 DEFAULT COLLATE utf8mb4_unicode_ci";
fi
With the configuration you are using the if [ -z "$mariadb" ] condition will always be true because the process id of mariadbd will never be found since it is not enabled. Therefore the We didn't find a PID for mariadb, skipping $DB creation message will always be displayed even though the databases are succesfully created for mysql. Technically that is correct based on the way the script is coded, but it is also a bit confusing.
Also as for why your databases disappeared when upgrading, assuming you were following these instructions:
https://laravel.com/docs/8.x/homestead#updating-homestead
The vagrant destroy command will completely remove the homestead box and rebuild it. Therefore any data or other custom configuration will be lost unless it is configured to backup the data:
https://laravel.com/docs/8.x/homestead#database-backups
I ran into this same issue recently with Homestead 12.3.0 and solved it by editing my Homestead.yaml with the following:
...
databases:
- homestead
- my_database
features:
# - mysql: true
- mariadb: false
- postgresql: false
- ohmyzsh: false
- webdriver: false
services:
- "mysql"
...
Then I ran vagrant reload --provision, and did not see the MariaDB error anymore.
To confirm you can SSH into the vagrant box, and log into MySQL (homestead / secret). In my case I found the database had been created correctly.
I get an error when I do homestead up --provision on my homestead machine:
...[success logs here]...
==> default: Running provisioner: shell...
default: Running: /var/folders/9j/bsvhbzdn2dx8hjwgnl7nrj7w0000gn/T/vagrant-
shell20170127-4343-1dyyzgz.sh
==> default: mysql:
==> default: [Warning] Using a password on the command line interface
can be insecure.
==> default: Please use --connect-expired-password option or invoke
mysql in interactive mode.
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.
Although I get this error, everything works fine except one:
Databases that I have defined in ~/.homestead/Homestead.yaml are not created in mysql. So I guess this error causes the issue.
Any help would be appreciated.
I believe this is actually due to MySQL having an expiration time on passwords rather than having them last forever. It seems to happen for me when I'm running my old Laravel Homestead 5 box instead of newer ones for Homestead 7+.
Note that the following solution also fixes ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
From the host machine:
vagrant up
# ignore "SSH command responded with a non-zero exit status"
vagrant ssh
Now within the client machine:
# log into mysql (for Homestead your password is likely "secret")
mysql -h localhost -u homestead -p
SET PASSWORD = PASSWORD('secret');
-- A) set password to never expire:
ALTER USER 'root'#'localhost' PASSWORD EXPIRE NEVER;
-- or B) to change password as well:
ALTER USER 'root'#'localhost' IDENTIFIED BY 'new_password', 'root'#'localhost' PASSWORD EXPIRE NEVER;
-- quit mysql
quit
# exit back to host shell
exit
Now from the host machine:
vagrant up --provision
And it should work.
However, if you now see ==> default: createdb: database creation failed: ERROR: database "homestead" already exists then run this line within the client machine:
mysql -h localhost -u homestead -p -e "DROP DATABASE homestead"
Then run vagrant up --provision from the host machine and be on your way.
I'm attempting get started with kubernetes and do a vagrant/virtualbox install as per http://kubernetes.io/docs/getting-started-guides/binary_release/#download-kubernetes-and-automatically-set-up-a-default-cluster
My commands are:
export KUBERNETES_PROVIDER=vagrant
curl -sS https://get.k8s.io | bash
I get the following errors at the terminal:
master: Vagrant insecure key detected. Vagrant will automatically replace
master: this with a newly generated keypair for better security.
master:
master: Inserting generated public key within guest...
master: Removing insecure key from the guest if it's present...
master: Key inserted! Disconnecting and reconnecting using new SSH key...
master: Warning: Authentication failure. Retrying...
<snip>
master: Warning: Authentication failure. Retrying...
Timed out while waiting for the machine to boot. This means that
Vagrant was unable to communicate with the guest machine within
the configured ("config.vm.boot_timeout" value) time period.
The script then exits without completing kubernetes "master" set up and without setting up any nodes.
I am able to vagrant ssh master, but need to manually enter the default "vagrant" password.
I am running OSX 10.11.6 (15G31). I am running recent versions of virtualbox (5.0.26 r108824) and vagrant (1.8.5).
These kubernetes "getting started" instructions appear to be downloading the latest kubernetes version (1.3.4).
Because I had older virtualbox and vagrant versions installed, I made sure to completely uninstall and reinstall both, as per:
https://www.virtualbox.org/manual/ch02.html#idm871
https://www.vagrantup.com/docs/installation/uninstallation.html
I assume there is something going wrong with ssh somewhere, though given that these are the published "getting started" instructions and I am using fresh installs of all components, I am surprised that this is not working right out of the box.
Take a look at https://github.com/kubernetes/minikube. It's an official Kubernetes project intended to simplify this exact use case. I've been using it for a few weeks and it works great.
The easiest way to run kubernetes on OSX, I think, is by using Kube-Solo or Kube-Cluster.
Please check this repo:
https://github.com/TheNewNormal/kube-cluster-osx
Note: for me is only working well with the CoreOS stable release.
I'm learning Chef (12.10.24) and am trying to build a cookbook with recipes for provisioning machines that I'll do Ruby development on.
I'm trying to use knife bootstrap to set up my laptop as a node but am getting a connection error that I'm not sure how to get around. Here is the output:
➜ chef-repo$ knife bootstrap localhost -yN my-macbook-pro -p 2200 -x david -P [password]
Creating new client for my-macbook-pro
Creating new node for my-macbook-pro
Connecting to localhost
ERROR: Network Error: Connection refused - connect(2) for 127.0.0.1:2200
Check your knife configuration and network settings
Connecting to chef-server is fine but I can't connecting to localhost. Any suggestions about what I might be doing wrong?
I neglected to mention that I am using OSX El Capitan. It turns out that the ssh daemon isn't on by default in OSX.
Turning it on in System Preferences > Sharing (check Remote Login) fixed the problem.
I am trying to load my vagrant box with salt, asking it to install Apache.
I am using salty-vagrant in masterless mode.
The vagrant box gets loaded, but it gets stuck in the console with the following message:
[default] Running provisioner: salt...
Checking if salt-minion is installed
salt-minion found
Checking if salt-call is installed
salt-call found
Salt did not need installing or configuring.
Calling state.highstate... (this may take a while)
When I check the vagrant salt log, the following is found:
[salt.utils ][ERROR ] This master address: 'salt' was previously resolvable but now fails to resolve! The previously resolved ip addr will continue to be used
[salt.minion ][WARNING ] Master hostname: salt not found. Retrying in 30 seconds
Has anyone faced this issue before?
You need to make sure you are passing a minion config with the following option set:
file_client: local
Read all the steps in the Masterless Quick Start: https://github.com/saltstack/salty-vagrant#masterless-quick-start