[Openstack] Create virtual machine in console

Open environment variable script

source your_admin-openrc

Create image from file

openstack image create --disk-format qcow2 --public --file ubuntu1604-image.qcow2 ubuntu1604

Create volume for virtual machine from image

openstack volume create --size 11 --image ubuntu1604 ubuntu1604-volume

If flavor not exist, crate one.

openstack flavor create --ram 8096 --vcpus 4 --public --disk 15 m1.large

Create simple network

openstack network create local
openstack subnet create local_subnet --network local --subnet-range 10.10.10.0/24 --allocation-pool start=10.10.10.10,end=10.10.10.20 --dns-nameserver 8.8.8.8

Create vm

Unfortunately when createin vm you have to use network id, not network name

$ openstack network list
+--------------------------------------+-------+--------------------------------------+
| ID | Name | Subnets |
+--------------------------------------+-------+--------------------------------------+
| e5d6ba6a-9866-4089-8125-2d2d90d1e890 | local | ae9e3f32-8e8c-483d-a957-50a0551a7fab |
+--------------------------------------+-------+--------------------------------------+
openstack server create --volume ubuntu1604-volume --flavor m1.large  --nic net-id=network_uuid ubuntu1604-vm

How to edit system images (e.g. Rasbian, Openstack)

We can use guestfish a simple tool to edit images file

Open file with command

guestfish -a OrangePi_2G-IOT_Ubuntu1604_Server_GSMPPP_V1_0.img
Welcome to guestfish, the guest filesystem shell for
editing virtual machine filesystems and disk images.
Type: 'help' for help on commands
 'man' to read the manual
 'quit' to quit the shell

><fs> run
 100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ --:--
><fs> list-filesystems 
/dev/sda1: ext2
/dev/sda2: ext4
><fs> mount /dev/sda2 /
><fs> edit /etc/network

 

PostgreSQL console

Useful Commands

Here are a few commands that can help you get an idea of your current environment:

  • \?: Get a full list of psql commands, including those not listed here.
  • \h: Get help on SQL commands. You can follow this with a specific command to get help with the syntax.
  • \q: Quit the psql program and exit to the Linux prompt.
  • \d: List available tables, views, and sequences in current database.
  • \du: List available roles
  • \dp: List access privileges
  • \dt: List tables
  • \l: List databases
  • \c: Connect to a different database. Follow this by the database name.
  • \password: Change the password for the username that follows.
  • \conninfo: Get information about the current database and connection.

systemd

W Centosie 7 wprowadzono do obsługi servisów systemd, w związku z czym z katalogu /etc/init.d znikneły skrypty do obsługi serwisów usług.

Teraz do obsługi serwisów będziemy korzystać z aplikacji service i systemctl

Aby zobaczyć listę dostępnych serwisów:

$systemctl list-unit-files

Jeśli chcemy zatrzymać/uruchomić jakąś usługę:

$service mariadb start

Aby wyświetlić informacje nt. danej usługi.

$service mariadb status
Redirecting to /bin/systemctl status mariadb.service
● mariadb.service – MariaDB database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor preset: disabled)
Active: active (running) since wto 2016-04-12 15:27:53 CEST; 1s ago
Process: 886 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=0/SUCCESS)
Process: 804 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SUCCESS)
Main PID: 885 (mysqld_safe)
CGroup: /system.slice/mariadb.service
├─ 885 /bin/sh /usr/bin/mysqld_safe –basedir=/usr
└─1042 /usr/libexec/mysqld –basedir=/usr –datadir=/var/lib/mysql –plugin-dir=/usr/lib64/mysql/plugin –log-error=/var/log/mariadb/mariadb.log –pid-file=/…

kwi 12 15:27:50 backup01 mariadb-prepare-db-dir[804]: The latest information about MariaDB is available at http://mariadb.org/.
kwi 12 15:27:50 backup01 mariadb-prepare-db-dir[804]: You can find additional information about the MySQL part at:
kwi 12 15:27:50 backup01 mariadb-prepare-db-dir[804]: http://dev.mysql.com
kwi 12 15:27:50 backup01 mariadb-prepare-db-dir[804]: Support MariaDB development by buying support/new features from MariaDB
kwi 12 15:27:50 backup01 mariadb-prepare-db-dir[804]: Corporation Ab. You can contact us about this at sales@mariadb.com.
kwi 12 15:27:50 backup01 mariadb-prepare-db-dir[804]: Alternatively consider joining our community based development effort:
kwi 12 15:27:50 backup01 mariadb-prepare-db-dir[804]: http://mariadb.com/kb/en/contributing-to-the-mariadb-project/
kwi 12 15:27:50 backup01 mysqld_safe[885]: 160412 15:27:50 mysqld_safe Logging to ‘/var/log/mariadb/mariadb.log’.
kwi 12 15:27:50 backup01 mysqld_safe[885]: 160412 15:27:50 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
kwi 12 15:27:53 backup01 systemd[1]: Started MariaDB database server.

Podstawy administracji Bazami danych – PostgresSQL

Założenia

System operacyjy Centos, RHEL 5 lub 6

Baza PostgreSQL 8 lub 9

Instalacja

Najprostszym (i IMO najlepszym) rozwiązaniem jest skorzystanie z gotowych pakietów rpm zawierających repozytoria YUMa dla kilku popularnych dystrybucji (Centos, RHEL, Fedora, Scientific Linux).

Wchodzimy na strone: http://yum.postgresql.org/repopackages.php, wybieramy pakiet dla naszej dystrybucji,w moim przypadku bÄ™dzie to:http://yum.postgresql.org/9.1/redhat/rhel-5-i386/pgdg-centos91-9.1-4.noarch.rpm, pakiet instalujemy poleceniem rpm -Uvh nazwa_pakietu

rpm -Uvh pgdg-centos91-9.1-4.noarch.rpm
Przygotowywanie…          ########################################### [100%]

1:pgdg-centos91
########################################### [100%]

Mamy juz zainstalowane repozytoria z pakietami dla postgresa. teraz instalujemy sam serwer postgersa.

yum install postgresql91-server
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: sunsite.icm.edu.pl
* epel: ftp.icm.edu.pl
* extras: sunsite.icm.edu.pl
* updates: sunsite.icm.edu.pl
Setting up Install Process
Resolving Dependencies
There are unfinished transactions remaining. You might consider running yum-complete-transaction first to finish them.
The program yum-complete-transaction is found in the yum-utils package.
–> Running transaction check
—> Package postgresql91-server.i386 0:9.1.3-1PGDG.rhel5 set to be updated
–> Processing Dependency: postgresql91 = 9.1.3-1PGDG.rhel5 for package: postgresql91-server
–> Running transaction check
—> Package postgresql91.i386 0:9.1.3-1PGDG.rhel5 set to be updated
–> Processing Dependency: postgresql91-libs = 9.1.3-1PGDG.rhel5 for package: postgresql91
–> Running transaction check
—> Package postgresql91-libs.i386 0:9.1.3-1PGDG.rhel5 set to be updated
–> Finished Dependency Resolution

Dependencies Resolved

=====================================================================================================================================================================================================================
Package                                                    Arch                                        Version                                                  Repository                                     Size
=====================================================================================================================================================================================================================
Installing:
postgresql91-server                                        i386                                        9.1.3-1PGDG.rhel5                                        pgdg91                                        5.2 M
Installing for dependencies:
postgresql91                                               i386                                        9.1.3-1PGDG.rhel5                                        pgdg91                                        1.6 M
postgresql91-libs                                          i386                                        9.1.3-1PGDG.rhel5                                        pgdg91                                        218 k

Transaction Summary
=====================================================================================================================================================================================================================
Install       3 Package(s)
Upgrade       0 Package(s)

Total download size: 7.0 M
Is this ok [y/N]: y
Downloading Packages:
(1/3): postgresql91-libs-9.1.3-1PGDG.rhel5.i386.rpm                                                                                                                                           | 218 kB     00:00
(2/3): postgresql91-9.1.3-1PGDG.rhel5.i386.rpm                                                                                                                                                | 1.6 MB     00:02
(3/3): postgresql91-server-9.1.3-1PGDG.rhel5.i386.rpm                                                                                                                                         | 5.2 MB     00:07
———————————————————————————————————————————————————————————————————————
Total                                                                                                                                                                                636 kB/s | 7.0 MB     00:11
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing     : postgresql91-libs                                                                                                                                                                             1/3
Installing     : postgresql91                                                                                                                                                                                  2/3
Installing     : postgresql91-server                                                                                                                                                                           3/3

Installed:
postgresql91-server.i386 0:9.1.3-1PGDG.rhel5

Dependency Installed:
postgresql91.i386 0:9.1.3-1PGDG.rhel5                                                                  postgresql91-libs.i386 0:9.1.3-1PGDG.rhel5

Complete!

Konfiguracja

Na początku trzeba zainicjować  bazę danych

/etc/init.d/postgresql-9.1 initdb

Inicjowanie bazy danych:                                   [  OK  ]

Edytujemy plik /var/lib/pgsql/9.1/data/pg_hba.conf i zmieniamy linie

host    all             all             127.0.0.1/32            ident

na

host    all             all             127.0.0.1/32            md5

I tak samo będziemy musieli zrobić z każdym ip, który będziemy się logować‚ do tego serwera.

Start bazy:

/etc/init.d/postgresql-9.1 start

Uruchamianie usługi postgresql-9.1:                        [  OK  ]

Zakłaadanie użytkownika

W shellu przechodzimy na użytkownika postgres

su - postgres

i wydajemy polecenie

createuser -P nazwa_uzytkownika

Zakładanie bazy

W shellu przechodzimy na użytkownika postgres

su - postgres

i wydajemy polecenie

createdb -O nazwa_uzytkownika nazwa_bazy

Logowanie

W shellu przechodzimy na użytkownika postgres

su - postgres

i wydajemy polecenie

psql -U nazwa_uzytkownika -h 127.0.0.1 nazwa_bazy

Obsługa certyfikatów w OpenSSL

Zamiana pfx -> certyfikat końcowy i klucz

a) certyfikat końcowy

openssl pkcs12 -in certyfikat.p12 -out certyfikat.cert.pem -nokeys -clcerts

b) klucz

openssl pkcs12 -in certyfikat.p12 -out certyfikat.key.pem -nodes -nocerts

Zamiana cert końcowy + klucz -> pfx

openssl pkcs12 -export -in certyfikat.cert.pem -inkey certyfikat.key.pem
-out certyfikat.p12

Odczyt w konsoli zawartości certyfikatu

openssl x509 -in certyfikat.crt -inform pem -text

PS. Podziękowania za pomoc w ujarzmieniu OpenSSL Łukaszowi W.