Subversion Repositories oidplus

Rev

Rev 1219 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
791 daniel-mar 1
 
2
Easy setup for Oracle DB testing
3
================================
4
 
863 daniel-mar 5
Setup OracleDB Virtual Machine (Developer Days VM 2019)
6
-------------------------------------------------------
791 daniel-mar 7
 
8
Download "DeveloperDaysVM2019-05-31_20.ova" at https://www.oracle.com/database/technologies/databaseappdev-vm.html
9
 
10
Import OVA in Oracle VirtualBox
11
 
12
Set network mode to "Network bridge"
13
 
14
Boot Virtual Machine
15
 
16
Inside the VM, run "ifconfig" to see the IP address of eth0
17
also note the "Pluggable DB" which should be orcl.
18
You need to include it in the PDO configuration settings of OIDplus (see below).
19
 
20
Inside the VM, edit /u01/app/oracle/product/version/db_1/network/admin/listener.ora
21
(this is required so that you can connect to the PDB)
22
==> Add "USE_SID_AS_SERVICE_LISTENER=on" at the end
23
 
24
Type "service oracle restart"
25
==> Password "oracle"
26
 
27
Open sqlcl (SQLplus)
28
 
29
	Username:	sys as sysdba
30
	Password:	oracle
31
 
32
	create user oidplus identified by oidplus;
33
	grant create session to oidplus;
34
	grant create table to oidplus;
35
	grant select any sequence to oidplus;
36
	grant create any sequence to oidplus;
37
	grant all privileges to oidplus;
863 daniel-mar 38
	exit;
791 daniel-mar 39
 
40
Open sqlcl (SQLplus)
41
 
42
	Username:	oidplus
43
	Password:	oidplus
44
 
45
	paste the struct SQL files from OIDplus
46
	Suggestion: Open new console Window
47
		cd Desktop
1244 daniel-mar 48
		wget https://raw.githubusercontent.com/danielmarschall/oidplus/master/plugins/viathinksoft/sqlSlang/oracle/sql/struct.sql
791 daniel-mar 49
		Then copy-paste the contents of this file into sqlcl
50
 
51
	Type "commit" (very important)
52
 
53
Note: Sometimes, the network connection will break. Then you need to enter "ifdown eth0" and "ifup eth0".
54
 
55
 
56
On the OIDplus machine (e.g. Windows)
57
-------------------------------------
58
 
59
On the OIDplus machine, download
60
	https://www.oracle.com/de/database/technologies/instant-client/winx64-64-downloads.html
61
	"Basic package"
62
	instantclient-basic-windows.x64-21.3.0.0.0
63
and extract it anywhere.
64
 
65
Extend the PATH environment variable by adding the directory where you extracted the instantclient
66
 
67
Reboot PC or logout and login to make the PATH environment variable effective
68
 
69
In the php.ini , enable the extension php_pdo_oci
70
	extension=pdo_oci
71
 
72
At OIDplus, edit userdata/baseconfig/config.inc.php:
73
	(IP-Address 10.0.22.152 is an example)
74
	OIDplus::baseConfig()->setValue('DATABASE_PLUGIN',   'PDO');
75
	OIDplus::baseConfig()->setValue('PDO_DSN',           "oci:dbname=(DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = 10.0.22.152)(PORT = 1521)))(CONNECT_DATA = (SID = orcl)))");
76
	OIDplus::baseConfig()->setValue('PDO_USERNAME',      "oidplus"); # Alternative: hr
77
	OIDplus::baseConfig()->setValue('PDO_PASSWORD',      "oidplus"); # Alternative: oracle
78
	OIDplus::baseConfig()->setValue('TABLENAME_PREFIX',  '');
79
 
80
Note: orcl is the PDB (pluggable database) and orclcdb is the CDB (container)
863 daniel-mar 81
 
82
 
83
 
84
Install OracleDB XE 21c Client+Server on an Ubuntu machine
85
----------------------------------------------------------
86
 
87
In this example, the sys password is "oidplus",
88
the SID is "XE", the PDB name is "XEPDB1" (these are the standards in my VM),
89
the port is 1539 (for some reason the default port in my installation),
90
and the PDB username is "oidplus" with password "oidplus".
91
 
92
 
93
1. Download Oracle Database Express Edition
94
 
865 daniel-mar 95
URL https://www.oracle.com/de/database/technologies/appdev/xe/quickstart.html
96
Download "oracle-database-xe-21c-1.0-1.ol8.x86_64.rpm"
863 daniel-mar 97
 
98
2. Create "DEB" file
99
 
865 daniel-mar 100
Install required packages using the command:
101
sudo apt-get install alien libaio1 unixodbc
863 daniel-mar 102
 
865 daniel-mar 103
Convert RPM package format to DEB package format (that is used by Ubuntu) using the command:
104
sudo alien --scripts -d oracle-database-xe-21c-1.0-1.ol8.x86_64.rpm
105
ATTENTION! THIS COMMAND TAKES VERY LONG (APPROX 2 HOURS) AND NEEDS 14 GB HARD DISK SPACE!
863 daniel-mar 106
 
107
3. Create the required chkconfig script using the command:
108
 
865 daniel-mar 109
sudo nano /sbin/chkconfig
110
Copy the following into the file and save:
863 daniel-mar 111
 
865 daniel-mar 112
#!/bin/bash
113
# Oracle 11gR2 XE installer chkconfig hack for Ubuntu
114
file=/etc/init.d/oracle-xe
115
if [[ ! `tail -n1 $file | grep INIT` ]]; then
116
echo >> $file
117
echo '### BEGIN INIT INFO' >> $file
118
echo '# Provides: OracleXE' >> $file
119
echo '# Required-Start: $remote_fs $syslog' >> $file
120
echo '# Required-Stop: $remote_fs $syslog' >> $file
121
echo '# Default-Start: 2 3 4 5' >> $file
122
echo '# Default-Stop: 0 1 6' >> $file
123
echo '# Short-Description: Oracle 11g Express Edition' >> $file
124
echo '### END INIT INFO' >> $file
125
fi
126
update-rc.d oracle-xe defaults 80 01
863 daniel-mar 127
 
128
4. Change the permission of the chkconfig file using the command:
129
 
865 daniel-mar 130
sudo chmod 755 /sbin/chkconfig  
863 daniel-mar 131
 
132
5. Set kernel parameters. Oracle XE requires additional kernel parameters which you need to set using the command:
133
 
865 daniel-mar 134
sudo nano /etc/sysctl.d/60-oracle.conf
135
Copy the following into the file and save:
863 daniel-mar 136
 
865 daniel-mar 137
# Oracle 11g XE kernel parameters  
138
fs.file-max=6815744  
139
net.ipv4.ip_local_port_range=9000 65000  
140
kernel.sem=250 32000 100 128 
141
kernel.shmmax=536870912 
863 daniel-mar 142
 
865 daniel-mar 143
5c. Now load the kernel parameters:
863 daniel-mar 144
 
865 daniel-mar 145
sudo service procps start
863 daniel-mar 146
 
865 daniel-mar 147
7. Set up /dev/shm mount point for Oracle. Create the following file using the command:
863 daniel-mar 148
 
865 daniel-mar 149
sudo nano /etc/rc2.d/S01shm_load
863 daniel-mar 150
 
865 daniel-mar 151
Copy the following into the file and save.
152
 
153
#!/bin/sh
154
case "$1" in
155
start) mkdir /var/lock/subsys 2>/dev/null
156
	touch /var/lock/subsys/listener
157
	rm /dev/shm 2>/dev/null
158
	mkdir /dev/shm 2>/dev/null
159
	mount -t tmpfs shmfs -o size=2048m /dev/shm ;;
160
*) echo error
161
exit 1 ;;
162
esac 
163
 
164
8. Change the permissions of the file using the command:
165
 
166
sudo chmod 755 /etc/rc2.d/S01shm_load
167
 
168
9. Execute the following commands:
169
 
170
sudo ln -s /usr/bin/awk /bin/awk 
171
sudo mkdir /var/lock/subsys 
172
sudo touch /var/lock/subsys/listener 
173
 
174
9. REBOOT your Ubuntu VM.
175
 
863 daniel-mar 176
5d. Verify the new parameters are loaded using:
177
 
865 daniel-mar 178
sudo sysctl -q fs.file-max
863 daniel-mar 179
 
865 daniel-mar 180
You should see the file-max value that you entered earlier.
863 daniel-mar 181
 
865 daniel-mar 182
10. Install the oracle DBMS using the command:
863 daniel-mar 183
 
865 daniel-mar 184
sudo dpkg --install oracle-database-xe-21c_1.0-2_amd64.deb
863 daniel-mar 185
 
186
 
187
 
188
 
189
 
865 daniel-mar 190
--------- TODO: AFTER I TRIED TO RE-DO THIS TUTORIAL ON A CLEAN INSTALLATION, I NOW GET FOLLOWING ERROR: ---------------
191
[SEVERE] An error occurred while configuring the directories for the Oracle home. Verify the execution of the following command: /opt/oracle/product/21c/dbhomeXE/bin/roohctl -enable  
192
dpkg: error processing package oracle-database-xe-21c (--install):
193
 installed oracle-database-xe-21c package post-installation script subprocess returned error exit status 1
194
Processing triggers for libc-bin (2.35-0ubuntu3) ...
195
Errors were encountered while processing:
196
 oracle-database-xe-21c
197
 
1159 daniel-mar 198
Probably the installation scripts in the generated DEB file are broken??? In the postinstall script /var/lib/dpkg/info/oracle-database-xe-21c.postinst we see:
865 daniel-mar 199
su -c "/opt/oracle/product/21c/dbhomeXE/bin/diagsetup clustercheck=false basedir=/opt/oracle oraclehome=/opt/oracle/product/21c/dbhomeXE " >> /dev/null -m 
200
this is wrong ">> /dev/null" will make "-m oracle" invalid?!
201
But why did it work on my first try?
202
----------------------------------------------------------------------------------------------------
863 daniel-mar 203
 
204
 
205
 
206
 
207
11. Configure Oracle using the command:
208
 
865 daniel-mar 209
sudo /etc/init.d/oracle-xe-21c configure 
863 daniel-mar 210
 
211
 
865 daniel-mar 212
 
213
 
214
 
215
 
216
 
217
--------- TODO: AFTER I TRIED TO RE-DO THIS TUTORIAL ON A CLEAN INSTALLATION, I NOW GET FOLLOWING ERROR: ---------------
218
/opt/oracle/product/21c/dbhomeXE/bin/orabase: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory
219
/bin/mkdir: cannot create directory ‘/cfgtoollogs’: Permission denied
220
bash: line 1: /cfgtoollogs/netca/netca_configure_out.log: No such file or directory
221
chmod: cannot access '/cfgtoollogs/netca/netca_configure_out.log': No such file or directory
222
bash: line 1: /cfgtoollogs/netca/netca_configure_out.log: No such file or directory
223
Listener configuration failed. Check log '/cfgtoollogs/netca/netca_configure_out.log' for more details.
224
-------------------------------------
225
 
226
 
227
 
228
 
229
Attention: If the drive has no enough space (approx 5 GB required),
230
then make sure that you put /opt on a separate virtual drive (add to fstab etc.)
231
In case you have a damaged installation because of an installer error,
232
you can try recovering using:
233
rm -rf /opt/oracle /var/lib/dpkg/info/oracle-database-xe-21c.*
234
 
863 daniel-mar 235
12. Enter the following information:
236
 
865 daniel-mar 237
- A password for the SYS and SYSTEM administrative user accounts    ===> ENTER "oidplus" in our example
238
- Confirm password for SYS and SYSTEM administrative user accounts  ===> ENTER "oidplus" in our example
863 daniel-mar 239
 
865 daniel-mar 240
13. You can now visit https://localhost:5500/em/login
863 daniel-mar 241
	Username:	sys
242
	Passwort:	oidplus
243
	Cont.name:	[empty]
244
 
245
14. Setup environment variables by editting your .bashrc file:
246
 
865 daniel-mar 247
nano ~/.bashrc
863 daniel-mar 248
 
865 daniel-mar 249
Add the following lines to the end of the file:
863 daniel-mar 250
 
865 daniel-mar 251
export ORACLE_HOME=/opt/oracle/product/21c/dbhomeXE/
252
export ORACLE_SID=XE
253
#export NLS_LANG=`$ORACLE_HOME/bin/nls_lang.sh`
254
export ORACLE_BASE=/opt/oracle
255
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
256
export PATH=$ORACLE_HOME/bin:$PATH
863 daniel-mar 257
 
258
15. Load the changes by executing your profile:
259
 
865 daniel-mar 260
. ~/.profile
863 daniel-mar 261
 
865 daniel-mar 262
16. Start the Oracle 21c XE:
863 daniel-mar 263
 
865 daniel-mar 264
sudo service oracle-xe-21c start
863 daniel-mar 265
 
865 daniel-mar 266
17. Add user YOURUSERNAME to group dba using the command (not important)
863 daniel-mar 267
 
865 daniel-mar 268
sudo usermod -a -G dba YOURUSERNAME
863 daniel-mar 269
 
270
18. Install php-oci8 on Ubuntu (it is not in the package manager!)
271
 
865 daniel-mar 272
18.1. Download the basic Instant Client
863 daniel-mar 273
 
865 daniel-mar 274
Oracle Website http://www.oracle.com/technetwork/database/database-technologies/instant-client/downloads/index.html
275
Download instantclient-basic-linux.x64-21.6.0.0.0dbru.zip
864 daniel-mar 276
 
865 daniel-mar 277
18.2. Unzip both files on server, in my case, you will get a new folder named "instantclient_12_2"
864 daniel-mar 278
 
865 daniel-mar 279
unzip instantclient-basic-linux.x64-21.6.0.0.0dbru.zip
864 daniel-mar 280
 
865 daniel-mar 281
18.3. Move and rename the instantclient folder to the oracle folder (in Ubuntu it is /opt/oracle)
864 daniel-mar 282
 
865 daniel-mar 283
sudo mkdir /opt/oracle/instantclient
284
sudo mv instantclient_12_2 /opt/oracle/instantclient
864 daniel-mar 285
 
865 daniel-mar 286
18.4. Change rights on folder
863 daniel-mar 287
 
865 daniel-mar 288
chown -R root:www-data /opt/oracle/instantclient
863 daniel-mar 289
 
865 daniel-mar 290
18.5. Check if you have the required packages for installing OCI8
863 daniel-mar 291
 
865 daniel-mar 292
apt install php7.2-dev php-pear build-essential libaio1
863 daniel-mar 293
 
865 daniel-mar 294
18.6a. Add instant client to ld config files
863 daniel-mar 295
 
865 daniel-mar 296
echo /opt/oracle/instantclient > /etc/ld.so.conf.d/oracle-instantclient.conf
863 daniel-mar 297
 
865 daniel-mar 298
18.6b. Update Dynamic Linker Run-Time Bindings
863 daniel-mar 299
 
865 daniel-mar 300
ldconfig
863 daniel-mar 301
 
865 daniel-mar 302
18.7a. Now install OCI8 by pecl
863 daniel-mar 303
 
865 daniel-mar 304
pecl install oci8
863 daniel-mar 305
 
865 daniel-mar 306
18.7b. The OCI8 installation is asking you for the right folder
863 daniel-mar 307
 
865 daniel-mar 308
instantclient,/opt/oracle/instantclient
863 daniel-mar 309
 
865 daniel-mar 310
18.8a. Add oci lib to the cli php config (console php)
863 daniel-mar 311
 
865 daniel-mar 312
echo "extension = oci8.so" >> /etc/php/8.1/cli/php.ini
863 daniel-mar 313
 
865 daniel-mar 314
18.8b. Add oci lib to the apache php config
863 daniel-mar 315
 
865 daniel-mar 316
echo "extension = oci8.so" >> /etc/php/8.1/apache2/php.ini
863 daniel-mar 317
 
865 daniel-mar 318
18.9a. Set environement variables for the cli version (you will need to reboot the server after)
863 daniel-mar 319
 
865 daniel-mar 320
echo "LD_LIBRARY_PATH=\"/opt/oracle/instantclient\"" >> /etc/environment
863 daniel-mar 321
 
865 daniel-mar 322
18.9b. Set environement variables for the apache version
863 daniel-mar 323
 
865 daniel-mar 324
echo "export LD_LIBRARY_PATH=\"/opt/oracle/instantclient\"" >> /etc/apache2/envvars
325
echo "export ORACLE_HOME=\"/opt/oracle/instantclient\"" >> /etc/apache2/envvars
863 daniel-mar 326
 
865 daniel-mar 327
18.10.	Restart Apache
863 daniel-mar 328
 
865 daniel-mar 329
service apache2 restart
863 daniel-mar 330
 
865 daniel-mar 331
19. Start command line shell as the system admin using the command:
863 daniel-mar 332
 
865 daniel-mar 333
sudo sqlplus sys as sysdba
863 daniel-mar 334
 
865 daniel-mar 335
Enter the password that you gave while configuring Oracle earlier. You will now be placed in a SQL environment that only understands SQL commands.
863 daniel-mar 336
 
865 daniel-mar 337
20. Create a regular user account in Oracle using the SQL command:
863 daniel-mar 338
 
865 daniel-mar 339
alter session set container=XEPDB1;
340
create user oidplus identified by oidplus;
341
grant create session to oidplus;
342
grant create table to oidplus;
343
grant select any sequence to oidplus;
344
grant create any sequence to oidplus;
345
grant all privileges to oidplus;
346
exit;
347
 
348
(Note: How did I find the name "XEPDB1"? I looked in /opt/oracle/oradata/XE/ )
349
 
863 daniel-mar 350
21. Start the commandline shell as a regular user using the command:
351
 
865 daniel-mar 352
sqlplus
863 daniel-mar 353
 
865 daniel-mar 354
You will be prompted for a username and password. Try oidplus and oidplus.
863 daniel-mar 355
 
356
22. In OIDplus, run setup. The parameters of the base config file are:
357
 
865 daniel-mar 358
OIDplus::baseConfig()->setValue('OCI_CONN_STR',      'localhost:1539/XEPDB1');
359
OIDplus::baseConfig()->setValue('OCI_USERNAME',      'oidplus');
360
OIDplus::baseConfig()->setValue('OCI_PASSWORD',      'oidplus');
361
// (Very important is port 1539)
863 daniel-mar 362
 
363
23. Install the database (with examples):
364
 
1219 daniel-mar 365
curl -s "http://localhost/oidplus/setup/struct_with_examples.sql.php?prefix=oidplus_&slang=oracle" | sqlplus oidplus/oidplus@localhost:1539/XEPDB1
863 daniel-mar 366
 
865 daniel-mar 367
-------------------------------------------------
863 daniel-mar 368
 
369
Troubleshooting in case the listener doesn't start:
370
- chmod -R 0777 /opt/oracle/product/21c/dbhomeXE/network/
371
- rm -rf /var/tmp/.oracle
372
- Check the output of /etc/init.d/oracle-xe-21c start
864 daniel-mar 373
 
865 daniel-mar 374
Troubleshooting VMware /mnt/hgfs (shared folders) empty:
375
- Run  sudo vmhgfs-fuse .host:/ /mnt/hgfs/ -o allow_other -o uid=1000
864 daniel-mar 376
 
377
When the system has rebooted, and Oracle DB is not started, run
865 daniel-mar 378
	sudo /etc/init.d/oracle-xe-21c start
379
	TODO: How to put this service in the auto-start???
864 daniel-mar 380
	This doesn't work:
381
		# systemctl enable oracle-xe-21c
382
		oracle-xe-21c.service is not a native service, redirecting to systemd-sysv-install.
383
		Executing: /lib/systemd/systemd-sysv-install enable oracle-xe-21c
384
		update-rc.d: error: oracle-xe-21c Default-Start contains no runlevels, aborting.
865 daniel-mar 385
 
386
TODO: I tried the above tutorial with a new Ubuntu VM, but the installation does not work!
387