unexpected[it]

Professional IT Blog

  • 5th, Aug 2010

Unix Box Handbook

Tags: , , , ,

#
# Variable file, Write all global vars in
#
.bash_login
PATH=$PATH:/Applications/MAMP/Library/bin/
alias ls="ls -G"

#
# Size of a folder
#
du -kH

#
# Find
#
find . -name "sendmail.cf"
find . -type f -name "*.java" -exec grep -l sendEmailPassword {} \;

#
# Virtual Box
#
VBoxManage internalcommands sethduuid

#
# Mails (Mac Snow Leopard)
# See the mail queue
/usr/sbin/sendmail -bp
# Start Postfix daemon
 /usr/bin/sudo /bin/launchctl load -w /Library/LaunchDaemons/com.cutedgesystems.postfix.plist
# Stop Postfix daemon
 /usr/bin/sudo /bin/launchctl unload -w /Library/LaunchDaemons/com.cutedgesystems.postfix.plist
# Mail out folder
/var/spool/postfix/maildrop

#
# Test Mail Sever through telnet
#
telnet 127.0.0.1 25
EHLO 127.0.0.1
MAIL FROM:root@localhost
RCPT TO: ignacio@richardmason.net
DATA
SUBJECT: test message
Test message
.
  • 4th, Aug 2010

Apache Http Password in Directory

Tags: , , ,

1) Create the password file .htpasswd
Go to the directory to protect and type in the shell

htpasswd -c -m .htpasswd webuser

-c means create file.
-m MD5 algorithm.

…if you want to get the generated MD5 password in the screen just type

htpasswd -n -bm  webuser 123456

2) Create a file .htaccess

AuthName "Restricted Area"
AuthType Basic
AuthUserFile /var/www/html/.htpasswd  #This is the file you generated before
AuthGroupFile /dev/null
require valid-user

3) Test it

  • 29th, Jul 2010

MySQL Cluster on Amazon EC2

Tags: , , , , , ,

I created two cluster servers and one management server for MySQL Cluster

AMI: Minimal Fedora Core 8, 32-bit architecture, Apache 2.0, and Amazon EC2 AMI Tools
MySQL Cluster version 7.1
Fedora Version: 8
Security Group: default

1) Download RPM files
From http://www.mysql.com/downloads/cluster/#downloads all rpm files for Red Hat & Oracle Enterprise Linux for (x86, 32-bit).

2) In each instance

yum --enablerepo=remi erase mysql mysql-libs mysql-server mysqlclient15.i386
rpm -iv MySQL-Cluster-gpl-*

3) Config Management Server
Server IP ( ec2-79-11-111-11.eu-west-1.compute.amazonaws.com )

vi /var/lib/mysql-cluster/config.ini
[NDBD DEFAULT]
NoOfReplicas=2
[MYSQLD DEFAULT]
[NDB_MGMD DEFAULT]
[TCP DEFAULT]
# Managment Server
[NDB_MGMD]
HostName=ec2-79-11-111-11.eu-west-1.compute.amazonaws.com		# the IP of THIS SERVER
# Storage Engines
[NDBD]
HostName=ec2-79-22-222-22.eu-west-1.compute.amazonaws.com		# the IP of the FIRST SERVER
DataDir= /var/lib/mysql-cluster
[NDBD]
HostName=ec2-79-33-333-33.eu-west-1.compute.amazonaws.com		# the IP of the SECOND SERVER
DataDir=/var/lib/mysql-cluster
# 2 MySQL Clients
# I personally leave this blank to allow rapid changes of the mysql clients;
# you can enter the hostnames of the above two servers here. I suggest you dont.
[MYSQLD]
[MYSQLD]

ndb_mgmd -f /var/lib/mysql-cluster/config.ini

The Management Server is now ready, you can check the conexions with the other servers doing this

ndb_mgm
ndb_mgm> show
Cluster Configuration
---------------------
[ndbd(NDB)]	2 node(s)
id=2	@79.22.222.22  (mysql-5.1.44 ndb-7.1.4, Nodegroup: 0, Master)
id=3	@79.33.333.33  (mysql-5.1.44 ndb-7.1.4, Nodegroup: 0, Master)

[ndb_mgmd(MGM)]	1 node(s)
id=1	@79.11.111.11  (mysql-5.1.44 ndb-7.1.4)

[mysqld(API)]	2 node(s)
id=4	@79.22.222.22  (mysql-5.1.44 ndb-7.1.4)
id=5	@79.33.333.33  (mysql-5.1.44 ndb-7.1.4)

4) Config Cluster Servers
Cluster Server IPs: (ec2-79-22-222-22.eu-west-1.compute.amazonaws.com and ec2-79-33-333-33.eu-west-1.compute.amazonaws.com )

/etc/my.cnf
[mysqld]
ndbcluster
ndb-connectstring=ec2-79-11-111-11.eu-west-1.compute.amazonaws.com     # the IP of the MANAGMENT SERVER
[mysql_cluster]
ndb-connectstring=ec2-79-11-111-11.eu-west-1.compute.amazonaws.com	# the IP of the MANAGMENT SERVER

/usr/sbin/ndbd --initial

/etc/init.d/mysql start

5) Testing
You can check in FIRST or SECOND server this and it will be duplicated in both servers.

mysql -u root -p
use test;
CREATE TABLE ctest (i INT) ENGINE=NDBCLUSTER;
INSERT INTO ctest () VALUES (1);
SELECT * FROM ctest;

6) Starting and Shutting down the MySQL Cluster
Starting
Management Server: db_mgmd -f /var/lib/mysql-cluster/config.ini
Cluster Servers: ndbd

Shutting down
Management Server: ndb_mgm> shutdown

Notes
Error: ERROR 1005 (HY000): Can’t create table ‘test.ctest’ (errno: 157)
Try to track the error with SHOW WARNINGS; When I have this problem I had disabled SELinux with “setenforce 0″.

Error: There is no populating changes trough the cluster servers.
Make sure they are connected each other, you can check this from management server with ndb_mgm> SHOW
Also double check all servers are in the security group “default” to leave the ports open. (see image)

Pages related: http://dev.mysql.com/tech-resources/articles/mysql-cluster-for-two-servers.html

  • 29th, Jul 2010

Setting up a Magento Server in Amazon Cloud EC2

Tags: , , , , , , , , , ,

How to create an instance for Magento in Amazon Cloud EC2

You can also get this ebs Image in Amazon EC2. Choose “426063643107/Magento 1.4.x on Fedora 8″
when you launch an instance in the tab “Community AMIs”
MySQL Admin
Username: root Password: 123456

Once the image is initialized
a) Install Magento 1.4.1.1 (For demo store follow 5.1)
In your browser go to: http://YOUREC2NAME.compute-1.amazonaws.com/magento/
b) Install Magento 1.4.1.1 DEMO Version
In your browser go to: http://YOUREC2NAME.compute-1.amazonaws.com/magento-demo/

1) Choose the simplest Instance Fedora Core 8 (AMI Id: ami-df1e35ab)
Minimal Fedora Core 8, 32-bit architecture, Apache 2.0, and Amazon EC2 AMI Tools.

2) Installing Remi Repository with Apache, MySQL and PHP

wget http://rpms.famillecollet.com/remi-release-8.rpm
rpm -Uvh remi-release-8.rpm
vi /etc/apt/sources.list.d/remi.list # Uncomment: repomd http://rpms.famillecollet.com/ fc$(VERSION).$(ARCH)

# Installing MySQL
#
yum --enablerepo=remi install mysql mysql-server mysql-devel

# Installing Http Server with PHP
#
yum --enablerepo=remi install php php-mysql php-common php-gd php-mbstring php-mcrypt php-devel php-xml

# Config MySQL
#
/usr/bin/mysqladmin -u root password '123456'

# Config Apache
#
# /etc/httpd/conf/httpd.con on Line 326 change
AllowOverride None
# to
AllowOverride All
# inside <Directory "/var/www/html"> ... </Directory>

# /etc/php.ini Activate this line to read <? tags
short_open_tag = On

#Try it out with the usual script in /var/www/html/test.php
&lt;?php
phpinfo();
?>

3) Installing Exim Mail Server

yum install exim
/etc/init.d/exim start
mail -s "testing" your@emailaddress.com
Testing purpose!
.
Cc:
# Your Mail Server should be running properly

4) SFtp Server Access

# Just using a SFtp Client Server Vicomsoft Ftp Client
#  configure a new connection without password and use
#  the option "Use SSH keyfile (SFTP only)" to add your
#  .pem file
#  Or just use
sshfs -i MYSECRETKEY.pem root@YOUREC2NAME.compute-1.amazonaws.com:/ /

5) Using ntsysv command choose the next services to start automatically
sendmail
httpd
mysqld

6) Optionally you can give NFS support to share files between images

#Server1
[root@server1]# vi /etc/exports
/var/www/html *(rw)

[root@server1]# /etc/init.d/rpcbind start

[root@server1]# /etc/init.d/nfs start
#Server2
[root@server2]# mount -o nolock ec2-79-xxx-xx-xxx.eu-west-1.compute.amazonaws.com:/var/www/html /mnt

7) Download and uncompress Magento versions in /var/www/html

CHANGELOG
File /etc/php.ini change short_open_tag = On

  • 24th, Jul 2010

Speed up images and flash loading times in sites

Tags: , , , ,

.htaccess file


Header set Cache-Control “max-age=7257600, public”

It means that image files are all forced to use the local cache for 3 months.
Speeds many sites up considerably.

  • 31st, Aug 2009

SSH Create Host – User Key to connect

Tags: , ,

#
# SSH create a connection host key
#
# Setting up RSync over SSH with No Password
# It's actually very simple. Just follow these few steps:
# ---- 1 ----
# As the user you are going to be running rsync as, and on the machine you will be running rsync on, type:
ssh-keygen -t rsa
# Follow the prompts and use the defaults for the filenames it gives you. Don't enter in a passphrase, otherwise you will still be prompted for a password when trying to connect.
# You should then have two new files in ~/.ssh, id_rsa and id_rsa.pub.
# ---- 2 ----
# Open ~/.ssh/id_rsa.pub and copy the line in it to the ~/.ssh/authorized_keys file on the host you will be connecting to as the user you will be logging in as.
# ---- 3 ----
# Now try it out. Try ssh'ing from the host you created the id_rsa* files on to the one you added a line to the authorized_keys file. You won't be prompted for a password any more.
# ---- 4 ----
# Test it!

#
# Example:
#

# Host server:
ls root/.ssh/
-rw-r--r-- 1 root root 424 Feb 26 15:38 authorized_keys
-rw------- 1 root root 672 Feb 25 17:48 id_dsa
-rw-r--r-- 1 root root 621 Feb 25 17:48 id_dsa.pub

cat authorized_keys:
ssh-rsa AA...L8vOA+w== ServerBackup@Server-Backups-Mac-Mini.local

# User server:
ls Users/ServerBackup/.ssh/
-rw-------  1 ServerBackup  staff  1675  4 Jul  2009 id_rsa
-rw-r--r--  1 ServerBackup  staff   424  4 Jul  2009 id_rsa.pub
-rw-r--r--  1 ServerBackup  staff  1246 26 Feb 15:44 known_hosts

cat known_hosts
server.unexpectedit.com,172.123.123.238 ssh-rsa AAAAB3NzaC1...psoQ==

© 2010 unexpected[it]. All Rights Reserved.

This blog is powered by Wordpress and a modified version of Magatheme