Como configurar o x11 automático na OCI

A dica de hoje é simples para facilitar a utilização do x11 em instalações ou criações de banco de dados Oracle na OCI utilizando o x11 com o sistema operacional Oracle Linux, abaixo criei um script para automatizar o Xauthority, bash_profile e o export do $DISPLAY para o usuário grid e Oracle.

Instalação dos pacotes necessários:

## Oracle Linux 7
yum install  xorg-x11-server-Xorg xorg-x11-xauth xorg-x11-apps -y
## Oracle Linux 8
dnf config-manager --enable ol8_codeready_builder
yum install  xorg-x11-server-Xorg xorg-x11-xauth xorg-x11-apps -y

Script x11_config.sh criado com o usuário root para automatizar o x11:

#!/bin/bash
#################################################################
#      x11 Automatic for user oracle and grid on OCI.           # 
#                                                               #
# Created by: Cesar Carvalho                                    #
# https://www.cesardba.com.br/                                  #
#################################################################
## rsync for .Xauthority user opc to oracle and grid user
> /home/oracle/.Xauthority
> /home/grid/.Xauthority
rsync -avq /home/opc/.Xauthority /home/oracle/.Xauthority
rsync -avq /home/opc/.Xauthority /home/grid/.Xauthority
chown oracle /home/oracle/.Xauthority
chown grid /home/grid/.Xauthority

## user oracle and grid bash_profile adjuste
sed -i '/DISPLAY/d' /home/oracle/.bash_profile
sed -i '/DISPLAY/d' /home/grid/.bash_profile
su opc -c 'echo export DISPLAY=$DISPLAY' >>/home/oracle/.bash_profile
su opc -c 'echo export DISPLAY=$DISPLAY' >>/home/grid/.bash_profile

Execute o script com o usuário root:

[root@instance-20240915-0012 ~]# chmod 775 x11_config.sh
[root@instance-20240915-0012 ~]# ./x11_config.sh
[root@instance-20240915-0012 ~]# exit 
[opc@instance-20240915-0012 ~]# exit 

Feche todas as conexões ssh abertas com o usuário opc, root, oracle e grid. Conecte via ssh novamente no servidor com o usuário root, execute o script, conecte com oracle e grid para testar o x11:

[opc@instance-20240915-0012 ~]$ sudo -i
[root@instance-20240915-0012 ~]# ./x11_config.sh
[root@instance-20240915-0012 ~]# su - oracle
[oracle@instance-20240915-0012 ~]$ xclock
[opc@instance-20240915-0012 ~]$ sudo -i
[root@instance-20240915-0012 ~]# su - grid
[grid@instance-20240915-0012 ~]$ xclock

Automatizando a execução do script, inserindo no .bash_profile do usuário root, desta forma não será necessário executar manualmente sempre que precisar utilizar o x11 com os usuários oracle e grid:

[root@instance-20240915-0012 ~]# cat /root/.bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH

## script configure x11 automatic for user oracle and grid.
sh /root/x11_config.sh
search previous next tag category expand menu location phone mail time cart zoom edit close