Install Oracle under Linux (command line installation detailed tutorial)

1. Installation under Linux (command line installation)

1. Installation environment

The following installation environment is in the virtual machine test environment, for reference only
Operating system: CentOS 7
Memory: 2G
CPU: Dual-core
Hard disk: 50G

Because rootthe capacity is only 10G, here is a new hard disk, the file format is ext4, the capacity is 50G, mount it /dataunder

2. Download the installation package

So far, the Oracle official website has not been able to find the Oracle12c package.

You can jump to the search resource search page to search for the corresponding version download.

  1. Search keywords Oracle Database 12c, and then select Oracle Database 12c 12.2.0.1.0 ( Oracle Database In-Memory, Oracle Database Vault )to add to the queue;
  2. Click on the upper right corner Continueto jump to the component package selection
  3. choose Oracle Database 12.2.0.1.0. rear platform selectionLinux x86_64
  4. and then all the Continueway toDownload
  5. Open the downloader downloaded in the above steps, select the download path, and it will be downloaded automatically

3. Environment configuration preparation

3.1 Firewall configuration


3.2 selinux configuration

Temporarily closed:setenforce 0

Permanently closed: edited /etc/selinux/config, changed toSELINUX=disabled

3.3 Install dependent packages

yum -y install binutils compat-libcap1 compat-libstdc++-33 compat-libstdc++-33*i686 compat-libstdc++-33*.devel compat-libstdc++-33 compat-libstdc++-33*.devel gcc gcc-c++ glibc glibc*.i686 glibc-devel glibc-devel*.i686 ksh libaio libaio*.i686 libaio-devel libaio-devel*.devel libgcc libgcc*.i686 libstdc++ libstdc++*.i686 libstdc++-devel libstdc++-devel*.devel libXi libXi*.i686 libXtst libXtst*.i686 make sysstat unixODBC unixODBC*.i686 unixODBC-devel unixODBC-devel*.i686

Check the package after installation, a total of 31

rpm -q binutils compat-libcap1 compat-libstdc++-33 gcc gcc-c++ glibc glibc-devel ksh libaio libaio-devel libgcc libstdc++ libstdc++-devel libXi libXtst make sysstat unixODBC unixODBC-devel

3.4 Create users and user groups

Create oinstalland dbausergroup

groupadd oinstall
groupadd dba

create oracleuser

useradd -g oinstall -G dba oracle

set oraclepassword

passwd oracle

View creation results

id oracle

Note: what is detected here uidmust be oracle, gidmust be oinstall, must bedba

3.5 Modify kernel parameters

edit open config file

vim /etc/sysctl.conf

Add to the file:

fs.aio-max-nr=1048576
fs.file-max=6815744
kernel.shmall=524288
kernel.shmmax=2147483647
kernel.sem=250 32000 100 128
kernel.shmmni=4096
kernel.panic_on_oops=1
net.core.rmem_default=262144
net.core.rmem_max=4194304
net.core.wmem_default=262144
net.core.wmem_max=1048576
net.ipv4.conf.all.rp_filter=2
net.ipv4.conf.default.rp_filter=2
fs.aio-max-nr=1048576
net.ipv4.ip_local_port_range=9000 65500

A description of each parameter is attached:

**fs.aio-max-nr:** This parameter limits concurrent outstanding requests and should be set to avoid I/O subsystem failures.
**fs.file-max:** This parameter determines the maximum number of file handles allowed in the system, and the file handle setting represents the number of files that can be opened in the linux system.
**kernel.shmall:** This parameter controls the total number of pages of shared memory that can be used. The Linux shared memory page size is 4KB, and the size of the shared memory segment is an integer multiple of the shared memory page size. The maximum size of a shared memory segment is 16G, so the number of shared memory pages required is 16GB/4KB=16777216KB /4KB=4194304 (pages), that is, 16GB physical memory under a 64Bit system, setting kernel.shmall = 4194304 to meet the requirements.
* *kernel.shmmax: ** is one of the most important parameters in the kernel parameters, used to define the maximum value of a single shared memory segment. The setting should be large enough, setting too low may result in the need to create multiple shared memory segments, which may lead to a decrease in system performance. As for the main reason for the system decline, when the instance is started and the ServerProcess is created, multiple small shared memory segments may cause a slight decrease in system performance at that time (it is necessary to create multiple virtual address segments at startup, in the process When creating, let the process "recognize" multiple segments, there will be some impact), but it will have no impact at other times.
**Official suggested value:**32-bit linux system: the maximum value is 4GB (4294967296bytes)-1byte, which is 4294967295. The recommended value is more than half of the memory, so if it is a 32-bit system, the generally desirable value is 4294967295.
64-bit Linux system: the desirable maximum value is the physical memory value -1 byte, and the recommended value is more than half of the physical memory. For example, if the physical memory is 12GB, the desirable value is 12 1024 1024* 1024-1 =12884901887.
**kernel.shmmni:** This parameter is the maximum number of shared memory segments. The default value of shmmni is 4096, which is generally enough.
kernel.sem:

Take kernel.sem = 250 32000 100 128 as an example:

  • 250 is the value of the parameter semmsl, indicating the maximum number of semaphores that can be contained in a semaphore set.
  • 32000 is the value of the parameter semmns, indicating the maximum number of semaphores allowed in the system.
  • 100 is the value of the parameter semopm, indicating the number of operations that a single semopm() call can perform on a semaphore set.
  • 128 is the value of the parameter semmni, indicating the total number of system semaphore sets.

**net.ipv4.ip_local_port_range:** Indicates the range of IPv4 ports available to the application.
**net.core.rmem_default: **Indicates the default value of the socket receive buffer size.
**net.core.rmem_max:** Indicates the maximum value of the socket receive buffer size.
**net.core.wmem_default: **Indicates the default value of the socket send buffer size.
**net.core.wmem_max:** Indicates the maximum value of the socket send buffer size.

effective configuration

sysctl -p

3.6 Modify configuration

3.6.1 Edit limits.conf

vim /etc/security/limits.conf

Add at the end of the file:

oracle soft nproc 2047
oracle hard nproc 16384
oracle soft nofile 1024
oracle hard nofile 65536
oracle soft stack 10240
oracle hard stack 10240

The first line is to set the soft limit of the number of processes;
the second line is to set the hard limit of the number of processes;
the third line is to set the soft limit of the number of files;
the fourth line is to set the hard limit of the number of files

3.6.2 Edit login

vim /etc/pam.d/login

Add the following

session required /lib64/security/pam_limits.so
session required pam_limits.so

3.6.3 Edit profile

vim /etc/profile

Add the following at the end of the file

if [ $USER = "oracle" ]; then
    if [ $SHELL = "/bin/ksh" ]; then
        ulimit -p 16384 ulimit -n 65536
    else
        ulimit -u 16384 -n 65536
    fi
fi

Make the configuration file take effect

source /etc/profile

3.6.4 Create database directory

mkdir -p /data/server/oracle
chown -R oracle:oinstall /data/server/oracle
chmod -R 775 /data/server/oracle

3.6.5 Configuring Oracle users

Switch to the oracle user

su oracle

Open and edit the environment variable file, configure oracle user environment variables

vim ~/.bash_profile

add at the end

export ORACLE_BASE=/data/server/oracle
export ORACLE_SID=orcl

Make the configuration take effect

source ~/.bash_profile

4. Installation, deployment and configuration

4.1 Upload the Oracle installation package

create a folder

su root
mkdir -p /data/file/oracle
chown -R oracle:oinstall /data/file/oracle
chmod -R 775 /data/file/oracle

# 传输安装包
scp -P 12305 [email protected]:/data/backup/db/oracle/12c/V839960-01.zip /data/file/oracle

4.2 Install the decompression tool

switch to root user

su - root

Install the decompression tool

yum install -y unzip zip

4.3 Unzip the file

Switch to oracle user

su - oracle

unzip files

unzip /data/file/oracle/V839960-01.zip

4.4 Copy the corresponding template

In order not to affect the original file content (the content of the file script will be modified later), copy the corresponding template, of course, this step can also be omitted

su oracle
mkdir /data/file/oracle/database/etc
cp  /data/file/oracle/database/response/* /data/file/oracle/database/etc

Setting permissions

su root
chmod 700 /data/file/oracle/database/etc/*.rsp

4.5 Edit file content

Switch to oracle user

su - oracle

Open and edit db_install.rsp

vim /data/file/oracle/database/etc/db_install.rsp

Find the following items and modify them (modify according to your actual situation, for example, the oracle directory on my side has been adjusted)

oracle.install.option=INSTALL_DB_SWONLY // 安装类型  
UNIX_GROUP_NAME=oinstall // 安装组  
INVENTORY_LOCATION=/data/server/oracle/oraInventory //INVENTORY目录(不填就是默认值)  
ORACLE_HOME=/data/server/oracle/product/12/db_1
ORACLE_BASE=/data/server/oracle
oracle.install.db.InstallEdition=EE     // 企业版本  
oracle.install.db.OSDBA_GROUP=dba  
oracle.install.db.OSOPER_GROUP=oinstall
oracle.install.db.OSBACKUPDBA_GROUP=oinstall  
oracle.install.db.OSDGDBA_GROUP=oinstall  
oracle.install.db.OSKMDBA_GROUP=oinstall
oracle.install.db.OSRACDBA_GROUP=oinstall

oracle.install.db.config.starterdb.type=GENERAL_PURPOSE //数据库类型  
oracle.install.db.config.starterdb.globalDBName=orcl  
oracle.install.db.config.starterdb.SID=orcl
oracle.install.db.config.starterdb.memoryLimit=81920 //自动管理内存的内存(M)  
oracle.install.db.config.starterdb.password.ALL=oracle//设定所有数据库用户使用同一个密码

SECURITY_UPDATES_VIA_MYORACLESUPPORT=false  
DECLINE_SECURITY_UPDATES=true

4.6 Start the installation

execute db_install.rspfile

cd /data/file/oracle/database/
./runInstaller -ignoreSysPrereqs -ignorePrereq -waitforcompletion -showProgress -silent -responseFile /data/file/oracle/database/etc/db_install.rsp
# 可以使用/data/server/oracle/oraInventory/logs/installActions2023-06-20_06-30-58PM.log实时监控日志
tail -f /data/server/oracle/oraInventory/logs/installActions2023-06-20_06-30-58PM.log

When the installation is almost complete, you will be prompted to switch to the root user to execute two scripts. Follow this step

su - root
sh /data/server/oracle/oraInventory/orainstRoot.sh
sh /data/server/oracle/product/12/db_1/root.sh

4.7 Configure oracle user

Switch to the oracle user, open and edit the user edit variable file

su - oracle
vim ~/.bash_profile

Add the following content as required

export ORACLE_BASE=/data/server/oracle
export ORACLE_SID=orcl
export ROACLE_PID=oral12
#export NLS_LANG=AMERICAN_AMERICA.AL32UTF8
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:/usr/lib
export ORACLE_HOME=/data/server/oracle/product/12/db_1
export PATH=$PATH:$ORACLE_HOME/bin
export LANG="zh_CN.UTF-8"
export NLS_LANG="SIMPLIFIED CHINESE_CHINA.AL32UTF8"
export NLS_DATE_FORMAT='yyyy-mm-dd hh24:mi:ss'

Make the configuration take effect

source ~/.bash_profile

Configure monitoring

netca /silent /responsefile /data/file/oracle/database/etc/netca.rsp

start monitoring

lsnrctl start

Modify the silent library file

vim /data/file/oracle/database/etc/dbca.rsp

The content of the file is modified as follows (modified according to the actual situation)

responseFileVersion=/data/server/oracle/product/12/db_1/assistants/rspfmt_dbca_response_schema_v12.2.0
gdbName=orcl
sid=orcl
databaseConfigType=SI  
createAsContainerDatabase=true  
numberOfPDBs=1  
pdbName=orclpdb  
templateName=/data/server/oracle/product/12/db_1/assistants/dbca/templates/General_Purpose.dbc
emExpressPort=5500
omsPort=0
characterSet=AL32UTF8
listeners=LISTENER
memoryPercentage=40
automaticMemoryManagement=false
totalMemory=0

Execute silent library building

dbca -silent -createDatabase  -responseFile  /data/file/oracle/database/etc/dbca.rsp

At this point the database has been successfully installed

4.8 Start the instance

sqlplus / as sysdba
SQL>startup

5. Database startup and shutdown

Only users with sysdba and sysoper system privileges can start and shut down the database.
Before starting the database, you should start the listener, otherwise you cannot use the command mode to manage the database, including starting and closing the database.
Although the database is running normally, clients cannot connect to the database without the listener started.

5.1 start

The complete startup process of the Oracle database includes the following three steps:
Simply put, it is: start the instance –> load the database –> open the database .
Specific instructions:
1. Create and start the instance corresponding to the database.
When an instance is started, a series of background processes and service processes will be created for the instance, and memory structures such as the SGA area will be created in the memory. Only the initialization parameter file is used during instance startup, and whether the database exists has no effect on instance startup. If the initialization parameters are set incorrectly, the instance will fail to start.
2. Load the database for the instance.
When loading the database, the instance will open the control file of the database, and obtain information about the physical structure of the database, such as the database name, the location and name of the data file, etc. from the control file, and prepare for opening the database. If the control file is corrupted, the instance will not be able to load the database. During the database loading stage, the instance does not open the physical files of the database - data files and redo log files.
3. Set the database to open.
When opening a database, the instance opens all datafiles and redo log files that are online. If any data file or redo log file in the control file cannot be opened normally, the database will return an error message, and database recovery is required at this time.
Only after the database is set to open, the database is in a normal state, and ordinary users can access the database at this time. In many cases, the above three steps are not directly completed when starting the database, but are completed step by step, and then necessary management operations are performed, and finally the database enters a normal operating state. Therefore, there are various startup modes for different database maintenance operations.
Because different stages of the Oracle database startup process can perform different maintenance operations on the database, corresponding to our different needs, so different modes are required to start the database.

Detailed explanation of various modes:
1. NoMount mode (starting the instance without loading the database)
command : startup nomount
Explanation : This startup mode will only create the instance and not load the database. Oracle only creates various memory structures and service processes for the instance, not will open any data file. In NoMount mode, only those data dictionary views related to the SGA area can be accessed, including V PARAMETER, V PARAMETER, VP A R A METER V SGA 、 VPROCESS and V PROCESS and VPROCESS and V SESSION, etc., the information in these views is obtained from the SGA area and has nothing to do with the database. Non-installation startup, this method can be executed: rebuild the control file, rebuild the database, read the init.ora file, start the instance, that is, start the SGA and the background process, this kind of startup only needs the init.ora file.
Mode purposes:
(1) Create a new database;
(2) Rebuild control files.

2. Mount mode (load the database but not open the database)
command : startup mount
Explanation : This startup mode will load the database for the instance, but keep the database closed. Because the database control file needs to be opened when loading the database, but neither the data file nor the redo log file can be read and written, so the user cannot operate the database. In Mount mode, only those data dictionary views related to the control file can be accessed, including V THREAD, V THREAD, VTHREADVCONTROLFILE、V D A T A B A S E 、 V DATABASE、V D A T A B A SE , V DATAFILE and V $ LOGFILE, etc., these views are obtained from the control file.
Mode purposes:
(1) Rename data files;
(2) Add, delete or rename redo log files;
(3) Perform complete database recovery operations;
(4) Change the archiving mode of the database.

3. Open mode (normally open the database)
command : startup [open]
Explanation : normally follow 3 steps to start the database.
Mode usage : usually do not do any maintenance on the database, like only doing application development, just use this mode.

4. Forced startup mode
command : startup force
Purpose & Explanation : In some cases, when the database cannot be successfully started using the previous modes, you can try the forced startup mode.
Using the Alter Database statement, you can also switch between startup modes. Moreover, it is also possible to set different states for the database for different operations, such as restricted/unrestricted pumping state, read-only.

Use the Alter Database statement to switch between startup modes.
(1) Switch from NoMount mode to Mount mode (no switch from mount to nomount):
Command: ALTER DATABASE MOUNT;
(2) When the database status is closed, switch to Open mode
Command: ALTER DATABASE OPEN;
(3) In In the Open mode, you can also choose to set the database to an unrestricted state and a restricted state.
Command:
When starting the Open mode, add the restrict keyword: startup restrict
Set or cancel the restricted state: alter system enable\disable restricted session;
Explanation :
The unrestricted state is the state we usually use for application development.
Restricted state, when the opened database is set to restricted state, only users with Create Session and Restricted Session system privileges or users with SYSDBA and SYSPORE system privileges can connect to the database. However, after entering the restricted state, there may still be active normal user sessions in the system.
Uses of restricted status:
(1) Perform data import or export operations;
(2) Temporarily deny ordinary users from accessing the database;
(3) Perform database migration or upgrade operations.
(4) Read-only state
Set the read-only command: alter database open read only;
cancel the read-only command: alter database open read write;
Purpose & Explanation: When a normally opened database is set to read-only status, users can only query data, but cannot modify database objects in any way. In a read-only state, it is possible to ensure that the contents of the data files and redo log files are not modified, but it does not restrict operations that will not write to the data files and redo log files.

5.2 Close

Like the database startup, closing the database and the instance is also divided into 3 steps: closing the database –> unloading the database from the instance –> terminating the instance .
The detailed steps are :
(1) Close the database, oracle writes the content in the redo log cache to the redo log file, and writes the changed data in the database cache to the data file, and then closes all the data files and redo log files, the control file for the database is still open, but users cannot access the database because the database is closed.
(2) Uninstall the database. After closing the database, the routine can be uninstalled. The control file is closed at this time, but the routine still exists.
(3) Terminate the routine, the process terminates, and the memory sga area allocated to the routine is recovered.

1.Nomal (normal shutdown mode)
command : shutdown normal
Explanation : When closing data in a normal way, Oracle performs the following operations:
(1) Prevent any user from establishing a new connection.
(2) Wait for all currently connected users to actively disconnect (in this way, Oracle will not immediately disconnect the current user, and these users still operate related operations) (3) Once all users are disconnected,
then Immediately shuts down, unmounts the database, and terminates the instance. (So, in general, when closing the database in a normal way, all online users should be notified to disconnect as soon as possible)
2. Immediate (immediate shutdown mode)
command : shutdown immediate
Explanation :
(1) prevent any user from establishing a new connection, and prevent the current Connected users start any new transactions.
(2) Oracle does not wait for online users to actively disconnect, forcibly terminates the user's current transaction, and rolls back any uncommitted transactions. (If there are too many uncommitted transactions, this method will take a long time to terminate and roll back transactions)
(3) Directly shut down, unload the database, and terminate the instance.
3. Transactional (transactional shutdown method)
command : shutdown transactional
Explanation : This method is between the normal shutdown method and the immediate shutdown method, the response time will be faster, and the processing will be more appropriate. The execution process is as follows:
(1) Prevent any user from establishing a new connection, and prevent the currently connected user from starting any new transaction.
(2) Wait for all uncommitted active transactions to be committed, and then immediately disconnect the user.
(3) Close and unload the database directly, and terminate the instance.
4. Abort (termination shutdown method)
command : shutdown abort
Explanation : This is a rough shutdown method. When the previous 3 methods cannot be closed, you can try to use the termination method to close the database. But closing the database in this way will lose part of the data information. When the instance is restarted and the database is opened, the background process SMON will perform the instance recovery operation. In general, you should try to avoid using this method to close the database. The execution process is as follows:
(1) Prevent any user from establishing a new connection, and prevent the currently connected user from starting any new transaction.
(2) Immediately terminate the currently executing SQL statement.
(3) Any uncommitted transaction will not be withdrawn.
(4) Directly disconnect all users, close and uninstall the database, and terminate the instance.

Six, sqlplus improvement

During the use of the default sqlplus, it is found that it is difficult to use. The best example is that the backspace key and the up and down keys that fall out of the history command cannot be used. Here is the improvement of the backspace key.

Switch to oracle user

su - oracle

Open and edit the user environment variable configuration file

vim ~/.bash_profile

Add the following code at the end of the file and save and exit

stty erase ^h

Make the configuration file take effect

source ~/.bash_profile

At this time, enter the sqlplus test and find that the backspace key is already available

Seven, navicat remote database

Generally, the database is installed on a remote server, and then connected with the local management software, which needs to be configured at this time.

Under the oracle user, open and edit the listener.ora file (usually in the installation directory)

su oracle
vim /data/server/oracle/product/12/db_1/network/admin/listener.ora

# 然后将其中的HOST改为服务器的IP(这里为了保留之前的配置所以直接在文件后面复制了上面的配置然后作修改)
LISTENER =
  (DESCRIPTION_LIST =
    (DESCRIPTION =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.3.245)(PORT = 1521))
      (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
    )
  )

Open and edit the tnsnames.ora file

su oracle
vim /data/server/oracle/product/12/db_1/network/admin/tnsnames.ora

LISTENER_ORCL =
  (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.3.245)(PORT = 1521))

ORCL =
  (DESCRIPTION =
    (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.3.245)(PORT = 1521))
    (CONNECT_DATA =
      (SERVER = DEDICATED)
      (SERVICE_NAME = orcl)
    )
  )

Then restart Oracle

lsnrctl restart

Guess you like

Origin blog.csdn.net/qq_38478995/article/details/131334560