1. 安装oracle
安装必须组件
sudo apt-get install alien libaio1 unixodbc
新建管理服务chkconfig的脚本
sudo nano /sbin/chkconfig
粘贴以下内容
#!/bin/bash
# Oracle 11gR2 XE installer chkconfig hack for Ubuntu
file=/etc/init.d/oracle-xe
if [[ ! `tail -n1 $file | grep INIT` ]]; then
echo >> $file
echo '### BEGIN INIT INFO' >> $file
echo '# Provides: OracleXE' >> $file
echo '# Required-Start: $remote_fs $syslog' >> $file
echo '# Required-Stop: $remote_fs $syslog' >> $file
echo '# Default-Start: 2 3 4 5' >> $file
echo '# Default-Stop: 0 1 6' >> $file
echo '# Short-Description: Oracle 11g Express Edition' >> $file
echo '### END INIT INFO' >> $file
fi
update-rc.d oracle-xe defaults 80 01
配置权限
sudo chmod 755 /sbin/chkconfig
设置内核kernel参数
sudo nano /etc/sysctl.d/60-oracle.conf
粘贴以下内容
# Oracle 11g XE kernel parameters
fs.file-max=6815744
net.ipv4.ip_local_port_range=9000 65000
kernel.sem=250 32000 100 128
kernel.shmmax=536870912
使用下面命令通过加载内核餐宿
sudo service procps start
检查新的参数是否加载成功
sudo sysctl -q fs.file-max
设置/dev/shm挂载点
sudo nano /etc/rc2.d/S01shm_load
粘贴以下内容
#!/bin/sh
case "$1" in
start) mkdir /var/lock/subsys 2>/dev/null
touch /var/lock/subsys/listener
rm /dev/shm 2>/dev/null
mkdir /dev/shm 2>/dev/null
mount -t tmpfs shmfs -o size=2048m /dev/shm ;;
*) echo error
exit 1 ;;
esac
添加文件权限
sudo chmod 755 /etc/rc2.d/S01shm_load
重启服务器
reboot
下载deb, 并安装
cd /tmp
wget https://github.com/duanzhichao/ubuntu2004-oracle11g/releases/download/deb/oracle-xe_11.2.0-2_amd64.deb
sudo dpkg --install oracle-xe_11.2.0-2_amd64.deb
按照以下内容配置
Specify the HTTP port that will be used for Oracle Application Express [8080]:
# 定义HTTP网站管理的端口,默认直接回车
Specify a port that will be used for the database listener [1521]:
# 定义数据库监听的端口,默认直接回车
Specify a password to be used for database accounts. Note that the same
password will be used for SYS and SYSTEM. Oracle recommends the use of
different passwords for each database account. This can be done after
initial configuration:
Confirm the password:
# 要求你设置系统账号SYS的SYSTEM的密码
Do you want Oracle Database 11g Express Edition to be started on boot (y/n) [y]:y
# 询问是否设置数据库开机启动启动,默认是开机启动,直接回车
# 成功的话终端输出以下内容
Starting Oracle Net Listener...Done
Configuring database...Done
Starting Oracle Database 11g Express Edition instance...Done
Installation completed successfully.
修改profile
sudo nano /etc/profile
粘贴以下内容
# Oracle Settings
TMP=/tmp; export TMP
TMPDIR=$TMP; export TMPDIR
ORACLE_BASE=/u01/app/oracle; export ORACLE_BASE
ORACLE_HOME=$ORACLE_BASE/product/11.2.0/xe; export ORACLE_HOME
ORACLE_SID=XE; export ORACLE_SID
ORACLE_TERM=xterm; export ORACLE_TERM
PATH=/usr/sbin:$PATH; export PATH
PATH=$ORACLE_HOME/bin:$PATH; export PATH
TNS_ADMIN=$ORACLE_HOME/network/admin
LD_LIBRARY_PATH=$ORACLE_HOME/lib:/lib:/usr/lib; export LD_LIBRARY_PATH
CLASSPATH=$ORACLE_HOME/jlib:$ORACLE_HOME/rdbms/jlib; export CLASSPATH
if [ $USER = "oracle" ]; then
if [ $SHELL = "/bin/ksh" ]; then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
fi
刷新使其生效
sudo source /etc/profile
启动oracle服务, 查看oracle运行状态
sudo systemctl start oracle-xe
sudo systemctl status oracle-xe
# 下面是正常运行的结果
● oracle-xe.service - LSB: Oracle 11g Express Edition
Loaded: loaded (/etc/init.d/oracle-xe; generated)
Active: active (exited) since Sun 2024-04-28 16:02:02 CST; 27min ago
Docs: man:systemd-sysv-generator(8)
Process: 803 ExecStart=/etc/init.d/oracle-xe start (code=exited, status=0/SUCCESS)
CPU: 61ms
2. 修改字符集, 无需要可以跳过
sudo su oracle
sqlplus /as sysdba
SQL> shutdown immediate;
SQL> startup mount;
SQL> ALTER SESSION SET SQL_TRACE=TRUE;
SQL> ALTER SYSTEM ENABLE RESTRICTED SESSION;
SQL> ALTER SYSTEM SET JOB_QUEUE_PROCESSES=0;
SQL> ALTER SYSTEM SET AQ_TM_PROCESSES=0;
SQL> ALTER DATABASE OPEN;
SQL> ALTER DATABASE character set INTERNAL_USE ZHS16GBK;
SQL> shutdown immediate;
SQL> startup
3. 升级apex 4.1或4.2, 无需要可跳过
cd /u01/app/oracle/product/11.2.0/xe/
wget https://github.com/duanzhichao/ubuntu2004-oracle11g/releases/download/apex41/apex_4.1.zip
# or
wget https://github.com/duanzhichao/ubuntu2004-oracle11g/releases/download/apex42/apex_4.2.2.zip
解压apex
mv ./apex ./apex_old
unzip apex_xxx.zip
mv apex_xxx ./apex
安装apex
cd apex
sqlplus / as sysdba
connect / as sysdba
SQL> @apexins SYSAUX SYSAUX TEMP /i/
设置静态资源
sqlplus / as sysdba
connect / as sysdba
SQL> @apex_epg_config /u01/app/oracle/product/11.2.0/xe/
汉化apex
NLS_LANG=American_America.AL32UTF8
export NLS_LANG
echo $NLS_LANG
cd builder/zh-cn
sqlplus / as sysdba
connect / as sysdba
SQL> @load_zh-cn.sql
更新密码
SQL> @apxchpwd
SQL> alter user apex_public_user account unlock;
SQL> alter user apex_public_user identified by 123;
# 如果4.1, APEX_040100; 如果4.2, APEX_040200
SQL> alter session set current_schema = APEX_040200;
4. 创建用户,表空间,导入数据
sqlplus / as sysdba
connect / as sysdba
SQL> create user u1 identified by "123456";
SQL> create tablespace U1 logging datafile '/u01/app/oracle/oradata/XE/U1.dbf' size 50m autoextend on next 50m maxsize 20480m extent management local;
命令行
imp hitb_pm/Hitb123456! file=/home/oracle/hitb_pm.dmp full=y ignore=y