Servidor de impressão com cotas no FreeBSD (CUPS + PostgreSQL + PyKota)
Tutorial completo de como configurar um servidor de impressão com cotas no FreeBSD. Abordaremos a instalação e configuração do CUPS, PostgreSQL e PyKota.
Parte 3: Instalar e realizar a configuração básica do PostgreSQL
Instalar o PostgreSQL:
# pkg install postgresql95-server-9.5.14 postgresql95-client-9.5.14
Adicionar a seguinte linha ao arquivo /etc/rc.conf:
Iniciar o PostgreSQL:
# service postgresql initdb
The files belonging to this database system will be owned by user "pgsql".
This user must also own the server process.
The database cluster will be initialized with locale "C".
The default text search configuration will be set to "english".
Data page checksums are disabled.
creating directory /usr/local/pgsql/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
creating template1 database in /usr/local/pgsql/data/base/1 ... ok
initializing pg_authid ... ok
initializing dependencies ... ok
creating system views ... ok
loading system objects' descriptions ... ok
creating collations ... ok
creating conversions ... ok
creating dictionaries ... ok
setting privileges on built-in objects ... ok
creating information schema ... ok
loading PL/pgSQL server-side language ... ok
vacuuming database template1 ... ok
copying template1 to template0 ... ok
copying template1 to postgres ... ok
syncing data to disk ... ok
WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.
Success. You can now start the database server using:
/usr/local/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start
Alterar e descomentar as linhas "#listen_addresses = 'localhost'" e "#port = 5432" no arquivo "postgresql.conf":
# ee /usr/local/pgsql/data/postgresql.conf
ATENÇÃO: o PostgreSQL ainda não está sendo executado, para ter certeza utilize o comando "sockstat":
# sockstat -4l
# service postgresql start
Agora já está sendo executado, para ter certeza utilize novamente o "sockstat":
# sockstat -4l
# passwd pgsql
Fazer teste no PostgreSQL:
Entrar com usuário "pgsql":
# su pgsql
Criar usuário de teste no PostgreSQL:
createuser -sdrP suporte
Criar DB de teste:
createdb -O suporte dbteste
Testes restantes:
pgsql dbteste
dbteste=# \list
View do teste:
# su pgsql
createuser -sdrP suporte
Enter password for new role:
Enter it again:
createdb -O suporte dbteste
$ psql dbteste
dbteste=# \q
exit
Editar o arquivo "pg_hba.conf":
# ee /usr/local/pgsql/data/pg_hba.conf
Adicionar a linha:
"host all all IP/Máscara trust"
# pkg install postgresql95-server-9.5.14 postgresql95-client-9.5.14
Adicionar a seguinte linha ao arquivo /etc/rc.conf:
postgresql_enable="YES"
Iniciar o PostgreSQL:
# service postgresql initdb
The files belonging to this database system will be owned by user "pgsql".
This user must also own the server process.
The database cluster will be initialized with locale "C".
The default text search configuration will be set to "english".
Data page checksums are disabled.
creating directory /usr/local/pgsql/data ... ok
creating subdirectories ... ok
selecting default max_connections ... 100
selecting default shared_buffers ... 128MB
selecting dynamic shared memory implementation ... posix
creating configuration files ... ok
creating template1 database in /usr/local/pgsql/data/base/1 ... ok
initializing pg_authid ... ok
initializing dependencies ... ok
creating system views ... ok
loading system objects' descriptions ... ok
creating collations ... ok
creating conversions ... ok
creating dictionaries ... ok
setting privileges on built-in objects ... ok
creating information schema ... ok
loading PL/pgSQL server-side language ... ok
vacuuming database template1 ... ok
copying template1 to template0 ... ok
copying template1 to postgres ... ok
syncing data to disk ... ok
WARNING: enabling "trust" authentication for local connections
You can change this by editing pg_hba.conf or using the option -A, or
--auth-local and --auth-host, the next time you run initdb.
Success. You can now start the database server using:
/usr/local/bin/pg_ctl -D /usr/local/pgsql/data -l logfile start
Alterar e descomentar as linhas "#listen_addresses = 'localhost'" e "#port = 5432" no arquivo "postgresql.conf":
# ee /usr/local/pgsql/data/postgresql.conf
listen_addresses = 'IP_DO_SERVIDOR' # what IP address(es) to listen on;
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
# (change requires restart)
port = 5432 # (change requires restart)
# comma-separated list of addresses;
# defaults to 'localhost'; use '*' for all
# (change requires restart)
port = 5432 # (change requires restart)
ATENÇÃO: o PostgreSQL ainda não está sendo executado, para ter certeza utilize o comando "sockstat":
# sockstat -4l
USER COMMAND PID FD PROTO LOCAL ADDRESS FOREIGN ADDRESS root sendmail 589 3 tcp4 127.0.0.1:25 *:* root cupsd 574 6 tcp4 *:631 *:* root sshd 565 4 tcp4 *:22 *:* root ntpd 527 21 udp4 *:123 *:* root ntpd 527 22 udp4 IP:123 *:* root ntpd 527 25 udp4 127.0.0.1:123 *:* root snmpd 499 8 udp4 *:161 *:* root snmpd 499 9 tcp4 *:199 *:* _tss tcsd_emu 452 4 tcp4 127.0.0.1:30003 *:* root syslogd 430 7 udp4 *:514Iniciar o serviço do PostgreSQL:
# service postgresql start
Agora já está sendo executado, para ter certeza utilize novamente o "sockstat":
# sockstat -4l
USER COMMAND PID FD PROTO LOCAL ADDRESS FOREIGN ADDRESS pgsql postgres 811 3 tcp4 IP:5432 *:* root sendmail 589 3 tcp4 127.0.0.1:25 *:* root cupsd 574 6 tcp4 *:631 *:* root sshd 565 4 tcp4 *:22 *:* root ntpd 527 21 udp4 *:123 *:* root ntpd 527 22 udp4 IP:123 *:* root ntpd 527 25 udp4 127.0.0.1:123 *:* root snmpd 499 8 udp4 *:161 *:* root snmpd 499 9 tcp4 *:199 *:* _tss tcsd_emu 452 4 tcp4 127.0.0.1:30003 *:* root syslogd 430 7 udp4 *:514 *:*Alterar a senha do "pgsql":
# passwd pgsql
Fazer teste no PostgreSQL:
Entrar com usuário "pgsql":
# su pgsql
Criar usuário de teste no PostgreSQL:
createuser -sdrP suporte
Criar DB de teste:
createdb -O suporte dbteste
Testes restantes:
pgsql dbteste
dbteste=# \list
View do teste:
# su pgsql
createuser -sdrP suporte
Enter password for new role:
Enter it again:
createdb -O suporte dbteste
$ psql dbteste
psql (9.5.14) Type "help" for help. dbteste=# \list List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges -----------+---------+----------+---------+-------+------------------- dbteste | suporte | UTF8 | C | C | postgres | pgsql | UTF8 | C | C | template0 | pgsql | UTF8 | C | C | =c/pgsql + | | | | | pgsql=CTc/pgsql template1 | pgsql | UTF8 | C | C | =c/pgsql + | | | | | pgsql=CTc/pgsql (4 rows) dbteste=#Sair do teste feito:
dbteste=# \q
exit
Editar o arquivo "pg_hba.conf":
# ee /usr/local/pgsql/data/pg_hba.conf
Adicionar a linha:
"host all all IP/Máscara trust"
# IPv4 local connections:
host all all 127.0.0.1/32 trust
host all all IP/24 trust
host all all 127.0.0.1/32 trust
host all all IP/24 trust
--
"There are lots of Linux users who don't care how the kernel works, but only want to use it. That is a tribute to how good Linux is." - Linus Torvalds