Mar 042016
 

Installing on Centos 6

I need PostgreSQL 9.3 on my Centos 6 box

yum localinstall https://download.postgresql.org/pub/repos/yum/9.3/redhat/rhel-6-x86_64/pgdg-centos93-9.3-2.noarch.rpm

yum list postgres*
yum install postgresql93-server
service postgresql-9.3 initdb

chkconfig postgresql-9.3 
service postgresql-9.3 start
service postgresql-9.3 status

 

Login to database

sudo -i -u postgres
psql --username=postgres -l 
# list all databases on psql prompt
\list or \l
# list all tables in the current database
\dt

 

Enabling password auth

sudo vi /var/lib/pgsql/data/pg_hba.conf

Find the lines that looks like this, near the bottom of the file:

# pg_hba.conf excerpt (original)
host    all             all             127.0.0.1/32            ident
host    all             all             ::1/128                 ident

Then replace “ident” with “md5”, so they look like this:

# pg_hba.conf excerpt (updated)
host    all             all             127.0.0.1/32            md5
host    all             all             ::1/128                 md5

Save and exit. PostgreSQL is now configured to allow password authentication.

Extensions

IF you need extensions, like RegExp-optimized index extension pg_trgm, you are going to need postgresql-contrib package. Once you have it installed, run:

$ sudo -u postgres sh
$ psql puppetdb -c 'create extension pg_trgm'
$ exit

 

File based backup

service postgresql stop
tar -czf /backup/full_postgres_backup-`date +%Y%m%d`.tar.gz' /var/lib/pgsql/data
service postgresql start

Single DB dump, for example spacewalk database

su - postgres -c 'pg_dump rhnschema |gzip -c > /backup/rhnschema_postgres_backup-`date +%Y%m%d`.sql.gz'

Backing up from cron

Moar scripts here https://github.com/zmielna/backup_scripts

# crontab -l
01 3 * * * /root/bin/postgresql_dump.sh 2>&1 |logger

vim /root/bin/postgresql_dump.sh

#!/bin/bash
#############################################################################
# Simple script to create a snapshot of a PostgreSQL databases.
# Can be run from cron like that
# 01 3 * * * /root/bin/postgresql_dump.sh 2>&1 |logger
# 
# Send bugreports, fixes, enhancements, t-shirts, money, beer & pizza to [email protected]
#############################################################################

#------------ variables
# Directory to store backups in
DST=/backup/dbback_postgresql
# DATABASES="postgres rhnschema"
DATABASES=`su - postgres -c "psql --username=postgres -l -x"|grep Name|grep -v template|cut -d"|" -f2|xargs`

# Any backups older than this will be deleted first
KEEPDAYS=7
DATE=$(date  +%Y-%m-%d)
#------------ code
/bin/logger "Starting PostgreSQL Dump....."
# cd $DST
find ${DST} -type f -mtime +${KEEPDAYS} -exec rm -f {} \;
rmdir $DST/* 2>/dev/null
mkdir -p ${DST}/${DATE}
chown postgres. ${DST}/${DATE}
for db in $DATABASES ; do
        echo -n "Backing up ${db}... " | logger
	su - postgres -c  "pg_dump ${db} |gzip -c > ${DST}/${DATE}/${db}-`date +%Y%m%d`.sql.gz"
        echo -n "Done with $db." | logger
done
/bin/logger "OK, all PostgreSQL dumps done in $DST"
Jan 272016
 

dell rackI keep forgetting syntax for these commands, maybe simply because I’m not using them too often. We mainly use Horizon web interface, do we? Anyway, here we go:

Keystone

keystone user-list
keystone token-get

Glance

glance image-list
glance image-create --min-disk 20 --name="CentOS 7 2015-12-17" \
--disk-format=qcow2 --container-format=bare --property architecture=x86_64 \
--progress --is-public yes --is-protected true \
--file CentOS-7-x86_64-GenericCloud.qcow2

Nova

nova list
nova image-list
nova host-list
nova service-list
nova-manage service describe_resource prod018.openstack.mielnet.pl
nova hypervisor-show prod017.openstack.mielnet.pl
#on the controller
multitail /var/log/nova/{scheduler.log,console.log,conductor.log}
# on the compute node
multitail /var/log/nova/compute.log

 

Neutron

neutron ext-list
neutron security-group-list
neutron security-group-show 626de015-b43f-405f-add2-e9797bcdb1d6
neutron router-list
neutron subnet-list
neutron net-external-list
neutron quota-list
neutron net-list

Cinder

cinder absolute-limits
cinder backup-list
cinder list
cinder service-list
cinder type-list
cinder-manage service list
cinder service-disable prod016.openstack.mielnet.pl cinder-volume
cinder service-disable prod016.openstack.mielnet.pl@gluster cinder-volume
cinder service-list
# I messed up and had to resolve problem in a brutal way, don't try this at home:
mysql -e "update services set deleted = 1 where host like 'prod016.openstack.mielnet.pl%' and disabled = 1 " cinder

 

Swift

swift-init all restart
swift list
head -c 1024 /dev/urandom > data1.file ; swift upload c1 data1.file
head -c 1024 /dev/urandom > data2.file ; swift upload c1 data2.file
head -c 1024 /dev/urandom > data3.file ; swift upload c1 data3.file
swift list
swift list c1

 

New release KILO comes with command “openstack”

openstack user list
openstack role list
openstack service list
openstack endpoint list
openstack endpoint show 75141ca587a64e3bbf76476dc0b28c87

Openvswitch

ovs-vsctl -v
ovs-vsctl show

ovs-vsctl list-br 
ovs-vsctl list-ports br-tun
ovs-vsctl list-ports br-int
ovs-vsctl list-ports br-ex

ovs-vsctl list interface

ovs-ofctl dump-flows br-tun
ovs-ofctl dump-flows br-int
ovs-ofctl dump-flows br-ex

ovs-ofctl show br-ex
ovs-ofctl show br-int
ovs-ofctl show br-tun

ovs-ofctl dump-ports br-ex
ovs-ofctl dump-ports br-tun
ovs-ofctl dump-ports br-int

watch "ovs-ofctl dump-flows br-tun"

ovs-dpctl dump-flows

ovs-appctl fdb/show br-int

ip neighbor 

ip netns exec qrouter-94f86c98-4a32-4e24-a0bc-03e6b330bf09 bash
ip netns exec qrouter-94f86c98-4a32-4e24-a0bc-03e6b330bf09 tcpdump -qnntpi any icmp
ip netns exec qrouter-94f86c98-4a32-4e24-a0bc-03e6b330bf09 tcpdump -e -n -l -i qg-938cc240-04

neutron router-list
neutron l3-agent-list-hosting-router 94f86c98-4a32-4e24-a0bc-03e6b330bf09
neutron l3-agent-router-remove a5ac220d-f1c7-42bc-8b55-db9cdf4bc198 94f86c98-4a32-4e24-a0bc-03e6b330bf09
neutron agent-list
neutron l3-agent-router-add a5ac220d-f1c7-42bc-8b55-db9cdf4bc198 94f86c98-4a32-4e24-a0bc-03e6b330bf09



 

Fixing things that went wrong

tgt-admin -s

mysql -e "update services set deleted = 1 where host like 'prod016.openstack.mielnet.pl%' and disabled = 1 " cinder

# mysql nova
delete from instance_faults where instance_faults.instance_uuid = 'ae7b9c84-4861-47a5-83af-4bd04b8d20c8';
delete from instance_id_mappings where instance_id_mappings.uuid = 'ae7b9c84-4861-47a5-83af-4bd04b8d20c8';
delete from instance_info_caches where instance_info_caches.instance_uuid = 'ae7b9c84-4861-47a5-83af-4bd04b8d20c8';
delete from instance_system_metadata where instance_system_metadata.instance_uuid = 'ae7b9c84-4861-47a5-83af-4bd04b8d20c8';
delete from security_group_instance_association where security_group_instance_association.instance_uuid = 'ae7b9c84-4861-47a5-83af-4bd04b8d20c8';
delete from block_device_mapping where block_device_mapping.instance_uuid = 'ae7b9c84-4861-47a5-83af-4bd04b8d20c8';
delete from fixed_ips where fixed_ips.instance_uuid = 'ae7b9c84-4861-47a5-83af-4bd04b8d20c8';
delete from instance_actions_events where instance_actions_events.action_id in (select id from instance_actions where instance_actions.instance_uuid = 'ae7b9c84-4861-47a5-83af-4bd04b8d20c8');
delete from instance_actions where instance_actions.instance_uuid = 'ae7b9c84-4861-47a5-83af-4bd04b8d20c8';
delete from virtual_interfaces where virtual_interfaces.instance_uuid = 'ae7b9c84-4861-47a5-83af-4bd04b8d20c8';
delete from instances where instances.uuid = 'ae7b9c84-4861-47a5-83af-4bd04b8d20c8';
update instances set deleted='1', vm_state='deleted', deleted_at='now()' where uuid='ae7b9c84-4861-47a5-83af-4bd04b8d20c8';