How to install VirtualBox GuestAddition on a guiless CentOs

https://www.if-not-true-then-false.com/2010/install-virtualbox-guest-additions-on-fedora-centos-red-hat-rhel/

  1. sudo yum update kernel* -y
  2. mkdir /media/cdrom
  3. mount -r /dev/cdrom /media/cdrom
  4. sudo rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
  5. sudo yum install gcc kernel-devel kernel-headers dkms make bzip2 perl -y
  6. KERN_DIR=/usr/src/kernels/uname -r
  7. export KERN_DIR
  8. cd /media/cdrom
  9. ./VBoxLinuxAdditions.run
  10. reboot
Advertisements

shell script to install spark 2.1.1

#! /bin/bash
echo download scala
wget http://downloads.typesafe.com/scala/2.12.2/scala-2.12.2.tgz
tar xvf scala-2.12.2.tgz
mv scala-2.12.2 /usr/lib
ln -s /usr/lib/scala-2.12.2 /usr/lib/scala
export PATH=$PATH:/usr/lib/scala/bin
scala -version

echo download spark
wget http://d3kbcqa49mib13.cloudfront.net/spark-2.1.1-bin-hadoop2.7.tgz
tar xvf spark-2.1.1-bin-hadoop2.7.tgz

export SPARK_HOME=$HOME/spark-2.1.1-bin-hadoop2.7
export PATH=$PATH:$SPARK_HOME/bin

firewall-cmd –permanent –zone=public –add-port=6066/tcp
firewall-cmd –permanent –zone=public –add-port=7077/tcp
firewall-cmd –permanent –zone=public –add-port=8080-8081/tcp
firewall-cmd –reload

echo ‘export PATH=$PATH:/usr/lib/scala/bin’ >> .bash_profile
echo ‘export SPARK_HOME=$HOME/spark-2.12.2-bin-hadoop2.7’ >> .bash_profile
echo ‘export PATH=$PATH:$SPARK_HOME/bin’ >> .bash_profile

a script to install basic Java dev tools for Vagrant provision

#! /bin/bash
echo install jdk1.8
wget –no-cookies –no-check-certificate –header “Cookie: oraclelicense=accept-securebackup-cookie” “http://download.oracle.com/otn-pub/java/jdk/8u131-b11/d54c1d3a095b4ff2b6607d096fa80163/jdk-8u131-linux-x64.rpm”
yum localinstall jdk-8u131-linux-x64.rpm -y
touch /etc/profile.d/java.sh
cat <<EOT >> /etc/profile.d/java.sh
export JAVA_HOME=”/usr/java/jdk1.8.0_131″
export JAVA_PATH=”$JAVA_HOME”
export PATH=”$PATH:$JAVA_HOME”
EOT
rm jdk-8u131-linux-x64.rpm

echo install ant
wget http://www.us.apache.org/dist/ant/binaries/apache-ant-1.10.1-bin.tar.gz
tar xvfz apache-ant-1.10.1-bin.tar.gz -C /opt
ln -s /opt/apache-ant-1.10.1 /opt/ant
sh -c ‘echo ANT_HOME=/opt/ant>>/etc/environment’
ln -s /opt/ant/bin/ant /usr/bin/ant
rm apache-ant-1.10.1-bin.tar.gz

echo install python3.6
yum -y groupinstall development
yum -y install https://centos7.iuscommunity.org/ius-release.rpm
yum -y install python36u python36u-pip python36u-devel
# yum -y install python36u-pip
# yum -y install python36u-devel

echo install Ansible
yum -y install ansible

echo set basic vim style
touch /etc/vimrc
cat <<EOT >> /etc/vimrc
filetype plugin indent on
set tabstop=2
set shiftwidth=2
set expandtab
set softtabstop=2
set nowrap
set number
color blue
EOT

echo install maven
wget http://apache.mirror.gtcomm.net/maven/maven-3/3.5.0/binaries/apache-maven-3.5.0-bin.tar.gz
tar xvf apache-maven-3.5.0-bin.tar.gz -C /usr/local
rm apache-maven-3.5.0-bin.tar.gz
ln -s /usr/local/apache-maven-3.5.0/ /usr/local/maven
touch /etc/profile.d/maven.sh
cat <<EOT >> /etc/profile.d/maven.sh
#! /bin/bash

export M2_HOME=/usr/local/maven
export PATH=$PATH:/usr/local/maven/bin
EOT

su -l vagrant -c “mkdir /home/vagrant/.m2”
touch /home/vagrant/.m2/settings.xml
cat <<EOT >> /home/vagrant/.m2/settings.xml
<settings>
<proxies>
<proxy>
<active>true</active>
<protocol>http</protocol>
<host>localhost</host>
<port>3128</port>
<nonProxyHosts>127.0.0.1</nonProxyHosts>
</proxy>
</proxies>
</settings>
EOT

chown vagrant /home/vagrant/.m2/settings.xml

echo install SDKMAN
yum install -y zip unzip
su -l vagrant -c ‘curl -s “https://get.sdkman.io&#8221; | bash’
su -l vagrant -c ‘source /home/vagrant/.sdkman/bin/sdkman-init.sh’

echo install Spring Boot
su -l vagrant -c ‘sdk install springboot’

echo install Intellij
sudo yum install -y xauth libXtst
wget http://download.jetbrains.com/idea/ideaIC-2017.1.3.tar.gz
tar xvf ideaIC-2017.1.3.tar.gz
mv idea-IC-171.4424.56 /usr/lib
ln -sf /usr/lib/idea-IC-171.4424.56 /usr/lib/idea
ln -sf /usr/lib/idea/bin/idea.sh /usr/bin/idea
sed -i ‘s/Xm\(s\|x\)[[:digit:]]*m/Xmx\12048m/g’ /usr/lib/idea/bin/idea.vmoptions /usr/lib/idea/bin/idea64.vmoptions
sed -i ‘s/ReservedCodeCacheSize=[[:digit:]]*m/ReservedCodeCacheSize=700m/g’ /usr/lib/idea/bin/idea.vmoptions /usr/lib/idea/bin/idea64.vmoptions
sed -i ‘4i -XX:MaxPermSize=512m’ /usr/lib/idea/bin/idea.vmoptions /usr/lib/idea/bin/idea64.vmoptions
cat <<EOT >> /etc
sysctl -p

How to create a headless Selenium Server vagrant box

Vagrantfile:

Vagrant.configure(“2”) do |config|
config.vm.box = “bento/ubuntu-16.04”
config.ssh.forward_agent = true

config.vm.network “forwarded_port”, guest: 4444, host: 4444

config.vm.provision ‘setup’, type: ‘shell’, path: ‘setup.sh’
config.vm.provision ‘cleanup’, type: ‘shell’, path: ‘cleanup’

end

setup.sh

#!/bin/sh
set -e

if [ -e /.installed ]; then
echo ‘Already installed.’

else
echo ”
echo ‘INSTALLING’
echo ‘———-‘

# Add Google public key to apt
wget -q -O – “https://dl-ssl.google.com/linux/linux_signing_key.pub&#8221; | sudo apt-key add –

# Add Google to the apt-get source list
echo “deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main” > /etc/apt/sources.list.d/google-chrome.list

# Update app-get
apt-get update

# Install Java, Chrome, Xvfb, and unzip
add-apt-repository ppa:webupd8team/java -y
apt-get update -y
echo “oracle-java8-installer shared/accepted-oracle-license-v1-1 select true” | debconf-set-selections
apt-get install -y oracle-java8-installer
apt-get -y install google-chrome-stable xvfb unzip

# Download and copy the ChromeDriver to /usr/local/bin
cd /tmp
wget -N http://chromedriver.storage.googleapis.com/2.29/chromedriver_linux64.zip
wget http://selenium-release.storage.googleapis.com/3.4/selenium-server-standalone-3.4.0.jar
unzip chromedriver_linux64.zip
mv chromedriver /usr/local/bin
mv selenium-server-standalone-3.4.0.jar /usr/local/bin

# So that running `vagrant provision` doesn’t redownload everything
touch /.installed
fi

echo Create xvfb startup script
touch /etc/systemd/system/xvfb.service
chmod 644 /etc/systemd/system/xvfb.service
cat <<EOT >> /etc/systemd/system/xvfb.service
[Unit]
Description=Xvfb
After=syslog.target network.target

[Service]
Type=oneshot
RemainAfterExit=yes
User=vagrant
ExecStart=/bin/xvfb.sh
Environment=DISPLAY=:10

[Install]
WantedBy=multi-user.target
EOT
touch /bin/xvfb.sh
chown :vagrant /bin/xvfb.sh
chmod 750 /bin/xvfb.sh
cat <<EOT >> /bin/xvfb.sh
#! /bin/bash

Xvfb :10 -screen 0 1366x768x24 -ac &
EOT

echo Create google-chrome startup script
touch /etc/systemd/system/google-chrome.service
chmod 644 /etc/systemd/system/google-chrome.service
cat <<EOT >> /etc/systemd/system/google-chrome.service
[Unit]
Description=Google Chrome
After=xvfb.service

[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/bin/google-chrome.sh
Environment=DISPLAY=:10

[Install]
WantedBy=multi-user.target
EOT
touch /bin/google-chrome.sh
chmod 750 /bin/google-chrome.sh
cat <<EOT >> /bin/google-chrome.sh
#! /bin/bash

google-chrome –remote-debugging-port=92222 &
EOT

echo Create selenium-server startup script
touch /etc/systemd/system/selenium-server.service
chmod 644 /etc/systemd/system/selenium-server.service
cat <<EOT >> /etc/systemd/system/selenium-server.service
[Unit]
Description=Selenium Standalone Server
After=google-chrome

[Service]
Type=oneshot
RemainAfterExit=yes
User=vagrant
ExecStart=/bin/selenium-server.sh

[Install]
WantedBy=multi-user.target
EOT
touch /bin/selenium-server.sh
chown :vagrant /bin/selenium-server.sh
chmod 750 /bin/selenium-server.sh
cat <<EOT >> /bin/selenium-server.sh
#! /bin/bash

export DISPLAY=:10
cd /usr/local/bin
nohup java -jar ./selenium-server-standalone-3.4.0.jar &
EOT

systemctl daemon-reload
systemctl enable xvfb
systemctl enable google-chrome
systemctl enable selenium-server
systemctl start xvfb
systemctl start google-chrome
systemctl start selenium-server

cleanup.sh

#! /bin/bash

apt-get autoclean
apt-get clean
apt-get autoremove

Enable X11 forwarding in Vagrantbox running in Cygwin

References:

http://x.cygwin.com/docs/ug/setup.html

https://coderwall.com/p/ozhfva/run-graphical-programs-within-vagrantboxes

https://superuser.com/questions/310197/how-do-i-fix-a-cannot-open-display-error-when-opening-an-x-program-after-sshi

  1. First, you need to install Cygwin/X packages as below:
    xorg-server
    xinit
    xorg-docs (optional)
    xlaunch (optional)
  2. In your Vagrantfile, add the following:
    Vagrant.config(2) do |vb|
    config.ssh.forward_agent = true
    config.ssh.forward_x11 = true
    end
    reboot your vagrant box by running ‘vagrant reload’
  3. In your vagrant box, install xauth ‘sudo yum install -y xauth’ (assume you are using CentOS)
  4. Start X Server in Cygwin:
    startxwin — -multiwindow -listen tcp &
  5. Pay attention to the output of startxwin, set up DISPLAY environment variable in Cygwin, ex. ‘export DISPLAY=’localhost:0.0’
  6. In your Vagrant box, make sure /etc/ssh/sshd_config has ‘X11Forwarding yes’ set up.
  7. Run a GUI app in Vagrant box such as:
    ssh -Y -p 2222 -i vagrant@localhost xclock
    (You need to make sure your private key has a mode of 600)

Note:

if you get error ‘Permission denied (publickey,gssapi-keyex,gssapi-with-mic)’, you need to make sure ‘config.ssh.forward_agent=true’ is added to your vagrant file and ‘Vagrant reload’ is executed.