This is the 27th day of my participation in the August Genwen Challenge.More challenges in August

🌲 preface

If you are a novice and can’t install Oracle database, you can download the box I packed and install it directly, then you can use Oracle database!!

⭐️ Boxluciferliu/oracle11g⭐ ️

Ha ha 😄, I am lazy again. I wrote a version of ❤️ Oracle one-click installation script ❤️, which greatly reduces the time normally used to install the database. However, installing Linux still takes time and is a repetitive click that is not automated.

So I started surfing the web at 🏄🏻 and found ansible, Cobbler, Vagrant, and more that could be used to automate script installation of Linux hosts. Resolutely, I chose Vagrant, the quickest and easiest to get started.

So, I began to toss. Vagrant successfully used Vagrant to install Linux on your computer, then combined the previous Oracle one-click installation script, and finally achieved 🎉 Vagrantg one-click Installation of Oracle database, completely free 🙌🏻!

🪐 Vagrant can be used at:

  • Vagrant’s Chinese document column
  • A one-line command installation for Linux, an ultra-detailed how-to guide to Vagrant

🌏 Oracle one-click installation script for details:

  • Oracle one-click setup script column
  • After writing over 4000 lines of Shell scripts, I was able to install Oracle RAC with one click!!

Good le, beep beep along while, the text begins ~ ヾ(◍°∇°◍) Blue ゙ 💻 Software needed in this paper:

  • Vagrant
  • VirtualBox

Note: 📢 please install in advance ~

⭐️ Vagrant installs Linux at ⭐️

The first step, of course, is to install Linux. For those of you who have not installed Vagrant, go to the Download page and install it. It’s easy. Won’t play, up to turn over a bit to see the tutorial, I default everyone has installed 👍🏻~

1. Installation directory

First you need to create a directory to place the Vagrantfile and the installation media:

mkdir /Volumes/DBA/vagrant/centos79 -p
Copy the code

Windows system friends 👬🏻, I will not say how to create directory ~

Download Vagrant Box

Suggest going straight toVagrant Box official download pageSearch for downloads. This article uses Centos version 7.9.Of course is to choose the highest downloads, updates closer to the wow 🤩~

Click in, and we choosevirtualboxVersion to download: Note: there are many versions available, including VMware or Parallels

Vagrant adds Box

After downloading, I changed the name of the file to make it easier to distinguishcentos7.9:usevagrant box addCommand to add the downloaded box:

Vagrant box add/Users/LPC/Downloads/centos7.9 - name centos79 vagrant box to the listCopy the code

Note:/ Users/LPC/Downloads/centos7.9Is the storage position of box,–name centos79Creates a logical name.Now that box has been successfully added, you need to configure the Vagrantfile file and upload the installation media.

4. Configure Vagrantfile

Here I will not explain how to configure Vagrantfile. For details, please refer to the official documentation. The configuration is as follows:

cd /Volumes/DBA/vagrant/centos79
cat <<EOF>Vagrantfile Vagrant.configure("2") do |config| config.vm.box = "centos79" config.vm.provision :shell, path: "/Volumes/DBA/vagrant/centos79/scripts/ora_preinstall.sh" config.vm.synced_folder "/Volumes/DBA/vagrant/centos79", "/vagrant" config.vm.network :forwarded_port, guest: 1521, host: 1521 config.vm.network :forwarded_port, guest: 22, host: 22 config.vm.network "public_network", ip: "192.168.1.120" config. The vm. The provider "virtualbox" do | | vb vb. Name = "orcl1" vb. The memory = 4196 vb. Cpus = 2 end end EOF
Copy the code

Here are a few parameters in the configuration file:

  • config.vm.box = “centos79”

Specify the box logical name added above for installing Linux

  • config.vm.provision :shell, path: “/Volumes/DBA/vagrant/centos79/scripts/ora_preinstall.sh”

The configuration is used to automatically execute shell scripts after the Linux system is installed

  • config.vm.synced_folder “/Volumes/DBA/vagrant/centos79”, “/vagrant”

Map a local directory to a Linux host directory

  • config.vm.network :forwarded_port, guest: 1521, host: 1521

Map Linux host port 1521 to local port 1521

  • config.vm.network :forwarded_port, guest: 22, host: 22

Map Linux host port 22 to local port 22

  • Config.vm.net work “public_network”, IP: “192.168.1.120”

Set the network of the host to 192.168.1.120. You are advised to bridge the network to the local host for Internet access

  • config.vm.provider “virtualbox” do |vb|

Set the program to VirtualBox, or paralles

  • vb.name = “orcl”

Configuring host Names

  • vb.memory = 4196

Configuring host Memory

  • vb.cpus = 2

Configuring host cpus

5. Prepare installation media

In the initial directory, create a soft folder and upload the required installation media: Here’s what the following files do:

  • CentOS – 7.9 – x86_64 – Everything – 2009. Iso

Centos ISO file, used to install the local YUM source

  • OracleShellInstall.sh

Oracle one-click installation script, available for download at Github, continue to update 🔥, welcome 👏🏻 Star

  • p13390677_112040_Linux-x86-64_1of7.zip
  • p13390677_112040_Linux-x86-64_2of7.zip

Oracle 11GR2 Database installation package

  • p31537677_112040_Linux-x86-64.zip

Oracle 11GR2 Database PSU patch package

  • p6880880_112000_Linux-x86-64.zip

Oracle OPatch patch pack

  • Rlwrap – 0.42. Tar. Gz

Context switch software, optional installation, not required

Here the installation medium is ready, put here on the line 😄 ~

6. Write Shell scripts defined in Vagrantfile

To automatically install the Oracle database after Linux is successfully installed, prepare shell scripts for invoking the Oracle database after Linux is installed.

mkdir -p /Volumes/DBA/vagrant/centos79/scripts
cd /Volumes/DBA/vagrant/centos79/scripts
cat <<EOF>ora_preinstall.sh #change root password echo oracle | passwd --stdin root #change sshd_config sed -i 's/PasswordAuthentication no/PasswordAuthentication yes/' /etc/ssh/sshd_config systemctl reload sshd.service #mkdir software dir mkdir /soft #cp software to softdir cp /vagrant/soft/* /soft #mount iso to mnt dir mount -o loop /soft/*iso  /mnt #chmod shell script chmod +x /soft/OracleShellInstall.sh #install oracle database cd /soft ./OracleShellInstall.sh -i 192.168.1.120 -opa 31537677 - InstallMode single -DBV 11g EOF
Copy the code

Here’s a little explanation of the steps in the script:

  • A. Change the password of user root
  • B. Configure the SSH service to allow password connection
  • C. Linux Create a soft directory on the host to store the installation media
  • D. Copy the installation media under the mapping directory /vagrant/soft to /soft
  • E. Mount the iso image file of centos7.9
  • F. Grant the Oracle one-click installation script execution permission
  • E. Go to the /soft directory and install the Oracle database according to the one-click installation parameters

At this point, all the pre-configuration is complete, and it’s time for miracles ᕕ(ᐛ)ᕗ ~

❤️ Vagrant launches a one-click install of Oracle ❤️

1, 😏 is very simple, a short line command

vagrant up
Copy the code

To get a sense of it, here’s a GIF: Start copying files a little slow, not the end of the Gif, wait a while to continue;

Due to Gif size limit, only show the PSU patch to install the stop, there is nothing to see, isSuccessful database construction!This is already installed. Now let’s connect to the database and try:✌🏻 can see database created successfully 🎉, PSU patch installed successfully ✌🏻 : This, you think this article is over ❓ of course not, there are dry goods to share 🔥!!

❄️ Vagrant Box ❄️

Vagrant supports box packaging and uploading to the official site for sharing, as well as backup, so you can open it up later.

Next, find out how to pack the Vagrant Box 😄!

1. Prepare before packing

Remove excess installation media to reduce box size and cancel/MNT image mount

rm -rf /soft
umount /mnt
Copy the code

Stop the Oracle database and listener

lsnrctl stop
sas
shudown immediate
Copy the code

Shutting down the Linux Host

vagrant halt
vagrant status
Copy the code

2. Pack a box

throughvagrant packageCommand to pack box:

sudo vagrant package
Copy the code

Note: If you pack the box directly, the box will be as high as 18G after packaging, which is obviously too large.

Use script cleanup to reduce box size:

Create a script file
vi /mnt/purge.sh
chmod +x /mnt/purge.sh
Write the following to the script file
#! /bin/sh
# Zero free space to aid VM compression
printf "STEP: Zero free space to aid VM compression\n"
dd if=/dev/zero of=/EMPTY bs=1M
rm -f /EMPTY

# Remove Linux headers
printf "STEP: Remove Linux headers\n"
rm -rf /usr/src/linux-headers*
 
# Remove Unused locales (edit for your needs, this keeps only en* and pt_BR)
printf "STEP: Remove Unused locales (edit for your needs, this keeps only en* and pt_BR)
find\n" 
find /usr/share/locale/{af,am,ar,as,ast,az,bal,be,bg,bn,bn_IN,br,bs,byn,ca,cr,cs,csb,cy,da,de,de_AT,dz,el,en_AU,en_CA,eo,es,et,et_EE,eu,fa,fi,fo,fr,fur,ga,gez,gl,gu,haw,he,hi,hr,hu,hy,id,is,it,ja,ka,kk,km,kn,ko,kok,ku,ky,lg,lt,lv,mg,mi,mk,ml,mn,mr,ms,mt,nb,ne,n l,nn,no,nso,oc,or,pa,pl,ps,qu,ro,ru,rw,si,sk,sl,so,sq,sr,sr*latin,sv,sw,ta,te,th,ti,tig,tk,tl,tr,tt,ur,urd,ve,vi,wa,wal, wo,xh,zh,zh_HK,zh_CN,zh_TW,zu} -type d -delete
 
# Remove bash history
printf "STEP: Remove bash history\n"
unset HISTFILE
rm -f /root/.bash_history

# Cleanup log files
printf "STEP: Cleanup log files\n"
find /var/log -type f | while read f; do echo -ne ' ' > $f; done;
 
# Whiteout root
printf "STEP: Whiteout root\n"
count=`df --sync -kP / | tail -n1  | awk -F ' ' '{print $4}'`;
count=$((count -= 1))
dd if=/dev/zero of=/tmp/whitespace bs=1024 count=$count;
rm /tmp/whitespace;
 
# Whiteout /boot
printf "STEP: Whiteout /boot\n"
count=`df --sync -kP /boot | tail -n1 | awk -F ' ' '{print $4}'`;
count=$((count -= 1))
dd if=/dev/zero of=/boot/whitespace bs=1024 count=$count;
rm /boot/whitespace;
 
# Whiteout swap 
printf "STEP: Whiteout swap\n"
swappart=`cat /proc/swaps | tail -n1 | awk -F ' ' '{print $1}'`
swapoff $swappart;
dd if=/dev/zero of=$swappart;
mkswap $swappart;
swapon $swappart;
Copy the code

Once you’re done cleaning up, repack the box. View size:

sudo vagrant package --output=centos79-oracle11g
Copy the code

Thorns do not stimulate from18Gbecome3.9 GCool ah, meizi 😄~

To make sure it works, let’s add another test:

mkdir -p /Volumes/DBA/vagrant/oracle11g
vagrant box add /Volumes/DBA/vagrant/centos79/centos79-oracle11g --name oracle11g
cd /Volumes/DBA/vagrant/oracle11g
vagrant init oracle11g
vagrant up --provider=virtualbox
vagrant ssh
su - oracle
Copy the code

After testing, the database can be used, no problem!!

3. Upload and share box

You need to register for Vagrant account. I’ve already registered here. Start uploading! The specific upload process is very simple, it is not demonstratedHarm, upload too slow, first to play for a while, and so on after I come 👋🏻 ~

. It’s been a long time… Finally upload success!! You can go to download and use ~☀️

Download method:luciferliu/oracle11g

There should be more versions of Box in the future, including RAC database, Dataguard, DNS server, OpenFiler server, MySQL, etc.

⭐️ take your time ~ ⭐️

Write in the last

While this approach is not suitable for production installations using 😒, it is extremely convenient for personal test practices using 😄. If you don’t know how to use vagrant Up, you can download my box directly and use it 🎉~

❤️ Finally, I wish you all have a good time. If you have any questions or technical exchanges, you can follow me and chat with me privately ~ ❤️


This is the end of sharing ~

If you think the article is helpful to you, please like it, favorites it, pay attention to it, comment on it, and support it four times with one button. Your support is the biggest motivation for my creation.