segunda-feira, 17 de novembro de 2014

Install PostgreSQL 9.3 on CentOS 7



Open Terminal ( Applications —> System Tools —> Terminal).
Switch to root user.
[raj@itzgeek~/]$ su -

Dependency:

rpm -Uvh ftp://ftp.muug.mb.ca/mirror/centos/7.0.1406/os/x86_64/Packages/uuid-1.6.2-26.el7.x86_64.rpm

Install PosgreSQL 9.1.3:

PostgreSQL publishes rpm packages for all Linux platforms, their packages are generally fresher than those in the other repository. We need to add the repository on our machine by installing repo rpm.
[root@itzgeek~/]# rpm -Uvh http://yum.postgresql.org/9.3/redhat/rhel-7-x86_64/pgdg-centos93-9.3-1.noarch.rpm
Install PostgreSQL 9.3.1 , enable only PostgreSQL repository to install.
[root@itzgeek~/]#  yum install postgresql93 postgresql93-server postgresql93-libs postgresql93-contrib postgresql93-devel --disablerepo=* --enablerepo=pgdg93

Configuring PostgreSQL 9.3.1 server:

Initialize the PostgreSQL.
[root@itzgeek~/]# /usr/pgsql-9.3/bin/postgresql93-setup initdb
PostgreSQL normally listens on the localhosts only, if would you like to enable the PostgreSQL to listen on all ip addresses; edit the /var/lib/pgsql/9.1/data/postgresql.conf .
[root@itzgeek~/]# vi /var/lib/pgsql/9.3/data/postgresql.conf
Go to Connections and Communications section, find the "listen_address" variable. Uncomment the "listen_addresses" and place "*" instead of "localhost"
Before editing:
#listen_addresses = "localhost"
After editing:
listen_addresses = "*"
Add your network to access database remotely; Edit  /var/lib/pgsql/9.3/data/pg_hba.conf.
[root@itzgeek~/]#  vi /var/lib/pgsql/9.3/data/pg_hba.conf
Add the following line according to your network configuration with md5 password authentication (Enable remote access of database).
# IPv4 local connections: host    all             all             127.0.0.1/32            md5 host    all             all             107.155.94.0/24         md5 # IPv6 local connections: host    all             all             ::1/128                 md5
Restart the PostgreSQL server.
[root@itzgeek~/]# systemctl start postgresql-9.3.service
Confirm the PostgreSQL listening.
[root@itzgeek ~/]# netstat -antup | grep 5432 tcp        0      0 0.0.0.0:5432            0.0.0.0:*               LISTEN      39620/postgres tcp6       0      0 :::5432                 :::*                    LISTEN      39620/postgres
Auto start the service on startup.
[root@itzgeek~/]# systemctl enable postgresql-9.3.service

Creating Database:

Login as postgres user.
[root@geeksite~/]$ su -l postgres
create the database called "test"
-bash-4.2$ createdb test
Login into the database.
-bash-4.2$ psql test
Create a new user called "raj" to manage the databases.
test=# CREATE USER raj WITH SUPERUSER LOGIN PASSWORD 'raj';
Login with the superuser.
sam@geeksite~/$ psql -h localhost -d test -U raj
That's all!. You have successfully installed the PostgreSQL 9.3 on CentOS 7 / RHEL 7.

segunda-feira, 26 de maio de 2014

Remove NULL values from PHP arrays with 1 line [Linux]

Remove NULL values from PHP arrays with 1 line

I had an array with something like the following: Array ( [0] => [1] => test [2] => fun ). But I don't want [0], the empty value in the array.

After searching the web for a good solution, I saw that people were using anywhere from 4 to 10+ lines of code to remove null values from arrays. This is obviously overkill so I decided to tackle the problem myself.

Remove NULL values only

$new_array_without_nulls = array_filter($array_with_nulls, 'strlen');

Remove any FALSE values

This includes NULL values, EMPTY arrays, etc. Thanks to Paul Scott for pointing out this method.

$new_array_without_nulls = array_filter($array_with_nulls);

 

terça-feira, 20 de maio de 2014

Jail only a specific user with vsftpd [Linux]

You have 2 options:

 

chroot_local_user=YES

chroot_list_enable=YES

chroot_list_file=/etc/vsftpd/nonchroot.list

 

# Where file /etc/vsftpd/nonchroot.list should contail the users you don’t want to chroot.

 

OR

 

chroot_list_enable=YES

chroot_list_file=/etc/vsftpd/chroot.list

 

Where the file /etc/vsftpd/chroot.list should contain the users you want to be chrooted to their home. By default all other users should have access to the / (root)

quarta-feira, 30 de abril de 2014

Substituir caracteres por quebra de linha

Quebra de linha manual ( )

 

No Word lica em substituir, ou CTRL + L:

 

Digita o termo de busca, e no outro digite: ^l or ^11

segunda-feira, 14 de abril de 2014

Error: core dump file size limit raised [Linux]

Cause:

core dump file size limit raised to 18446744073709551615 bytes

[notice] suEXEC mechanism enabled (wrapper: /usr/sbin/suexec)

Solution:

Step 7: Remove nss.conf file from httpd conf.d directory
#cd /etc/httpd/conf.d
#mv nss.conf nss.conf.orig
#/etc/init.d/httpd start
Start httpd   [
OK]

segunda-feira, 17 de março de 2014

bash: fork: Recurso temporariamente indisponível [Linux]

Solução:
 
Alterar arquivo /etc/security/limits.conf e descomentar ou adicionar a linha:
 
@users        -       maxlogins       10000
 
Salvar e atualizar as regras:
 
ulimit -a
 


Obs.: As vezes aconteceu comigo, de apresentar o mesmo erro mesmo após a mudança do 'limits', porém existia um shellscript no servidor que criava várias instâncias do processo na memória (ps -aux), o famoso processo zumbie. Resolvi criando um crontab para dar killall -9 a cada 1h.

terça-feira, 1 de outubro de 2013

terça-feira, 27 de agosto de 2013

Upload arquivo para FTP usando Curl [Linux]

#instalação do pacote yum install curl.x86_64 (para 64bits)
yum install curl.i386 (Para 32 bits)
 #Comando:
curl -T uploadfile -u user:passwd ftp://ftp.upload.com/myfile

quarta-feira, 26 de junho de 2013

CentOS – descobrindo qual pacote contém determinado arquivo [Linux]

No CentOS, as vezes necessitamos descobrir qual pacote fornece um determinado arquivo. Para isso, basta usar o comando yum whatprovides …

Por exemplo, para saber qual pacote fornece o arquivo libstdc++.so.5, execute

# yum whatprovides libstdc++.so.5

O resultado deve ser parecido com

Loaded plugins: fastestmirror, priorities
Loading mirror speeds from cached hostfile
* base: mirror.gtdinternet.com
* extras: mirror.gtdinternet.com
* rpmforge: mirror.awanti.com
* updates: mirror.gtdinternet.com
compat-libstdc++-33-3.2.3-61.i386 : Compatibility standard C++ libraries
Repo : base
Matched from:
Other : libstdc++.so.5

No caso acima, o pacote é compat-libstdc++-33-3.2.3-61.i386. Basta agora instalar o pacote com o comando

# yum install compat-libstdc++-33-3.2.3-61.i386

Os comandos acima foram testados no CentOS 5.4
(joaomedeiros.net)

Tmux gerenciador de Janelas SSH [Linux]

Centos install:

#yum install tmux.x86_64 (para versões x64)
#yum install tmux.i386     (para versões x32)

Ubuntu:

#apt-get update && apt-get install tmux

Comandos:

Lista janelas ssh abertas
#tmux ls

Recuperar janela:
#tmux attach -t id_janela
ou
#tmux a -t id_janela

Desconectar janela:
#CTRL + B e depois D

Criar frame vertical:
#CTRL + B e depois %

Criar frame horizontal:
#CTRL + B e depois "

Mudar cursor entre frames:
#CTRL + B <-- ou -->

####

tmux new -d -s decoder3 #Cria janela em dettach
tmux send -t decoder3 ls ENTER #Envia comando para janela em dettach

Reverse SSH Tunneling [Linux]

Have you ever wanted to ssh to your Linux box that sits behind NAT? Now you can with reverse SSH tunneling. This document will show you step by step how to set up reverse SSH tunneling. The reverse SSH tunneling should work fine with Unix like systems.

Let's assume that Destination's IP is 192.168.20.55 (Linux box that you want to access).

You want to access from Linux client with IP 138.47.99.99.

Destination (192.168.20.55) <- |NAT| <- Source (138.47.99.99)

1. SSH from the destination to the source (with public ip) using command below:

ssh -R 19999:localhost:22 sourceuser@138.47.99.99

* port 19999 can be any unused port.

2. Now you can SSH from source to destination through SSH tuneling:

ssh localhost -p 19999

3. 3rd party servers can also access 192.168.20.55 through Destination (138.47.99.99).

Destination (192.168.20.55) <- |NAT| <- Source (138.47.99.99) <- Bob's server

3.1 From Bob's server:

ssh sourceuser@138.47.99.99

3.2 After the sucessful login to Source:

ssh localhost -p 19999

* the connection between destination and source must be alive at all time.


segunda-feira, 24 de junho de 2013

Installing JRE 1.7 in Centos 6.4 and Chrome [Linux]

1. Download the latest RPM version from Oracle download page

2. Go to the folder where you have saved the file:

cd ~/Downloads

3. Install the package using the following command:

yum localinstall jre-7-linux-x64.rpm

4. Now, install Java plugin in Chrome using:

For x64
ln -s /usr/java/default/lib/amd64/libnpjp2.so /opt/google/chrome/plugins

For x86
ln -s /usr/java/default/lib/i386/libnpjp2.so /opt/google/chrome/plugins

5. If you do not have the folder /opt/google/chrome/plugins, just create it using:

mkdir -p /opt/google/chrome/plugins

6. Test it at Java Test Page.

Enjoy!

sexta-feira, 21 de junho de 2013

dpkg missing dependencies [Linux]

In case "dpkg" indicates missing dependencies, complete the installation by executing the following command:


  • sudo apt-get install -f

Screen gerenciador de Janelas SSH [Linux]

Centos install:

#yum install screen.x86_64 (para versões x64)
#yum install screen.i386     (para versões x32)

Ubuntu:

#apt-get update && apt-get install screen


Comandos:

Lista janelas ssh abertas
#screen -ls

Recuperar janela:
#screen -xr iddajanela

Criar janela com alias:
#screen -S nomejanela

Desconectar janela:
#CTRL + A e depois D

Para capturar janelas de outros usuários, deve iniciar o processo adicionando
o screen na última linha do bash_profile do usuário.

#echo screen >> ~root/.bash_profile

quarta-feira, 29 de maio de 2013

Procedure to mount ISO images under Linux

1) You must login as a root user, if not root user then switch to root user using following command:

$ su -

2) Create the directory i.e. mount point:
# mkdir -p /mnt/disk

3) Use mount command as follows to mount iso file called disk1.iso:
# mount -o loop disk1.iso /mnt/disk

4) Change directory to list files stored inside an ISO image:
# cd /mnt/disk
# ls -l