Linux virtual machine Cenos7 install oracle and use PQSQL for remote connection

1. Go to the official website to download the linux version of the oracle package:  https://www.cnblogs.com/mmzs/p/9030823.html

2. First of all, for ease of use, please use xshell to open two windows, one for the root user and the other for the oracle user (the oracle user will be created in step 7)

       Here, the user who operates root is called 1 window, and the user who operates oracle is called 2 window. Later, it is called 1 window and 2 window.

3. Upload the package to the server and decompress it, and move the decompressed database to the /usr/local directory

unzip linux.x64_11gR2_database_1of2.zip
unzip linux.x64_11gR2_database_2of2.zip
mv database /usr/local/

4. Close selinux

vim /etc/selinux/config
#修改SELINUX=disabled
#查看
setenforce 0

5. Open ports

firewall-cmd --zone=public --add-port=1521/tcp --permanent
#重启
systemctl restart firewalld.service

6. Install oracle-related dependencies

yum install gcc make binutils gcc-c++ compat-libstdc++-33elfutils-libelf-devel elfutils-libelf-devel-static ksh libaio libaio-develnumactl-devel sysstat unixODBC unixODBC-devel pcre-devel –y

7. Add installation users and user groups

groupadd woodie
groupadd dba
useradd -g woodie -G dba oracle
passwd oracle
id oracle

#最后输出信息如下
#uid=1001(oracle) gid=1001(woodie) groups=1001(woodie),1002(dba)

If you need to delete a user or group

userdel 用户名
groupdel 组名

If an error is reported when adding a user: Creating mailbox file: File exists

cd /var/spool/mail
# 删除与你需要创建用户名字相同的文件

8. Modify the kernel parameter configuration file

vim /etc/sysctl.conf

# 末尾添加内容如下
fs.aio-max-nr = 1048576
fs.file-max = 6815744
kernel.shmall = 2097152
kernel.shmmax = 1073741824
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

9. Modify the user's restricted file

vim /etc/security/limits.conf
# 末尾添加的内容如下
oracle           soft    nproc           2047
oracle           hard    nproc           16384
oracle           soft    nofile          1024
oracle           hard    nofile         65536
oracle           soft    stack           10240 
vim /etc/pam.d/login
#在末尾添加的内容如下
session required  /lib64/security/pam_limits.so
session required   pam_limits.so 

10. Modify the /etc/profile file

vim /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

11. Create a directory for oracle installation and a directory for data storage

mkdir -p /usr/local/oracle/product/11.2.0
mkdir /usr/local/oracle
mkdir /usr/local/oracle/oradata
mkdir /usr/local/oracle/inventory
mkdir /usr/local/oracle/fast_recovery_area
chown -R oracle:woodie /usr/local/oracle
chmod -R 775 /usr/local/oracle

12. Use the following command in the 2 window to enter the oracle user

su -l oracle

13. Set the environment variables of the oracle user (2 windows)

vim .bash_profile

#在末尾添加下面的命令
ORACLE_BASE=/usr/local/oracle
ORACLE_HOME=$ORACLE_BASE/product/11.2.0
ORACLE_SID=orcl
PATH=$PATH:$ORACLE_HOME/bin
NLS_LANG=AMERICAN_AMERICA.AL32UTF8
export ORACLE_BASE ORACLE_HOME ORACLE_SID PATH NLS_LANG

# 在保存退出后,使用下面命令加载数据
source .bash_profile

14. Copy the files in the database to the current directory (2 windows)

cp -R /usr/local/database/response/ .

15. Edit the installation response file (2 windows)

vim response/db_install.rsp

#修改以下的内容,这里需要非常的小心,需要慢慢的找字段并修改,不要修改错了,需要与自己的安装目录相对应
oracle.install.option=INSTALL_DB_SWONLY
ORACLE_HOSTNAME=CentOS
UNIX_GROUP_NAME=woodie
INVENTORY_LOCATION=/usr/local/oracle/inventory
SELECTED_LANGUAGES=en,zh_CN
ORACLE_HOME=/usr/local/oracle/product/11.2.0
ORACLE_BASE=/usr/local/oracle
oracle.install.db.InstallEdition=EE
oracle.install.db.DBA_GROUP=dba
oracle.install.db.OPER_GROUP=dba
DECLINE_SECURITY_UPDATES=true

16. Install oracle (2 windows)

#首先进入到/usr/local/database中
cd /usr/local/database/
#执行下面的命令进行安装
./runInstaller -silent -responseFile /home/oracle/response/db_install.rsp -ignorePrereq

# 出现下面内容说明已经安装成功了
/usr/local/oracle/inventory/orainstRoot.sh
/usr/local/oracle/product/11.2.0/root.sh
To execute the configuration scripts:
	 1. Open a terminal window 
	 2. Log in as "root" 
	 3. Run the scripts 
	 4. Return to this window and hit "Enter" key to continue 

Successfully Setup Software.

17. Execute the startup script (1 window)

sh /usr/local/oracle/inventory/orainstRoot.sh
sh /usr/local/oracle/product/11.2.0/root.sh

18. Configure monitoring (2 windows)

netca /silent /responseFile /home/oracle/response/netca.rsp

19. Check whether the port is listening (2 windows)

netstat -tnulp | grep 1521

#没有这个命令,在root用户(1窗口)下使用下面的命令进行安装
yum install net-tools

20 Create a new database and create an instance (2 windows)

vim /home/oracle/response/dbca.rsp

# 修改下面的内容,有些在文件中是注释掉的,需要放开注释在进行修改操作
GDBNAME = "orcl.test"
SID = "orcl"
SYSPASSWORD = "rss123"
SYSTEMPASSWORD = "rss123"
SYSMANPASSWORD = "rss123"
DBSNMPPASSWORD = "rss123"
DATAFILEDESTINATION =/usr/local/oracle/oradata
RECOVERYAREADESTINATION=/usr/local/oracle/fast_recovery_area
NATIONALCHARACTERSET= "UTF8"
TOTALMEMORY = "1683"

21. Configure (2 windows)

dbca -silent -responseFile /home/oracle/response/dbca.rsp

22. Check the progress of the instance (2 windows)

 ps -ef | grep ora_ | grep -v grep

23. View the monitoring status (2 windows)

lsnrctl status

24. Create a login user (2 windows)

sqlplus / as sysdba
# 进入sql成功后输入下面的命令创建一个用户
CREATE  USER woodie IDENTIFIED BY rss123;
alter user woodie account unlock;
grant create session to woodie;
grant dba to woodie;
connect woodie/rss123;

#解决中文乱码
shutdown immediate;
startup mount;
alter system enable restricted session;
alter system set job_queue_processes=0;
alter database open;
alter database character set internal_use AL32UTF8;
shutdown immediate;
startup
alter system disable restricted session;


So far, the basic environment has been set up, but it still cannot be connected through plsql, and the following error will occur:

ORA-12514 TNS listener currently does not recognize the requested service in the connection descriptor

        I have been looking for answers to this question for a long time on the Internet, but almost all the answers are to configure tnsnames.ora locally to modify the ip to achieve the access operation, but this operation is different from the way I operate at work. It is accessed through ip:1521/orcl, which is different from what is said on the Internet. Finally, the configuration found on the Internet is like 25 and 26; the test in step 27 is as I expected.

 

25. Change the monitoring method (1 window), please make a backup of the modified files

        This step is necessary, otherwise plsql cannot connect to the data

# 进入到下面的目录,修改其中的两个文件
cd /usr/local/oracle/product/11.2.0/network/admin


# 修改listener.ora,替换为以下内容, 注意改ip
SID_LIST_LISTENER = (SID_LIST = (SID_DESC = (GLOBAL_DBNAME = orcl)(ORACLE_HOME = /usr/local/oracle/product/11.2.0)(SID_NAME = orcl)))
LISTENER = (DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.142.129)(PORT = 1521)))
ADR_BASE_LISTENER = /usr/local/oracle


#修改tnsnames.ora,替换为以下内容, 注意改ip
orcl =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.142.129)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SID = orcl)
    )
  )

26. Restart the monitor and update the registration

lsnrctl stop                #先关闭监听服务
lsnrctl start               #开启监听服务

27. Test the connection

 

If the connection can be made above, you can directly ignore the following operation

 

28, local plsql connects to the remote database related configuration

After plsql is installed, you cannot directly access the remote database. You need to install the oracle database locally, or the oracle client. Here I strongly recommend installing the oracle client.

There are many online tutorials for installing oracle database, so I won't repeat it. (The oracle database takes up very much memory and disk space)

Install the oracle client as follows

1) Go to the official website to download the client package of the current windows environment

     Official website: https://www.cnblogs.com/mmzs/p/9030823.html

2) The file downloaded by Xunlei is obrareq.cgi.html, which needs to be renamed to .zip and decompressed.

3) After decompression, execute the .exe file. After double-clicking here, it will take a long time to wait patiently

4) The following interface appears, select the first one, and the rest continue to the next step until the installation is complete.

5)打开plsql ---> tools  ---> Preferences

    The oci file corresponds to the directory of the oracle client you installed, here you can generally choose a drop-down selection,

After finishing here, you can connect to oracle.

Guess you like

Origin blog.csdn.net/qq_26896085/article/details/105186971
Recommended