要在服务器linux 下连接使用oracle 必须先按装oracle客户端。下面来记录下如何安装成功。

一、安装必要的库gcc依赖

yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel gcc python-devel -y

二、用pip安装cx_Oracle

pip install cx_Oracle

三、使用的时候,得装一个oracle客户端
下载地址:
链接:https://pan.baidu.com/s/1o8eQze_cgUKdPJjigOF9-w 密码:0cit

四、上传 oracle_client.zip 到服务器linux

rz  oracle_client.zip

五、移动到 /usr/local/oracle 目录

 	 mkdir -p /usr/local/oracle
    unzip -d /usr/local/oracle/ oracle_client.zip

六、配置环境变量:
(root)

vim /etc/profile

export ORACLE_HOME=/usr/local/oracle                 
export LD_LIBRARY_PATH=/usr/local/oracle
PATH=$PATH
export PATH

source /etc/profile

七、创建软链接

cd /usr/local/oracle
ln -s /usr/local/oracle/libclntsh.so.11.2  libclntsh.so

如果提示存在就不需要创建

八、指定动态链接库
(root)

cd /etc/ld.so.conf.d
touch oracle.conf
vim oracle.conf

九、写入oracle_client的路径

/usr/local/oracle

启动生效

ldconfig

十:配置etc/hosts
增加一行命令

127.0.0.1 hostname

如:127.0.0.1 DT-IMG-1

封装成 sh 脚本 一键安装 install-oracle-client.sh

yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel gcc python-devel -y
pip install cx_Oracle
mkdir -p /usr/local/oracle
unzip -d /usr/local/oracle/ oracle_client.zip

(grep "ORACLE_HOME" -lr /etc/profile) || echo -e "export ORACLE_HOME=/usr/local/oracle\nexport LD_LIBRARY_PATH=/usr/local/oracle\nPATH=$PATH\nexport PATH\n" >>/etc/profile

source /etc/profile

cd /usr/local/oracle && ln -s /usr/local/oracle/libclntsh.so.11.2  libclntsh.so

cd /etc/ld.so.conf.d && touch oracle.conf
> /usr/local/oracle
cat >> /etc/ld.so.conf.d/oracle.conf << EOF
/usr/local/oracle
EOF

ldconfig

Logo

更多推荐