lunes, 17 de junio de 2013

Installing DataStax Enterprise with Ansible

You can see in other blogs how to install ansible on Ubuntu, this time it is just shown how to install DSE using Ansible.

REQUIREMENTS:

You need to be registered at Datastax so you could get an user/passwd to get Datastax DSE.

It is assumed that you already have Ansible configured and have a servers group named "dse.

You can follow follow post to install ansible: http://kozlex.blogspot.mx/2013/04/installing-and-executing-ansible-on.html


Do a quick test:


$ ansible dse -m ping -u ubuntu
10.40.207.50 | success >> {
    "changed": false,
    "ping": "pong"
}




To install DSE on ubuntu, we need to make sure that:


- JNA is installed

- Oracle java6 is installed
- You have a Datastax user/password. Get it from: http://www.datastax.com/download/register

Installing JNA:

ansible dse -a "sudo apt-get install libjna-java" -u ubuntu -y



Installing Java6 on Ubuntu 12.04 x64:


First enable non-interctive mode

# echo debconf shared/accepted-oracle-license-v1-1 seen true | sudo debconf-set-selections


# echo debconf shared/accepted-oracle-license-v1-1 select true | sudo debconf-set-selections





Install Java:


# sudo apt-get install oracle-java6-installer -y



make sure java is running:


# java -version
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) 64-Bit Server VM (build 20.45-b01, mixed mode)


1. Add to sources list datastax repository with your user/passwd and install dse:


# deb http://your.user.name_company.com:dRteasd34DW@debian.datastax.com/enterprise stable main

curl -L http://debian.datastax.com/debian/repo_key | sudo apt-key add -

# sudo apt-get update

# sudo apt-get install dse-full -y


Enable Solr and Hadoop at SDE

To enable Solr and Hadoop follow variables need to be set to ‘1’ at /etc/default/dse config file:


HADOOP_ENABLED=1
SOLR_ENABLED=1


Start Datastax Enterprise.
Start the service with:


# sudo dse cassandra -s

2. Open new terminal and verify DSE is running and operational.


# sudo dsetool ring -h localhost


Output should look similar to the example below:
Address         DC          Rack        Status State   Load            Owns                Token
127.0.0.1       Solr        rack1       Up     Normal  9.29 MB         100.00%             33015982249869676890




# sudo /etc/init.d/dse stop




2.  To verify that the cluster node is up and running execute:

# nodetool ring -h localhost
Note: Ownership information does not include topology, please specify a keyspace.
Address         DC          Rack        Status State   Load            Owns                Token                                       
127.0.0.1       Analytics   rack1       Up     Normal  4.38 MB         100.00%             42053256256062917965909574476650479427      
#
You can issue hadoop commands to make sure that it is working correctly:

# dse hadoop fs -mkdir my_test_dir

# dse hadoop fs -ls
Found 1 item
drwxrwxrwx   - root root          0 2013-04-23 16:56 /user/root/my_test_dir
#

If the directory created is listed then hadoop service works!

If you want to verify Hadoop deeper you can follow Hadoop demos:



Enjoy!
P.S. You can see the flags of there world!











miércoles, 22 de mayo de 2013

Installing percona ans sysbench on ubuntu encrypting with aesni-enabled

This time we are dividign this section in 4 topics:

1. Installing percona
2. Installing Sysbench
3. Enablingaesni
4.  Ecnrypting /var/lib/mysql
5. Issuing a sysbench test

INSTALLING Percona
From: http://www.percona.com/doc/percona-server/5.5/installation/apt_repo.html

ubuntu@ip-10-40-255-125:~$ gpg --keyserver  hkp://keys.gnupg.net --recv-keys 1C4CBDCDCD2EFD2A
gpg: directory `/home/ubuntu/.gnupg' created
gpg: new configuration file `/home/ubuntu/.gnupg/gpg.conf' created
gpg: WARNING: options in `/home/ubuntu/.gnupg/gpg.conf' are not yet active during this run
gpg: keyring `/home/ubuntu/.gnupg/secring.gpg' created
gpg: keyring `/home/ubuntu/.gnupg/pubring.gpg' created
gpg: requesting key CD2EFD2A from hkp server keys.gnupg.net
gpg: /home/ubuntu/.gnupg/trustdb.gpg: trustdb created
gpg: key CD2EFD2A: public key "Percona MySQL Development Team <mysql-dev@percona.com>" imported
gpg: Total number processed: 1
gpg:               imported: 1
ubuntu@ip-10-40-255-125:~$ gpg -a --export CD2EFD2A | sudo apt-key add -
OK
ubuntu@ip-10-40-255-125:~$

Add this to /etc/apt/sources.list, replacing VERSION with the name of your distribution:

deb http://repo.percona.com/apt precise  main
deb-src http://repo.percona.com/apt precise main
Remember to update the local cache:

$ apt-get update
After that you can install the server and client packages

# apt-get install percona-server-server-5.5 percona-server-client-5.5



Start and stop percona to verify that it is working:





root@ip-10-40-255-125:/home/ubuntu# sudo service mysqld restart
mysqld: unrecognized service
root@ip-10-40-255-125:/home/ubuntu# sudo service mysql restart
 * Stopping MySQL (Percona Server) mysqld                                                                                                                                              [ OK ]
 * Starting MySQL (Percona Server) database server mysqld                                                                                                                              [ OK ]
 * Checking for corrupt, not cleanly closed and upgrade needing tables.
root@ip-10-40-255-125:/home/ubuntu# sudo service mysql status
 * /usr/bin/mysqladmin  Ver 8.42 Distrib 5.5.30, for Linux on x86_64
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Server version        5.5.30-30.2
Protocol version    10
Connection        Localhost via UNIX socket
UNIX socket        /var/run/mysqld/mysqld.sock
Uptime:            5 sec

Threads: 1  Questions: 106  Slow queries: 0  Opens: 171  Flush tables: 1  Open tables: 41  Queries per second avg: 21.200
root@ip-10-40-255-125:/home/ubuntu#


2. INSTALLING SYSBENCH

root@ip-10-40-255-125:/home/ubuntu# apt-get install sysbench
Reading package lists... Done
Building dependency tree      
Reading state information... Done
The following NEW packages will be installed:
  sysbench
0 upgraded, 1 newly installed, 0 to remove and 86 not upgraded.
Need to get 66.0 kB of archives.
After this operation, 170 kB of additional disk space will be used.
Get:1 http://us-east-1.ec2.archive.ubuntu.com/ubuntu/ precise/universe sysbench amd64 0.4.12-1build2 [66.0 kB]
Fetched 66.0 kB in 0s (398 kB/s)   
Selecting previously unselected package sysbench.
(Reading database ... 62104 files and directories currently installed.)
Unpacking sysbench (from .../sysbench_0.4.12-1build2_amd64.deb) ...
Processing triggers for man-db ...
Setting up sysbench (0.4.12-1build2) ...
root@ip-10-40-255-125:/home/ubuntu# sys
sysbench  sysctl   
root@ip-10-40-255-125:/home/ubuntu# sysbench

That is it! Later we will prepare a database and execute a test


3. ENABLING AESNI

ubuntu@ip-10-40-255-125:~$ lsmod }| grep aesni
Usage: lsmod
ubuntu@ip-10-40-255-125:~$ lsmod | grep aesni
aesni_intel            55664  0
cryptd                 20530  1 aesni_intel
aes_x86_64             17255  1 aesni_intel
ubuntu@ip-10-40-255-125:~$

4. encrypting with zNcrypt

Let's say it is already installed and /mnt/encrypt is our encryption directory.

Add the rule zncrypt acl --add --rule="ALLOW @mysql * /usr/sbin/mysqld"
as well as "ALLOW @mysql * /usr/bin/mysqld_safe --shell=/bin/dash"



root@ip-10-40-255-125:/home/ubuntu# zncrypt acl --add --rule="ALLOW @mysql * /usr/sbin/mysqld"
Type MASTER passphrase:
1 rule(s) were added
root@ip-10-40-255-125:/home/ubuntu# sudo service mysql stop
 * Stopping MySQL (Percona Server) mysqld                                                                                                                                              [ OK ]
root@ip-10-40-255-125:/home/ubuntu# zncrypt encrypt @mysql /var/lib/mysql /mnt/encrypted/
encrypt: invalid command action.
root@ip-10-40-255-125:/home/ubuntu# zncrypt-move encrypt @mysql /var/lib/mysql /mnt/encrypted/
Type MASTER passphrase:

Size to encrypt: 29928 Kb
Moving from: '/var/lib/mysql'
Moving to:   '/mnt/encrypted/mysql/var/lib/mysql'
  [=====================================================================>] 100%

Done.
root@ip-10-40-255-125:/home/ubuntu#


root@ip-10-40-255-125:/home/ubuntu# zncrypt acl --add --rule="ALLOW @mysql * /usr/bin/mysqld_safe --shell=/bin/dash"
Type MASTER passphrase:
1 rule(s) were added
root@ip-10-40-255-125:/home/ubuntu# sudo service mysql start
 * Starting MySQL (Percona Server) database server mysqld                                                                                                                              [ OK ]
 * Checking for corrupt, not cleanly closed and upgrade needing tables.
root@ip-10-40-255-125:/home/ubuntu#



5. EXECUTING SYSBENCH

First lets create sbtest database:

root@ip-10-40-255-125:/home/ubuntu# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 41
Server version: 5.5.30-30.2 Percona Server (GPL), Release 30.2

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database sbtest;
Query OK, 1 row affected (0.00 sec)

mysql> exit
Bye
root@ip-10-40-255-125:/home/ubuntu#


Now let's prepare sysbench:

root@ip-10-40-255-125:/home/ubuntu# sysbench --db-driver=mysql --test=oltp --mysql-user=root --max-requests=100000 --oltp-table-size=1000000 --mysql-password=root --mysql-db=sbtest   --mysql-socket=/var/run/mysqld/mysqld.sock prepare
sysbench 0.4.12:  multi-threaded system evaluation benchmark

Creating table 'sbtest'...
Creating 1000000 records in table 'sbtest'...
root@ip-10-40-255-125:/home/ubuntu#


Then test a with multiple threads:



Check the aesni_intel usage

root@ip-10-40-255-125:/home/ubuntu# lsmod | grep aesni
aesni_intel            55664  100
cryptd                 20530  1 aesni_intel
aes_x86_64             17255  1 aesni_intel
root@ip-10-40-255-125:/home/ubuntu#


Enjoy!
P.S. No Flags for today!










lunes, 20 de mayo de 2013

Installing percona and sysbench on redhat


 Percona is a software and services company specializing in database support, development, consulting and training


 INSTALLING SYSBENCH ON REDHAT



Based on: http://www.serveradminblog.com/2010/02/sysbench-on-centos-howto/
http://tech-for-me.blogspot.mx/2012/07/installing-sysbench-from-launchpad.html

1.  Install compiler tools to compile the source
#yum -y install gcc gcc-c++ autoconf automake make libtool

2.  Install bzr so you download the source from the repository
#yum -y install bzr

3.  Install MySQL dependencies to build sysbench:
#yum -y install mysql mysql-server mysql-devel

4.  Download sysbench
#bzr branch lp:sysbench

5.  Compile and install sysbench
#cd sysbench
#./autogen.sh
#./configure --prefix=/usr --mandir=/usr/share/man
#make
#make instal
l

6.  Copy lua templates
# mkdir /usr/share/sysbench/tests/db -p
# cp sysbench/tests/db/* /usr/share/sysbench/tests/db

NOTE: Verify location of your lua files (*.lua)

6.  Test if sysbench is working

#sysbench

You should see the help


7. Since we are going to install percona you can remove mysql*
#yum -y remove mysql mysql-server mysql-devel




Troubleshooting:

If you receive an error like:
# sysbench --db-driver=mysql --test=oltp --oltp-table-size=1000000 --mysql-socket=/var/lib/mysql/mysql.sock --mysql-user=root --mysql-password= preparesysbench 0.5:  multi-threaded system evaluation benchmark

PANIC: unprotected error in call to Lua API (cannot open oltp: No such file or directory)
#
IT IS BECAUSE --TEST PARAM doesn't have the complete path: it should be:

# sysbench --db-driver=mysql --test=/usr/share/sysbench/tests/db/oltp.lua --oltp-table-size=1000000 --mysql-socket=/var/lib/mysql/mysql.sock --mysql-user=root --mysql-password= prepare




INSTALLING PERCONA

Based on : http://www.percona.com/doc/percona-server/5.5/installation/yum_repo.html


Remember that mysql* has to be uninstalled if not, you might have conflicts.

1.-  Add percona repository

vi /etc/yum.repos.d/Percona.repo


 Then Add:


[percona]
name = CentOS $releasever - Percona
baseurl=http://repo.percona.com/centos/$releasever/os/$basearch/
enabled = 1
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-percona
gpgcheck = 1

2. Verify that percone is listed as an installation package

 # yum list | grep percona
# yum list | grep percona
                              5.0.92-b23.89.rhel6  percona                     
Percona-SQL-client-50.x86_64  5.0.92-b23.89.rhel6  percona                     
Percona-SQL-devel-50.x86_64   5.0.92-b23.89.rhel6  percona                     
Percona-SQL-server-50.x86_64  5.0.92-b23.89.rhel6  percona                     
Percona-SQL-shared-50.x86_64  5.0.92-b23.89.rhel6  percona                     
                              5.0.92-b23.89.rhel6  percona                     
Percona-SQL-test-50.x86_64    5.0.92-b23.89.rhel6  percona                     
                                                   percona  


3. Download GPG keys:

Add follow key to: /etc/pki/rpm-gpg/RPM-GPG-KEY-percona

-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v1.4.9 (GNU/Linux)

mQGiBEsm3aERBACyB1E9ixebIMRGtmD45c6c/wi2IVIa6O3G1f6cyHH4ump6ejOi
AX63hhEs4MUCGO7KnON1hpjuNN7MQZtGTJC0iX97X2Mk+IwB1KmBYN9sS/OqhA5C
itj2RAkug4PFHR9dy21v0flj66KjBS3GpuOadpcrZ/k0g7Zi6t7kDWV0hwCgxCa2
f/ESC2MN3q3j9hfMTBhhDCsD/3+iOxtDAUlPMIH50MdK5yqagdj8V/sxaHJ5u/zw
YQunRlhB9f9QUFfhfnjRn8wjeYasMARDctCde5nbx3Pc+nRIXoB4D1Z1ZxRzR/lb
7S4i8KRr9xhommFnDv/egkx+7X1aFp1f2wN2DQ4ecGF4EAAVHwFz8H4eQgsbLsa6
7DV3BACj1cBwCf8tckWsvFtQfCP4CiBB50Ku49MU2Nfwq7durfIiePF4IIYRDZgg
kHKSfP3oUZBGJx00BujtTobERraaV7lIRIwETZao76MqGt9K1uIqw4NT/jAbi9ce
rFaOmAkaujbcB11HYIyjtkAGq9mXxaVqCC3RPWGr+fqAx/akBLQ2UGVyY29uYSBN
eVNRTCBEZXZlbG9wbWVudCBUZWFtIDxteXNxbC1kZXZAcGVyY29uYS5jb20+iGAE
ExECACAFAksm3aECGwMGCwkIBwMCBBUCCAMEFgIDAQIeAQIXgAAKCRAcTL3NzS79
Kpk/AKCQKSEgwX9r8jR+6tAnCVpzyUFOQwCfX+fw3OAoYeFZB3eu2oT8OBTiVYu5
Ag0ESybdoRAIAKKUV8rbqlB8qwZdWlmrwQqg3o7OpoAJ53/QOIySDmqy5TmNEPLm
lHkwGqEqfbFYoTbOCEEJi2yFLg9UJCSBM/sfPaqb2jGP7fc0nZBgUBnFuA9USX72
O0PzVAF7rCnWaIz76iY+AMI6xKeRy91TxYo/yenF1nRSJ+rExwlPcHgI685GNuFG
chAExMTgbnoPx1ka1Vqbe6iza+FnJq3f4p9luGbZdSParGdlKhGqvVUJ3FLeLTqt
caOn5cN2ZsdakE07GzdSktVtdYPT5BNMKgOAxhXKy11IPLj2Z5C33iVYSXjpTelJ
b2qHvcg9XDMhmYJyE3O4AWFh2no3Jf4ypIcABA0IAJO8ms9ov6bFqFTqA0UW2gWQ
cKFN4Q6NPV6IW0rV61ONLUc0VFXvYDtwsRbUmUYkB/L/R9fHj4lRUDbGEQrLCoE+
/HyYvr2rxP94PT6Bkjk/aiCCPAKZRj5CFUKRpShfDIiow9qxtqv7yVd514Qqmjb4
eEihtcjltGAoS54+6C3lbjrHUQhLwPGqlAh8uZKzfSZq0C06kTxiEqsG6VDDYWy6
L7qaMwOqWdQtdekKiCk8w/FoovsMYED2qlWEt0i52G+0CjoRFx2zNsN3v4dWiIhk
ZSL00Mx+g3NA7pQ1Yo5Vhok034mP8L2fBLhhWaK3LG63jYvd0HLkUFhNG+xjkpeI
SQQYEQIACQUCSybdoQIbDAAKCRAcTL3NzS79KlacAJ0aAkBQapIaHNvmAhtVjLPN
wke4ZgCePe3sPPF49lBal7QaYPdjqapa1SQ=
=qcCk
-----END PGP PUBLIC KEY BLOCK-----

4.-  Then install percona

#  yum install Percona-Server-client-55 Percona-Server-server-55

5.- do some start/stop operations with percona to verify installation:

# sudo service mysql status
 ERROR! MySQL (Percona Server) is not running
# sudo service mysql start
Starting MySQL (Percona Server).. SUCCESS!


6. Defaultt user is root without password

# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.30-30.2 Percona Server (GPL), Release rel30.2, Revision 509

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 




VERIFYING SYSBENCH

1. show databases:

# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.30-30.2 Percona Server (GPL), Release rel30.2, Revision 509

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases
    -> ;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| test               |
+--------------------+
4 rows in set (0.01 sec)

mysql> exit
Bye
#


2.- create 'sbtest' database, we will use it to execute sysbench



# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.30-30.2 Percona Server (GPL), Release rel30.2, Revision 509

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> create database sbtest;
Query OK, 1 row affected (0.00 sec)

mysql> exit
Bye




3. Run sysbench test:


# sysbench --db-driver=mysql --test=/usr/share/sysbench/tests/db/oltp.lua --oltp-table-size=1000000 --mysql-socket=/var/lib/mysql/mysql.sock --mysql-user=root --mysql-password= prepare
sysbench 0.5:  multi-threaded system evaluation benchmark

Creating table 'sbtest1'...
Inserting 1000000 records into 'sbtest1'
#


4. You will see that sbtest has some tables:

mysql> use sbtest;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> show tables;
+------------------+
| Tables_in_sbtest |
+------------------+
| sbtest1          |
+------------------+
1 row in set (0.00 sec)

mysql>



Enjoy!
P.S. Would you believe about this flag


martes, 30 de abril de 2013

Installing and executing Ansible on Ubuntu

This time is shown how to install and deploy and Ansible installation, also how to configure myhost to set a group of hosts to issue Ansible commands.

It is easy and simple. http://ansible.cc/


Ansible is useful if you want sto perform multiple aoperation on remote hosts; for example to install a big data database or to configure a multinode hadoop cluster. You can also send requests to find particular information and work with the result data; perhaps you need maintenance to cleanup your temporal file or create a cron job for all hosts, or some, etc.


Here you will see how to issue simple ansible commands and basic ansible-playbooks with an ease java-6-oracle example.


To install it on Ubuntu:


  # sudo add-apt-repository ppa:rquillo/ansible
  # sudo apt-get update
  # sudo apt-get install ansible -y


It is IMPORTANT to add to authorized_keys the uder (id_rsa,pub) that will issue Ansible Commands, in this case it is the same host. IF YOU DON'T have an id_rsa, then create it.

To create id_rsa:   (Make sure you don't have one already)

  # ssh-keygen            
               
Then cat it to copy it pubkey content and add it to authorized keys, remember in this examplo it is in the same authorized keys of the same host.

  # cat .ssh/id_rsa.pub 
  # vi .ssh/authorized_keys 




Now you can add localhost to myhosts to do a quick test:

   # echo localhost > myhosts
   # export  ANSIBLE_HOSTS=$(pwd)/myhosts
   # echo $ANSIBLE_HOSTS
   # ansible all -m ping -u ubuntu


     localhost | success >> {
         "changed": false,
         "ping": "pong"
     }


There you go, Ansible works, what have we done so far? Just test it, you can ccreat at myhosts a set of remote instances by adding to my hosts a tag like:

     # vi myhosts

 
     [my_remote_servers]
     10.40.207.50
     10.40.207.82

In this case you can issue Ansible commands for a particular set of my_remote_servers like:

   # ansible my_remote_servers -m ping -u ubuntu

You can see now that only the servers listed in my_remote_servers will respond to ping.


What can we do? all that the specified user can do, for example:


     # ansible gazzang  -a "ls /home/ubuntu" -u ubuntu
     10.40.207.50 | success | rc=0 >>
     dir_test
     file.txt

   10.40.207.82 | success | rc=0 >>
     my_directory
     this_is_a_file.doc




Remember that for 10.40.207.50 and 10.40.207.82 the id_rsa_pub should've been added to their corresponding autrorized keys; if not the Ansible command will fail with:


     # ansible gazzang  -a "ls /home" -u ubuntu
     10.40.207.50 | FAILED => FAILED: Authentication failed.

IF YOU ARE PLANNING TO ISSUE SUDO COMMANDS, then remember to add to /root/.ssh/authorized keys the id_rsa.pub.  Or add to the non-root user root permissions, just be careful.



Wanna go further? of course yo do!

Follow are two YAML files, these are ansible-playbooks, you can see that we are installing java-6-oracle from PPA and we acre including one YAML into another.


# This playbook just includes a second playbook
- hosts: ec2
  vars:
    reponame: stable
    distro_release: precise
  user: ubuntu
  sudo: yes
  tasks:
  - include: install_java6oracle_on_ubuntu.yml


  #First operations
  - name: Describe first task
    shell: echo "This is the issued command"


  - name: Describing second task
    shell: sudo gpg --keyserver pgpkeys.mit.edu --recv-key  D2B6F0B7FADF302F



 install_java6oracle_on_ubuntu.yml:



You can do many operations on the different ansible-platbook tasks, this is just a small set of them.

  - name: Changing the cluster name at /etc/cassandra/cassandra.yaml and the listen_address
    shell: sudo cat $cassandra_orig  | sed "s/Test Cluster/Cassandra Production Cluster/" | sed "s/listen_address:\ localhost/listen_address:\ \"$( ifconfig  | grep Bcast | awk '{print
substr($2,6)}')\"/" | sed "s/seeds:\ \"127.0.0.1\"/seeds:\ \"$seed_ip\"/" | sed "s/rpc_address:\ localhost/rpc_address:\ 0.0.0.0/"    > $cassandra_tmp


You can save stdout at a ansible variable from prompt commands by using the operation register:

  - name: Get Cassandra PID
    shell: ps aux | grep cassandra | grep oracle | grep root | grep -v ansible | awk '{ print($2) }'
    register: cassandra_pid

  - name: Creating cassandra profile
    shell: sudo zncrypt-profile  --pid=${cassandra_pid.stdout} > $cassandra_profile_file




Have Fun!
.Alex

P.D. Flag has no reverse meaning (useless)

jueves, 11 de abril de 2013

Install Java6-sun on scripts with non-interactive (unattended) mode

This has been tested on ubuntu 10.04 and ubuntu 12.04

Follow is a python function that does that, you can see the commands:

For ubuntu 10.04:

def install_java_6(status):
        output = ""
    status, output = execute('sudo add-apt-repository ppa:sun-java-community-team/sun-java6')
    if status == 0:
        status, output = execute('sudo apt-get update')
    if status == 0:
        status, output = execute('sudo sh -c \'echo sun-java6-jre shared/accepted-sun-dlj-v1-1 select true | /usr/bin/debconf-set-selections\' ')
    if status == 0:
        status, output = execute('sudo apt-get install -y sun-java6-jdk')
    if status == 0:
        status, output = execute('sudo update-java-alternatives -s java-6-sun')
        status = 0;
    return status,output
exit




For Ubuntu 12.04:

def install_java_6(status):
        output = ""
        #2.4 status, output = execute('sudo add-apt-repository ppa:sun-java-community-team/sun-java6')
        status, output = execute('sudo add-apt-repository ppa:webupd8team/java -y')
        if status == 0:
            status, output = execute('sudo apt-get update')
        if status == 0:   
            status, output = execute(' echo debconf shared/accepted-oracle-license-v1-1 select true | sudo debconf-set-selections ')
            status, output = execute(' echo debconf shared/accepted-oracle-license-v1-1 seen true | sudo debconf-set-selections ')
        if status == 0:
            #2.4 status, output = execute('sudo apt-get install -y sun-java6-jdk')i
            status, output = execute('sudo apt-get install oracle-java6-installer')
        if status == 0:
            #status, output = execute('sudo update-java-alternatives -s java-6-sun')
            status = 0;
        return status,output
exit


IMPORTANT, debconf is receiving select and seen, If you miss selelect you will receive an error like:

error: Cannot find a question for shared/accepted-oracle-license-v1-1


For both 10.04 and 12.04 the execute function is:


def execute( cmd ):
    print "\n\n Executing :" + cmd
    status, output = commands.getstatusoutput(cmd)
    print "status: " + str(status)
    print "output: " + output
    return status, output
exit




If you want to uninstall java-6-oracle:

# ubuntu@ip-10-136-0-17:~$    sudo apt-get purge oracle-java6-installer


Enjoy!

P.D. Should exist a Cuernavaca's flag!


Add and prepare a Volume to an EC2 Instance

Well this is simple and will document it just for fun! =)


You can attach a volume to an EC2 instance by:

1. creating the volume at EC2 - > Volumes -> Create volume

Select the size and create it. It is IMPORTANT that the volume is created in the same Geography and lab, i.e. If an instance is un us-east-1a and your volume is in us-east-1b you will not be able to attach the volume; use us-east-1a for both for example.


Once it is created

2. Right click on the volume -> Attach Volume

Then select the instance you want to attach to.

See that volume state will be attaching for a while; in my case I did it when the instance was running, I guess this also works for stopped instances.

Ok, so now we have to format, mount and att to fstab our new device:


ssh your EC2 instance.

If our Volume is named: /dev/xvdf and we want to use an ext4 filesystem:

sudo mkfs.ext4 /dev/xvdf

Then mount to a particular directory

mkdir /mnt_large

sudo mount /dev/xvdf /mnt_large

Finally add to fstab:


Follow is the original content:

LABEL=cloudimg-rootfs   /        ext4   defaults        0 0
/dev/xvdb       /mnt    auto    defaults,nobootwait,comment=cloudconfig 0       2


Add your device line and final result will be:

LABEL=cloudimg-rootfs   /        ext4   defaults        0 0
/dev/xvdb       /mnt    auto    defaults,nobootwait,comment=cloudconfig 0       2
/dev/xvdf       /mnt_large    auto    defaults,nobootwait,comment=cloudconfig 0       2


For details on fstab see: https://help.ubuntu.com/community/Fstab


Why do we add it to fstab? well if you reboot you can make sure that your device will be automatically mounted.

That's it!

P.D. I should say that there are not ugly flags.