Using Vagrant for development, the VM freezes after a while working with it. I have to reload the box in order to be able to work with it again. The file is very simple and straightforward:
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "ubuntu/xenial32"
config.vm.network "forwarded_port", guest: 80, host: 8080
config.vm.network :private_network, ip: "192.168.68.8"
config.vm.provider "virtualbox" do |v|
v.memory = 8192
v.cpus = 2
end
config.vm.synced_folder "./", "/var/www/html", owner: "www-data", group: "www-data"
config.ssh.insert_key = false
config.vm.provision :shell, path: "config/vagrant/bootstrap.sh"
end
and config/vagrant/bootstrap.sh looks like:
#!/usr/bin/env bash
# Variables
DBNAME=dbname
DBUSER=dbuser
DBPASSWD=dbpassword
apt-get -y install software-properties-common
add-apt-repository -y ppa:ondrej/php
apt-get update
apt-get update
debconf-set-selections <<< "mysql-server mysql-server/root_password password $DBPASSWD"
debconf-set-selections <<< "mysql-server mysql-server/root_password_again password $DBPASSWD"
apt-get -y install mysql-server
sed -i "s/.*bind-address.*/bind-address = 0.0.0.0/" /etc/mysql/mysql.conf.d/mysqld.cnf
mysql -uroot -p$DBPASSWD -e "CREATE DATABASE $DBNAME"
mysql -uroot -p$DBPASSWD -e "grant all privileges on $DBNAME.* to '$DBUSER'#'%' identified by '$DBPASSWD'"
mysql -uroot -p$DBPASSWD -e "flush privileges"
sudo apt-get -y install apache2 php7.4 php7.4-mysql php7.4-mbstring php7.4-dom php7.4-sqlite php7.4-zip php7.4-curl php7.4-intl
sudo apt-get -y install curl composer zip unzip
sudo phpenmod pdo_mysql
sudo service apache2 restart
sudo service mysql restart
I read a blog post that suggests removing config.ssh.insert_key = false as a solution but this does not work.
Any ideas?
EDIT
there is no output. It works as expected for approximately 15 minutes before the entire box freezes and stops responding (no response to shell input as well as no vagrant ssh).
Ok, I think I found the issue.
I have changed this line:
v.cpus = 2
to
v.cpus = 1
and I had no hang ups the whole day.
Related
I'm trying to set up a remotely accessible Postgres database. I want to host this databse on one Linux based device (HOST), and to access it on another Linux based device (CLIENT).
In my specific case, HOST is a desktop device running Ubuntu. CLIENT is a Chromebook with a Linux virtual system. (I know. But it's the closest thing to a Linux based device that I have to hand.
Steps Already Taken to Set Up the Database
Installed the required software on HOST using APT.
PGP_KEY_URL="https://www.postgresql.org/media/keys/ACCC4CF8.asc"
POSTGRES_URL_STEM="http://apt.postgresql.org/pub/repos/apt/"
POSTGRES_URL="$POSTGRES_URL_STEM `lsb_release -cs`-pgdg main"
POSTGRES_VERSION="12"
PGADMIN_URL_SHORT="https://www.pgadmin.org/static/packages_pgadmin_org.pub"
PGADMIN_URL_STEM="https://ftp.postgresql.org/pub/pgadmin/pgadmin4/apt"
PGADMIN_TO_ECHO="deb $PGADMIN_URL_STEM/`lsb_release -cs` pgadmin4 main"
PGADMIN_PATH="/etc/apt/sources.list.d/pgadmin4.list"
sudo apt install curl --yes
sudo apt install gnupg2 --yes
wget --quiet -O - $PGP_KEY_URL | sudo apt-key add -
echo "deb $POSTGRES_URL" | sudo tee /etc/apt/sources.list.d/pgdg.list
sudo apt install postgresql-$POSTGRES_VERSION --yes
sudo apt install postgresql-client-$POSTGRES_VERSION --yes
sudo curl $PGADMIN_URL_SHORT | sudo apt-key add
sudo sh -c "echo \"$PGADMIN_TO_ECHO\" > $PGADMIN_PATH && apt update"
sudo apt update
sudo apt install pgadmin4 --yes
Create a new Postgres user.
NU_USERNAME="my_user"
NU_PASSWORD="guest"
NU_QUERY="CREATE USER $NU_USERNAME WITH superuser password '$NU_PASSWORD';"
sudo -u postgres psql -c "$NU_QUERY"
Created the new server and database. I did this manually, using the PGAdmin GUI.
Added test data, a table with a couple of records. I did this with a script.
Followed the steps given in this answer to make the databse remotely accessible.
Steps Already Taken to Connect to the Database REMOTELY
Installed PGAdmin on CLIENT.
Attempted to connect using PGAdmin. I used the "New Server" wizard, and entered:
Host IP Address: 192.168.1.255
Port: 5432 (same as when I set up the database on HOST)
User: my_user
Password: guest
However, when I try to save the connection, PGAdmin responds after a few seconds saying that the connection has timed out.
You have to configure listen_addresses in /var/lib/pgsql/data/postgresql.conf like this:
listen_addresses = '*'
Next make sure your firewall doesn't block the connection by checking if telnet can connect to your server:
$ telnet 192.168.1.255 5432
Connected to 192.168.1.255.
Escape character is '^]'.
If you see Connected network connectivity is ok. Next you have to configure access rights for remote hosts.
I'm very new to Vagrant/ using vm boxes on a daily basis and cant seem to figure out how to access a file that I've shared from my local machine, to the vm, through the browser. I've got a shared folder going to the root home/vagrant which is the directory I'm navigated to when logging in using vagrant ssh. Then opening up a browser and typing in localhost:8000/index.html i get a 404 not found.
I know i'm doing something very wrong and probably using Vagrant incorrectly but at the same time feel like I'm just not pointing my shared folder to the right place.
-- Edit --
So far my vagrantfile a provisioning looks like
Vagrant.configure("2") do |config|
config.vm.box = "scotch/box"
config.vm.network "forwarded_port", guest: 80, host: 9001
config.vm.provision :shell, path: "bootstrap.sh"
config.vm.synced_folder ".", "/var/www"
end
apt-get update
apt-get install -y apache2
if ! [ -L /var/www ]; then
ln -fs /vagrant /var/www
fi
Figured it out, it was a combination of pointing my shared folder to the correct place in the vm using
config.vm.synced_folder "./dist/src", "/var/www"
cding into that directory and then using
php -S <-IP->:8000
I'm trying to create a VM CentOS7 using Vagrant (2.2.3) and Virtual Box (6.0.4), on Windows 10 using the following Vagrant file
Vagrant.configure("2") do |config|
config.vm.box = "bento/centos-7"
config.vm.network "private_network", ip: "192.168.56.3"
config.vm.synced_folder "D://SharedWithVM//CentOS7-Work", "/media/sf_CentOS7-Work", type: "virtualbox"
config.vm.provider "virtualbox" do |vb|
vb.name = "Test"
end
config.vm.provision "shell", path: "./scripts/InstallGuestAdditions.sh"
end
and the InstallGuestAdditions.sh shell script is the follow ..
#!/bin/bash
curl -C - -O http://download.virtualbox.org/virtualbox/6.0.4/VBoxGuestAdditions_6.0.4.iso
sudo mkdir /media/VBoxGuestAdditions
sudo mount -o loop,ro VBoxGuestAdditions_6.0.4.iso /media/VBoxGuestAdditions
sudo sh /media/VBoxGuestAdditions/VBoxLinuxAdditions.run
rm VBoxGuestAdditions_6.0.4.iso
sudo umount /media/VBoxGuestAdditions
sudo rmdir /media/VBoxGuestAdditions
All works fine and the CentOS7 VM is created.
If I check the machine properties about shared directories I can see this
So I'm quite surprised about this path \\?\D:\SharedWithVM\CentOS7-Work.
How should I change my Vagrantfile to obtain a right path?
I've tried to connect at my CentOS 7 VM using vagrant ssh command and all works. Also the command cd /media/sf_CentOS7-Work works fine but no file or directory can be listed or shared between the two systems.
I've tried to create files or directories in Windows 10 and also in CentOS7 VM.
Any suggestion or example will be appreciated.
I'm using virtual box to act as Linux guest to Cassandra DB, and I'm trying to access it through my windows host, however, i don't know what are the right configurations to do that.
on virtual box I'm using "host only networking" to communicate from windows.
Anyone knows how to do these configurations?
Maybe, it's the network configuration of the guest.
In VirtualBox environment, if you want communicate to the guest from the host, the network type of the VM must be "bridged networking" or "host only networking".
You can find more information here : https://www.virtualbox.org/manual/ch06.html.
Access Cassandra on Guest VM from Host OS
For future reference to myself and others, this worked for me for Cassandra v3.10:
http://grokbase.com/t/cassandra/user/14cpyy7bt8/connect-to-c-instance-inside-virtualbox
Once your Guest VM is provisioned with Cassandra, I had a host only network adapter set with IP 192.168.5.10.
Then had to modify /etc/cassandra/cassandra.yaml to set:
From
rpc_address: localhost
To
rpc_address: 192.168.5.10
Then run sudo service cassandra restart and give it 15 seconds...
Then on the guest VM or on the host the following worked:
cqlsh 192.168.5.10
Hope that helps someone.
Vagrantfile for reference
Note it doesn't work for multiple nodes in a cluster yet
# Adjustable settings
## Cassandra cluster settings
mem_mb = "3000"
cpu_count = "2"
server_count = 1
network = '192.168.5.'
first_ip = 10
servers = []
seeds = []
cassandra_tokens = []
(0..server_count-1).each do |i|
name = 'cassandra-node' + (i + 1).to_s
ip = network + (first_ip + i).to_s
seeds << ip
servers << {'name' => name,
'ip' => ip,
'provision_script' => "sleep 15; sudo sed -i -e 's/^rpc_address: localhost/rpc_address: #{ip}/g' /etc/cassandra/cassandra.yaml; sudo service cassandra restart;",
'initial_token' => 2**127 / server_count * i}
end
# Configure VM server
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "ubuntu/xenial64"
servers.each do |server|
config.vm.define server['name'] do |x|
x.vm.provider :virtualbox do |v|
v.name = server['name']
v.customize ["modifyvm", :id, "--memory", mem_mb]
v.customize ["modifyvm", :id, "--cpus" , cpu_count ]
end
x.vm.network :private_network, ip: server['ip']
x.vm.hostname = server['name']
x.vm.provision "shell", path: "provision.sh"
x.vm.provision "shell", inline: server['provision_script']
end
end
end
provision.sh
# install Java and a few base packages
add-apt-repository ppa:openjdk-r/ppa
apt-get update
apt-get install vim curl zip unzip git python-pip -y -q
# Java install - adjust if needed
# apt-get install openjdk-7-jdk -y -q
apt-get install openjdk-8-jdk -y -q
# Install Cassandra
echo "deb http://www.apache.org/dist/cassandra/debian 310x main" | sudo tee -a /etc/apt/sources.list.d/cassandra.sources.list
curl https://www.apache.org/dist/cassandra/KEYS | sudo apt-key add -
sudo apt-get update
sudo apt-get install cassandra -y
sudo service cassandra start
So you are trying to connect to Cassandra from Linux guest in your virtualbox? Or is it the other way around?
Anyways, whatever the direction make sure that you IP is reachable and that the Cassandra ports are open (start with 9042).
I am attempting to make a LAMP box using Vagrant. I have been told that it is quite simple to use. I am completely new to networks and virtual machines and have very little experience with Linux/Ubuntu. I have currently tried following the tutorial on the official documentation page: http://docs.vagrantup.com/v2/getting-started/networking.html.
I have gotten up to the networking article in the documentation and can't seem to get it working.
Now the problem is, due to my inexperience with networking and linux based OS's I have no idea where to begin trouble shooting. I will try to give as much information I can.
I'm running the latest version of Vagrant with the latest version of Virtualbox with Windows 8.1.
As per the tutorial, my current Vagrantfile looks like this:
Vagrant.configure(2) do |config|
config.vm.box = "hashicorp/precise32"
config.vm.provision :shell, path: "bootstrap.sh"
config.vm.network :forwarded_port, host: 4567, guest: 80
end
My bootstrap.sh file looks like this:
#!/usr/bin/env bash
apt-get update
apt-get install -y apache2
if ! [ -L /var/www ]; then
rm -rf /var/www
ln -f /vagrant /var/www
fi
When I went to http://127.0.0.1:4567, it displayed an error page containing this message:
Not Found
The requested URL / was not found on this server.
===================================================
Apache/2.2.22 (Ubuntu) Server at 127.0.0.1 Port 4567
I would rather not edit any config files, unless there was an explanation, as I feel that would be a workaround. But regardless, ANY help would be appreciated. If I need to open up a port, then how do I'm at the point where I'm just considering using XAMPP.
I had same problem. I tried to restart apache from the vagrant box, I got following warning on my terminal.
vagrant#vagrant-ubuntu-trusty-64:~$ sudo service apache2 restart
* Restarting web server apache2
AH00112: Warning: DocumentRoot [/var/www/html] does not exist
AH00558: apache2: Could not reliably determine the server's fully qualified
domain name, using 10.0.2.15. Set the 'ServerName' directive globally to suppress this message
Create a DocumentRoot to fix the 404 issue by creating a directory called /var/www/html
The issue is on /etc/apache2/sites-enabled 000-default file.
Apache2 is pointing to var/www/html and vagrant example to var/www just remove de /html and make a sudo service apache2 restart.
Can you access your web server from inside your virtual machine ?
For example, try curl localhost:80
if curl is not installed, use sudo apt-get install curl on Ubuntu and try again.
Also, have you checked your apache virtual hosts ?
Is there a 000-default file in /etc/apache2/sites-available ?
There are two issues in bootstrap.sh
You need start the web service. You can also vagrant ssh to manually start it
You need make soft link, not hard link.
So the script will be updated as
$ cat bootstrap.sh
#!/usr/bin/env bash
apt-get update
apt-get install -y apache2
if ! [ -L /var/www ]; then
rm -rf /var/www
ln -s /vagrant /var/www
fi
service apache2 start
I've experimented two working solutions:
The first is to change the file /etc/apache2/sites-enabled/000-default.conf modifing DocumentRoot in /var/www instead of /var/www/html
The second is to change the Vagrant file bootstrap.sh in the following way:
#!/usr/bin/env bash
apt-get update
apt-get install -y apache2
if ! [ -L /var/www/html ]; then
rm -rf /var/www/html
ln -fs /vagrant /var/www/html
fi
Beside that, for some reason I've had to change also the configuration of port forwarding in the Vagrantfile, adding the host_ip key, like this:
Vagrant.configure(2) do |config|
config.vm.box = "hashicorp/precise32"
config.vm.provision :shell, path: "bootstrap.sh"
config.vm.network :forwarded_port, host: 4567, guest: 80, host_ip: "127.0.0.1"
end