This blog will introduce you to the steps to install the Oracle 11g database on the CentOS 7 operating system, as well as the scripts to create table spaces and users in the Oracle database.
1. Install necessary software and dependencies
First, we need to install some necessary software and dependencies. Execute the following command in the terminal:
yum -y install xorg-x11-xauth
yum -y install libXtst
yum -y install unzip
2. Turn off the firewall and SELinux
To ensure a smooth installation, we need to temporarily turn off the firewall and SELinux:
systemctl stop firewalld
systemctl disable firewalld
vi /etc/selinux/config
# 修改 SELINUX=disabled,用于指示系统在启动时禁用 SELinux。
# 立即将 SELinux 切换到“宽松模式”,允许警告但不会阻止操作
setenforce 0
3. Check and create Swap partition
The Oracle installation process requires some Swap space. You can check if there is enough Swap using the following command:
free -m
If there is insufficient Swap space, it can be solved by allocating a new Swap partition.
4. Modify the host name and hosts file
/etc/hosts
Add a mapping of hostnames and IP addresses to the file :
vi /etc/hosts
# 添加类似这样的行:192.168.20.235 oracle
5. Install Oracle dependency packages
Install the dependency packages required by Oracle:
yum install -y gcc make binutils gcc-c++ compat-libstdc++-33 elfutils-libelf-devel elfutils-libelf-devel-static ksh libaio libaio-devel numactl-devel sysstat unixODBC unixODBC-devel pcre-devel
Confirm that the installation is correct
rpm -qa gcc make binutils gcc-c++ compat-libstdc++-33 elfutils-libelf-devel elfutils-libelf-devel-static ksh libaio libaio-develnumactl-devel sysstat unixODBC unixODBC-devel pcre-devel
6. Create users and groups
Create the required users and groups for Oracle:
groupadd oinstall
groupadd dba
useradd -g oinstall -G dba oracle
passwd oracle
7. Modify kernel parameters
Edit /etc/sysctl.conf
and add the following content, where kernel.shmmax = 1073741824 is half of the local physical memory (2G), in bytes
vi /etc/sysctl.conf
# 增加以下内容
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 1048576
kernel.shmmax = 4294967295
kernel.shmmni = 4096
kernel.sem = 250 32000 100 128
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 262144
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576
# 修改完之后立即执行修改:
sysctl -p
8. Modify user restrictions
Edit /etc/security/limits.conf
the file and add the following content:
vi /etc/security/limits.conf
# 添加用户限制设置
oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
oracle soft stack 10240
9. Modify PAM configuration
Edit /etc/pam.d/login
the file and add the following content:
vi /etc/pam.d/login
# 添加 PAM 配置
session required /lib64/security/pam_limits.so
session required pam_limits.so
10. Modify the /etc/profile file
vi /etc/profile
# 添加以下内容:
if [ $USER = "oracle" ]; then
if [ $SHELL = "/bin/ksh" ]; then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
fi
# 执行生效
source /etc/profile
11. Create necessary directories
Create the directories required by Oracle and set permissions:
mkdir -p /u01/oracle/product/11.2.0
mkdir /u01/oracle/oradata
mkdir /u01/oraInventory
mkdir /u01/oracle/fast_recovery_area
chown -R oracle:oinstall /u01/oracle
chmod -R 775 /u01/oracle
chown -R oracle:oinstall /u01/oraInventory
chmod -R 775 /u01/oraInventory
12. Upload Oracle software package
Upload the Oracle software package 1of2 2of2 to the directory /opt/oracle
:
chown -R oracle:oinstall /opt/oracle
chmod 755 -R /opt/oracle
su - oracle
cd /opt/oracle
unzip linux.x64_11gR2_database_1of2.zip && unzip linux.x64_11gR2_database_2of2.zip
13. Modify oracle user environment variables
Edit ~/.bash_profile
the file and add Oracle related environment variables:
vi ~/.bash_profile
# 添加 Oracle 环境变量
ORACLE_BASE=/u01/oracle
ORACLE_HOME=$ORACLE_BASE/product/11.2.0
ORACLE_SID=orcl
PATH=$PATH:$ORACLE_HOME/bin
export ORACLE_BASE ORACLE_HOME ORACLE_SID PATH
# 执行以下命令加载环境变量
source ~/.bash_profile
14. Configure silent installation files
Edit /opt/oracle/database/response/db_install.rsp
the file and set the options according to your needs.
vi /opt/oracle/database/response/db_install.rsp
# 需要设置的选项如下:
oracle.install.option=INSTALL_DB_SWONLY
ORACLE_HOSTNAME=oracle
UNIX_GROUP_NAME=oinstall
INVENTORY_LOCATION=/u01/oraInventory
SELECTED_LANGUAGES=en,zh_CN
ORACLE_HOME=/u01/oracle/product/11.2.0
ORACLE_BASE=/u01/oracle
oracle.install.db.InstallEdition=EE
oracle.install.db.DBA_GROUP=dba
oracle.install.db.OPER_GROUP=dba
DECLINE_SECURITY_UPDATES=true
15. Install Oracle database software
Execute the installation command and install according to the silent installation file:
cd /opt/oracle/database
./runInstaller -silent -responseFile /opt/oracle/database/response/db_install.rsp -ignorePrereq
16. Complete the installation steps
Execute the following two scripts as the root user:
/u01/oraInventory/orainstRoot.sh
/u01/oracle/product/11.2.0/root.sh
17. Configure listeners
Install the listener silently:
netca /silent /responseFile /opt/oracle/database/response/netca.rsp
18. Create Oracle database
Edit /opt/oracle/database/response/dbca.rsp
the file and set database related options.
vi /opt/oracle/database/response/dbca.rsp
# 修改如下内容
GDBNAME= "orcl"
SID ="orcl"
SYSPASSWORD= "Oracle_123"
SYSTEMPASSWORD= "Oracle_123"
SYSMANPASSWORD= "Oracle_123"
DBSNMPPASSWORD= "Oracle_123"
DATAFILEDESTINATION=/u01/oracle/oradata
RECOVERYAREADESTINATION=/u01/oracle/fast_recovery_area
CHARACTERSET= "AL32UTF8"
# ----TOTALMEMORY ="1638" 为1638MB,物理内存2G*80%。
TOTALMEMORY= "40960"
# 执行如下命令安装
dbca -silent -responseFile /opt/oracle/database/response/dbca.rsp
19. Complete the installation
At this point, your Oracle 11g database has been successfully installed and configured.
Of course, here is the Markdown blog description of the script you provided:
20. Create tablespace
First, the script creates two different types of tablespaces:
20.1 PIS table space
CREATE TABLESPACE PIS
LOGGING
DATAFILE '/u01/oracle/oradata/pis.dbf'
SIZE 2048m
AUTOEXTEND ON
NEXT 512m MAXSIZE UNLIMITED
EXTENT MANAGEMENT LOCAL;
This code creates a tablespace named "PIS" with the following settings:
- Logging: Indicates that database changes will be recorded in the redo log.
- Datafile: Specifies the location and name of the data file associated with the table space.
- Size: Sets the initial size of the table space to 2048 megabytes.
- Autoextend: Enable automatic extension of data files.
- Next: Specifies to expand the size of the data file if needed.
- Maxsize Unlimited: Indicates that the data file can grow indefinitely without a specific upper limit.
- Extent Management Local: Use local extent management to manage table spaces.
20.2 Temporary table space pis_temp
CREATE TEMPORARY TABLESPACE pis_temp
TEMPFILE '/u01/oracle/oradata/pis_temp.dbf'
SIZE 512m
AUTOEXTEND ON
NEXT 512m MAXSIZE UNLIMITED
EXTENT MANAGEMENT LOCAL;
This code creates a temporary tablespace named "pis_temp", similar to the above process, with the following settings:
- Tempfile: Specify the location and name of the temporary data file.
- Size: Sets the initial size of the temporary table space to 512 megabytes.
- Autoextend, Next, Maxsize: similar to the settings in the PIS table space.
- Extent Management Local: Use local extent management again to manage temporary table spaces.
21. Create user
Next, the script creates a user named "PIS" and assigns the user a set of permissions:
create user PIS identified by PIS
default tablespace pis
temporary tablespace pis_temp
profile DEFAULT;
This code creates a user "PIS" with the following properties:
- Identified by PIS: Set the user's password to "PIS".
- Default Tablespace: Set the user's default tablespace to "PIS".
- Temporary Tablespace: Set the user's temporary tablespace to "pis_temp".
- Profile: Assign the default profile "DEFAULT" to the user.
22. Grant permissions
The following sections grant various permissions to user "PIS":
grant connect to PIS;
grant resource to PIS;
grant create procedure to PIS;
grant create sequence to PIS;
grant create synonym to PIS;
grant create trigger to PIS;
grant create type to PIS;
grant create view to PIS;
grant unlimited tablespace to PIS with admin option;
These lines of code grant various permissions to user "PIS":
- Grant CONNECT: Allows users to connect to the database.
- Grant RESOURCE: Provides users with basic resource permissions to create objects.
- Grant CREATE permission: Allows the user to create stored procedures, sequences, synonyms, triggers, types, views, and is granted unlimited tablespace permissions with administrator options.