Archive for November, 2013

How to create the first VM on XenServer automatically without XenCenter

Environment:
httprepo: 192.168.92.128
xenserver: 192.168.92.140
vm: 192.168.92.142

1. Create a http repo
# yum install httpd
# wget http://linux.mirrors.es.net/centos/6/isos/x86_64/CentOS-6.4-x86_64-minimal.iso

# mkdir -p /var/www/html/repo/centos/6
# mkdir /var/www/html/repo/ks
# mount -o loop CentOS-6.4-x86_64-minimal.iso /var/www/html/repo/centos/6/

# service httpd start

2. Create the kickstart configuration file
# vi /var/www/html/repo/ks/centos-6.4-x86_64-minimal.ks

cmdline
skipx
install
cdrom
lang en_US.UTF-8
keyboard us

network --onboot yes --device eth0 --bootproto=static --ip=192.168.92.142 --netmask=255.255.255.0 --gateway=192.168.92.2 --nameserver=192.168.92.2 --noipv6

rootpw mypasswd

firewall --service=ssh
authconfig --enableshadow --passalgo=sha512
selinux --disabled
timezone --utc Etc/UTC

bootloader --location=mbr --driveorder=xvda --append="crashkernel=auto"

zerombr
clearpart --all --initlabel
autopart

reboot

%packages --nobase
@core
%end

3. Install the first vm automatically
Get the Local storage uuid
# xe sr-list | grep -C 1 "Local"

uuid ( RO) : fbeda99f-b5a7-3100-5e3d-fbb48a46fca0
name-label ( RW): Local storage
name-description ( RW):

Create an empty vm
# xe vm-install new-name-label=centos6_template sr-uuid=fbeda99f-b5a7-3100-5e3d-fbb48a46fca0 template=Other\ install\ media

2fe3c706-9506-50d5-a557-0d61ebde651b

Configure the cpu,memory of the vm
# xe vm-param-set VCPUs-max=1 uuid=2fe3c706-9506-50d5-a557-0d61ebde651b
# xe vm-param-set VCPUs-at-startup=1 uuid=2fe3c706-9506-50d5-a557-0d61ebde651b

# xe vm-param-set memory-dynamic-max=512MiB uuid=2fe3c706-9506-50d5-a557-0d61ebde651b
# xe vm-param-set memory-static-max=512MiB uuid=2fe3c706-9506-50d5-a557-0d61ebde651b
# xe vm-param-set memory-dynamic-min=512MiB uuid=2fe3c706-9506-50d5-a557-0d61ebde651b
# xe vm-param-set memory-static-min=512MiB uuid=2fe3c706-9506-50d5-a557-0d61ebde651b

Configure the bootloader,httprepo,kickstart of the vm installation
# xe vm-param-set HVM-boot-policy="" uuid=2fe3c706-9506-50d5-a557-0d61ebde651b
# xe vm-param-set PV-bootloader="eliloader" uuid=2fe3c706-9506-50d5-a557-0d61ebde651b
# xe vm-param-set other-config:install-repository="http://192.168.92.128/repo/centos/6/" uuid=2fe3c706-9506-50d5-a557-0d61ebde651b
# xe vm-param-set PV-args="ip=192.168.92.142 netmask=255.255.255.0 gateway=192.168.92.2 ns=192.168.92.2 noipv6 ks=http://192.168.92.128/repo/ks/centos-6.4-x86_64-minimal.ks ksdevice=eth0" uuid=2fe3c706-9506-50d5-a557-0d61ebde651b

Add a virtual disk to the vm
# xe vm-disk-add uuid=2fe3c706-9506-50d5-a557-0d61ebde651b sr-uuid=fbeda99f-b5a7-3100-5e3d-fbb48a46fca0 device=0 disk-size=20GiB

Make the virtual disk bootable
# xe vbd-list vm-uuid=2fe3c706-9506-50d5-a557-0d61ebde651b userdevice=0 params=uuid --minimal
d304bbbd-f4e2-d648-a668-fe6a803bc301

# xe vbd-param-set bootable=true uuid=d304bbbd-f4e2-d648-a668-fe6a803bc301

Create a network connection of the vm
# xe network-list bridge=xenbr0 --minimal
a6fcd4a1-fb61-6f73-2b31-2a20ad45e0cc

# xe vif-create vm-uuid=2fe3c706-9506-50d5-a557-0d61ebde651b network-uuid=a6fcd4a1-fb61-6f73-2b31-2a20ad45e0cc mac=random device=0
aaf0a04d-c721-fae8-aca1-eb63e047ea93

Start the VM, it will be installed automatically with basic packages and start sshd
# xe vm-start uuid=2fe3c706-9506-50d5-a557-0d61ebde651b

4. Wait for 20 minutes then try to login the vm
# ssh root@192.168.92.142

The authenticity of host '192.168.92.142 (192.168.92.142)' can't be established.
RSA key fingerprint is d5:de:ac:6a:7f:33:0c:ca:84:aa:d5:62:43:d2:9a:23.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.92.142' (RSA) to the list of known hosts.
root@192.168.92.142's password: mypasswd
Last login: Thu Oct 10 22:17:48 2013 from 192.168.92.140
[root@localhost ~]# ls
anaconda-ks.cfg install.log install.log.syslog
[root@localhost ~]#

,

1 Comment

How to setup Percona XtraDB Cluster

Environment:
servers: demoenv-trial-1 demoenv-trial-2 demoenv-trial-3

1. Install Percona Server, on all servers:
$ sudo yum install http://www.percona.com/downloads/percona-release/percona-release-0.0-1.x86_64.rpm
$ sudo yum install http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
$ sudo yum install Percona-Server-shared-compat
$ sudo yum install Percona-Server-server-55 Percona-Server-client-55

2. Configure the /etc/my.cnf, on all servers:
$ sudo vim /etc/my.cnf

[mysqld]
# basic settings
datadir = /opt/mysql/data
tmpdir = /opt/mysql/tmp
socket = /opt/mysql/run/mysqld.sock
port = 3306
pid-file = /opt/mysql/run/mysqld.pid

# innodb settings
default-storage-engine = INNODB
innodb_file_per_table = 1
log-bin = /opt/mysql/binlogs/bin-log-mysqld
log-bin-index = /opt/mysql/binlogs/bin-log-mysqld.index
innodb_data_home_dir = /opt/mysql/data
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /opt/mysql/data
binlog-do-db = testdb

# server id
server-id=1

# other settings
max_allowed_packet = 64M
max_connections = 1024
expire_logs_days = 14
character-set-server = utf8

[mysqld_safe]
log-error = /opt/mysql/log/mysqld.log
pid-file = /opt/mysql/run/mysqld.pid
open-files-limit = 8192

[mysqlhotcopy]
interactive-timeout

[client]
port = 3306
socket = /opt/mysql/run/mysqld.sock
default-character-set = utf8

3. Create directories, on all servers:
$ sudo mkdir -p /opt/mysql/{data,tmp,run,binlogs,log}
$ sudo chown mysql:mysql /opt/mysql/{data,tmp,run,binlogs,log}

4. Initialize the database, on all servers:
$ sudo -i
# su - mysql
$ mysql_install_db --user=mysql --datadir=/opt/mysql/data/
$ exit
# exit
$ sudo /etc/init.d/mysql start

5. Remove them without dependencies, on all servers:
Because if we install xtradb cluster, we will get error messages like:
Error: Percona-XtraDB-Cluster-client conflicts with Percona-Server-client-55-5.5.34-rel32.0.591.rhel6.x86_64
Error: Percona-XtraDB-Cluster-server conflicts with Percona-Server-server-55-5.5.34-rel32.0.591.rhel6.x86_64
Error: Percona-XtraDB-Cluster-shared conflicts with Percona-Server-shared-55-5.5.34-rel32.0.591.rhel6.x86_64

$ sudo /etc/init.d/mysql stop
$ sudo rpm -qa | grep Percona-Server | grep -v compat | xargs sudo rpm -e --nodeps
Read the rest of this entry »

, ,

2 Comments

How to upgrade Percona Server 55 to 56

1. Stop Percona Server, on all servers:
$ sudo service mysql stop

2. Check installed packages, on all servers:
$ sudo rpm -qa | grep Percona-Server | grep -v compat

Percona-Server-client-55-5.5.34-rel32.0.591.rhel6.x86_64
Percona-Server-shared-55-5.5.34-rel32.0.591.rhel6.x86_64
Percona-Server-server-55-5.5.34-rel32.0.591.rhel6.x86_64

Remove them without dependencies, on all servers:
$ sudo rpm -qa | grep Percona-Server | grep -v compat | xargs sudo rpm -e --nodeps

3. Install new packages, on all servers:
$ sudo yum install Percona-Server-server-56

4. Start without reading grant table, on all servers, may see some ERROR messages:
$ sudo /usr/sbin/mysqld --skip-grant-tables --user=mysql &
Read the rest of this entry »

1 Comment

Replication and auto-failover made easy with MySQL Utilities

Reference:
http://www.clusterdb.com/mysql/replication-and-auto-failover-made-easy-with-mysql-utilities

Environment:
master: demoenv-trial-1
slaves: demoenv-trial-2 demoenv-trial-3

1. Install Percona Server, on all servers:
$ sudo yum install http://www.percona.com/downloads/percona-release/percona-release-0.0-1.x86_64.rpm
$ sudo yum install Percona-Server-shared-compat
$ sudo yum install Percona-Server-server-56

$ sudo yum install http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
$ sudo yum install mysql-utilities

2. Configure /etc/my.cnf, on all servers:
Ensure the "server-id" is different and the "report-host" same as own hostname
$ sudo vim /etc/my.cnf

[mysqld]
# basic setting
datadir = /opt/mysql/data
tmpdir = /opt/mysql/tmp
socket = /opt/mysql/run/mysqld.sock
port = 3306
pid-file = /opt/mysql/run/mysqld.pid

# innodb setting
default-storage-engine = INNODB
innodb_file_per_table = 1
log-bin = /opt/mysql/binlogs/bin-log-mysqld
log-bin-index = /opt/mysql/binlogs/bin-log-mysqld.index
innodb_data_home_dir = /opt/mysql/data
innodb_data_file_path = ibdata1:10M:autoextend
innodb_log_group_home_dir = /opt/mysql/data
binlog-do-db = testdb

# server id
server-id=1

# gtids setting
binlog-format = ROW
log-slave-updates = true
gtid-mode = on
enforce-gtid-consistency = true
report-host = demoenv-trial-1
report-port = 3306
master-info-repository = TABLE
relay-log-info-repository = TABLE
sync-master-info = 1

# other settings
max_allowed_packet = 64M
max_connections = 1024
expire_logs_days = 14
character-set-server = utf8

[mysqld_safe]
log-error = /opt/mysql/log/mysqld.log
pid-file = /opt/mysql/run/mysqld.pid
open-files-limit = 8192

[mysqlhotcopy]
interactive-timeout

[client]
port = 3306
socket = /opt/mysql/run/mysqld.sock
default-character-set = utf8

3. Create directories, on all servers:
$ sudo mkdir -p /opt/mysql/{data,tmp,run,binlogs,log}
$ sudo chown mysql:mysql /opt/mysql/{data,tmp,run,binlogs,log}

4. Initialize the database, on all servers:
$ sudo -i
# su - mysql
$ mysql_install_db --user=mysql --datadir=/opt/mysql/data/
$ exit
# exit
$ sudo /etc/init.d/mysql start

5. Create remote access to root@'%' for "mysqlreplicate" to create replication setting, on all servers:
$ mysql -uroot
mysql> grant all on *.* to root@'%' identified by 'pass' with grant option;
mysql> quit;

6. Create replication user, on all servers:
$ mysql -uroot
mysql> grant replication slave on *.* to 'rpl'@'%' identified by 'rpl';
mysql> quit;

7. Set up replication, on any one server:
[dong.guo@demoenv-trial-1 ~]$ mysql -uroot
mysql> use mysql;
mysql> drop user root@'demoenv-trial-1';
mysql> quit;
Read the rest of this entry »

, ,

5 Comments

Fork me on GitHub