vitualbox virtual machine installs centos 7 and ssh access self boot and other configuration methods
- 2020-06-12 11:27:53
- OfStack
For convenience, I recently built a VIRTUAL machine based on centos7 with vitualbox. The whole process is relatively simple. Record 1 here.
Download vitualbox
Directly to the website (https: / / www. virtualbox. org/wiki/Downloads) to download it
Download the centos installation package
Also download website (https: / / www. centos. org download /), I download minimal iso
The installation
Installation process is very simple, 1 way default point goes down ok, intermediate memory, partition what can adjust 1 according to need
Configure native ssh access
The vitualbox default resolution is very low and can be optimized by installing enhancement tools. However, since we don't need a graphical interface, there is actually another way to solve this problem, which is to use xshell or putty to remotely login to the virtual machine via ssh.
Open the ssh service
service sshd start
chkconfig sshd on
Start ssh services separately and set ssh to self-start
Turn off the firewall
Just for fun, turn off the firewall.
The firewall operation of centos7 is quite different from previous versions:
sudo systemctl stop firewalld.service
sudo systemctl disable firewalld.service
Turn off the firewall and start automatically
Configure port forwarding
Configure port forwarding under VitualBox: Set - network - advanced - port forwarding, and forward port 22 to the host port, which can be the same as 22 or configured as other ports.
If you need to access other ports of the virtual machine on the host, such as tomcat's 8080, activemq's 61616,8161, you can also configure one here.
View the virtual machine ip
Execute ipconfig on the host, find sudo systemctl disable firewalld.service corresponding ip, and then configure the corresponding ip and port in xshell to access the virtual machine.
Configure the self-starting service
There are many ways to configure self-boot under centos, but we offer one of the simplest here.
Write a script
For example vim opt/app/service sh
#!/bin/bash
export JAVA_HOME=/opt/app/jdk1.8.0_121
sh /opt/app/apache-activemq-5.14.4/bin/activemq start >/opt/app/start.log
Put all the scripts you need to start up here, and you'll only need to work with this script when you want to add a self-starting service.
configuration
chmod +x /opt/app/service.sh
Under centos7 etc/rc. d/rc local also need to add execute permissions:
chmod +x /etc/rc.d/rc.local
Then open/etc/rc d/rc local, in the final script with their own:
/opt/app/service.sh
Save, and you are ready to configure the self-starting service.
After that, we can start with vitualbox's interface free mode and operate freely in xshell.