Saturday, September 30, 2017

Debian Stretch: XEN configure & create DomU HVM Centos part 2

Get centos iso cd
# mkdir iso/
# cd iso
# mkdir centos7
# cd centos7
# wget http://centos.biz.net.id/7/isos/x86_64/CentOS-7-x86_64-NetInstall-1708.iso
Note: you can choose your closest mirror.

Create logical volume for guest
# lvcreate -L300g -n xcentos701-disk volGroup1
  Logical volume "xcentos701-disk" created.
# lvdisplay
  --- Logical volume ---
  LV Path                /dev/volGroup1/xcentos701-disk
  LV Name                xcentos701-disk
  VG Name                volGroup1
  LV UUID                jmP1d1-9xFo-ruio-eEXx-Vkgi-w1Ah-X4tO7B
  LV Write Access        read/write
  LV Creation host, time server, 2017-09-29 02:29:55 +0700
  LV Status              available
  # open                 0
  LV Size                300.00 GiB
  Current LE             76800
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           254:0

Create guest configuration file /etc/xen/xcentos701.cfg
builder = "hvm"
name = "xcentos701"
memory = 8192
vcpus = 4
vif = [ 'mac=00:16:4f:02:02:15, ip=[your_ip], bridge=br0' ]
# Disk Devices
# A list of `diskspec' entries as described in
# docs/misc/xl-disk-configuration.txt
disk = [
  '/dev/volGroup1/xcentos701-disk,raw,xvda,rw',
  'file:/[your_home]/iso/centos7/centos7.iso,xvdc:cdrom,r'
  ]
boot = "dc"
vnc = 1
vnclisten = "[your_ip]"
vncdisplay = 0
vncpasswd = "password"

You need to use any vnc viewer to finish installation. At the end, set root password and reboot. 

If the reboot is stuck, destroy the instance.
# xl destroy xcentos701

You need to remove cdrom from configuration, edit /etc/xen/xcentos701.cfg 
builder = "hvm"
name = "xcentos701"
memory = 8192
vcpus = 4
vif = [ 'mac=00:16:4f:02:02:15, ip=[your_ip], bridge=br0' ]
# Disk Devices
# A list of `diskspec' entries as described in
# docs/misc/xl-disk-configuration.txt
disk = [
  '/dev/volGroup1/xcentos701-disk,raw,xvda,rw'
  ]
boot = "c"
We don't need vnc anymore, so we remove it (comment it out).

Start your guest
# xl create /etc/xen/xcentos701.cfg 
# xl list
Name                                        ID   Mem VCPUs      State   Time(s)
Domain-0                                     0 11815    24     r-----    5001.7
xcentos701                                   1 12288     4     -b----    9315.6

State:

  • r - running
  • b - blocked
  • p - paused
  • s - shutdown
  • c - crashed
  • d - dying


To connect to your guest
# xl console xencentos701

To make your guest start after boot/restart
# mkdir /etc/xen/auto
# ln -s /etc/xen/xcentos701.cfg /etc/xen/auto/xcentos701.cfg

Add user and allow su/sudo
# adduser [your_user]
# usermod -aG wheel [your_user]

References:

  1. http://blog.noviantech.com/2010/06/23/debian-kernels-and-tigon-tg3-firmware/
  2. https://wiki.debian.org/Firmware
  3. https://wiki.debian.org/LVM
  4. https://wiki.debian.org/LinuxRaidForAdmins
  5. https://ycnrg.org/xen-install-os-from-iso-pv/
  6. http://hwraid.le-vert.net/

Debian Stretch: XEN part 1

Install minimum Debian Stretch and add some tools
# apt-get install net-tools
# apt-get install fail2ban
# apt-get install debian-goodies
# apt-get install ntp
# apt-get install dnsutils

Install Firmware
1. Add firmware repository
# vi /etc/apt/sources.list
# NON FREE
deb http://httpredir.debian.org/debian stretch main contrib non-free
# apt-get update 
2. Install firmware
# apt-get install firmware-linux-nonfree

To configure timezone
# dpkg-reconfigure tzdata

If your hardware use LSI RAID for my case Mega Raid, you need to monitor your disks status. Install this tool.
1. Add Raid tools repository
# wget https://hwraid.le-vert.net/debian/hwraid.le-vert.net.gpg.key
# apt-key add ./hwraid.le-vert.net.gpg.key
# vi /etc/apt/sources.list
...
deb ​http://hwraid.le-vert.net/debian stretch main
...
# apt-get update 
2. Install Raid tools to monitor disks status.
# apt-get install megaraid-status
# megaraidsas-status
-- Arrays informations --
-- ID | Type | Size | Status
a0d0 | RAID 1 | 931GiB | optimal

-- Disks informations
-- ID | Model | Status | Warnings
a0e32s0 | SEAGATE ST1000NM0001 931GiB | online
a0e32s1 | SEAGATE ST1000NM0023 931GiB | online
a0e32s2 | SEAGATE ST1000NM0001 | ready
a0e32s3 | SEAGATE ST31000640SS 931GiB | predictive-failure

There is at least one disk/array in a NOT OPTIMAL state.

Install & configure LVM (Logical Volume Manager)
1. Install LVM2
# apt-get install lvm2 
2. Create Physical Volume on unused partition
# pvcreate /dev/sda5
WARNING: ext4 signature detected on /dev/sda5 at offset 1080. Wipe it? [y/n]: y
  Wiping ext4 signature on /dev/sda5.
  Physical volume "/dev/sda5" successfully created.
3. Create Volume Group
# vgcreate volGroup1 /dev/sda5
  Volume group "volGroup1" successfully created
# vgdisplay
  --- Volume group ---
  VG Name               volGroup1
  System ID
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               784.78 GiB
  PE Size               4.00 MiB
  Total PE              200903
  Alloc PE / Size       0 / 0
  Free  PE / Size       200903 / 784.78 GiB
  VG UUID               LzgeKn-N4EO-R4mV-YbRB-6Utc-7GmB-F0ALs1

Install Xen 4.8 (default in stretch)
# apt-get install xen-system-amd64 xen-tools

Make prioritise boot xen kernel
# dpkg-divert --divert /etc/grub.d/08_linux_xen --rename /etc/grub.d/20_linux_xen
# update-grub
Including Xen overrides from /etc/default/grub.d/xen.cfg
WARNING: GRUB_DEFAULT changed to boot into Xen by default!
         Edit /etc/default/grub.d/xen.cfg to avoid this warning.
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-4.9.0-3-amd64
Found initrd image: /boot/initrd.img-4.9.0-3-amd64
Found linux image: /boot/vmlinuz-4.9.0-3-amd64
Found initrd image: /boot/initrd.img-4.9.0-3-amd64
Found linux image: /boot/vmlinuz-4.9.0-3-amd64
Found initrd image: /boot/initrd.img-4.9.0-3-amd64
done

Network configuration for bridge
# vi /etc/network/interfaces
# The primary network interface
auto eno1
iface eno1 inet manual

# Bridge
#allow-hotplug eno1
auto br0
iface br0 inet static
   address [your_ip]/24
   gateway [your_gateway]
   # dns-* options are implemented by the resolvconf package, if installed
   dns-nameservers 8.8.8.8 208.67.222.222
   bridge_ports eno1
# shutdown -r now

Edit /etc/xen/xl.conf to make bridge br0 as default network bridge
# vi /etc/xen/xl.conf
...
# default bridge device to use with vif-bridge hotplug scripts
#vif.default.bridge="xenbr0"
vif.default.bridge="br0"
...

Done! :)

Debian Stretch: XEN part 1
Debian Stretch: XEN configure & create DomU PV Debian part 3
Debian Stretch: XEN configure & create DomU HVM Centos part 2
Debian Stretch: XEN configure & create DomU PV ubuntu xenial part 4

To show memory:
# xl info | grep memory
total_memory           : 24530
free_memory            : 3122
sharing_freed_memory   : 0
sharing_used_memory    : 0

To show VCPU:
# xl info | grep cpu
nr_cpus                : 24
max_cpu_id             : 47
cpu_mhz                : 2000
free_cpus              : 0

To show volume group free space:
# vgdisplay | grep Free
  Free  PE / Size       71367 / 278.78 GiB

References:

  1. http://blog.noviantech.com/2010/06/23/debian-kernels-and-tigon-tg3-firmware/ 
  2. https://wiki.debian.org/Firmware 
  3. https://wiki.debian.org/LVM
  4. https://wiki.debian.org/LinuxRaidForAdmins
  5. https://ycnrg.org/xen-install-os-from-iso-pv/
  6. http://hwraid.le-vert.net/




Friday, September 29, 2017

WHM/Cpanel: install on centos 7 (1708)

Recommendation: install whm/cpanel on minimum Centos 7

Install yum util and network tool
# yum install yum-utils net-tools

Disable SeLinux
# vi /etc/selinux/config
...
SELINUX=disabled
...

Set  fully qualified hostname 
# hostname example.[your_domain]

Download whm/cpanel installer script
# wget https://securedownloads.cpanel.net/latest
--2017-09-29 02:02:22--  https://securedownloads.cpanel.net/latest
Resolving securedownloads.cpanel.net (securedownloads.cpanel.net)... 208.74.123.12
Connecting to securedownloads.cpanel.net (securedownloads.cpanel.net)|208.74.123.12|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 26720 (26K)
Saving to: ‘latest’

100%[======================================>] 26,720       125KB/s   in 0.2s

2017-09-29 02:02:23 (125 KB/s) - ‘latest’ saved [26720/26720]

Run whm/cpanel installer
# chmod 744 latest
# ./latest

It may takes some times. Mine, it takes al least 40 minutes.

Continue configure your whm/cpanel via web, for example https://[youripaddress]:2087

Thursday, September 21, 2017

Debian Stretch: replace php5 to 7.0

You can remove php5 by command
 # apt-get purge *php5*

Delete any configuration exist
# rm -R /etc/php5/

You need to know which php5 library you used and upgrade it to php7.0.
Note: php7.1 not available in Debian Stretch currently.

Show available php7.0
# apt-cache search 'php7.0'
php-amqp - AMQP extension for PHP
php-apcu - APC User Cache for PHP
php-all-dev - package depending on all supported PHP development packages
php-gearman - PHP wrapper to libgearman
php-geoip - GeoIP module for PHP
php-gmagick - Provides a wrapper to the GraphicsMagick library
php-gnupg - PHP wrapper around the gpgme library
php-igbinary - igbinary PHP serializer
php-imagick - Provides a wrapper to the ImageMagick library
php-libsodium - PHP wrapper for the Sodium cryptographic library
php-mailparse - Email message manipulation for PHP
php-memcache - memcache extension module for PHP
php-memcached - memcached extension module for PHP, uses libmemcached
php-mongodb - MongoDB driver for PHP
php-msgpack - PHP extension for interfacing with MessagePack
php-oauth - OAuth 1.0 consumer and provider extension
php-http - PECL HTTP module for PHP Extended HTTP Support
php-pinba - Pinba module for PHP
php-propro - propro module for PHP
php-radius - radius client library for PHP
php-raphf - raphf module for PHP
php-redis - PHP extension for interfacing with Redis
php-rrd - PHP bindings to rrd tool system
php-smbclient - PHP wrapper for libsmbclient
php-solr - PHP extension for communicating with Apache Solr server
php-ssh2 - Bindings for the libssh2 library
php-stomp - Streaming Text Oriented Messaging Protocol (STOMP) client module for PHP
php-uploadprogress - file upload progress tracking extension for PHP
php-uuid - PHP UUID extension
php-yac - YAC (Yet Another Cache) for PHP
php-yaml - YAML-1.1 parser and emitter for PHP
php-zmq - ZeroMQ messaging bindings for PHP
libapache2-mod-php7.0 - server-side, HTML-embedded scripting language (Apache 2 module)
libphp7.0-embed - HTML-embedded scripting language (Embedded SAPI library)
php7.0 - server-side, HTML-embedded scripting language (metapackage)
php7.0-bcmath - Bcmath module for PHP
php7.0-bz2 - bzip2 module for PHP
php7.0-cgi - server-side, HTML-embedded scripting language (CGI binary)
php7.0-cli - command-line interpreter for the PHP scripting language
php7.0-common - documentation, examples and common module for PHP
php7.0-curl - CURL module for PHP
php7.0-dba - DBA module for PHP
php7.0-dev - Files for PHP7.0 module development
php7.0-enchant - Enchant module for PHP
php7.0-fpm - server-side, HTML-embedded scripting language (FPM-CGI binary)
php7.0-gd - GD module for PHP
php7.0-gmp - GMP module for PHP
php7.0-imap - IMAP module for PHP
php7.0-interbase - Interbase module for PHP
php7.0-intl - Internationalisation module for PHP
php7.0-json - JSON module for PHP
php7.0-ldap - LDAP module for PHP
php7.0-mbstring - MBSTRING module for PHP
php7.0-mcrypt - libmcrypt module for PHP
php7.0-mysql - MySQL module for PHP
php7.0-odbc - ODBC module for PHP
php7.0-opcache - Zend OpCache module for PHP
php7.0-pgsql - PostgreSQL module for PHP
php7.0-phpdbg - server-side, HTML-embedded scripting language (PHPDBG binary)
php7.0-pspell - pspell module for PHP
php7.0-readline - readline module for PHP
php7.0-recode - recode module for PHP
php7.0-snmp - SNMP module for PHP
php7.0-soap - SOAP module for PHP
php7.0-sqlite3 - SQLite3 module for PHP
php7.0-sybase - Sybase module for PHP
php7.0-tidy - tidy module for PHP
php7.0-xml - DOM, SimpleXML, WDDX, XML, and XSL module for PHP
php7.0-xmlrpc - XMLRPC-EPI module for PHP
php7.0-xsl - XSL module for PHP (dummy)
php7.0-zip - Zip module for PHP
php-remctl - PECL module for Kerberos-authenticated command execution
php-tideways - Tideways PHP Profiler Extension
php-xdebug - Xdebug Module for PHP


Now you can choose and install php7.0. For instant:
# apt-get install php7.0 php7.0-gd php7.0-pgsql php7.0-cli php7.0-common php7.0-mcrypt php7.0-mysql php7.0-curl php7.0-json php7.0-cgi php7.0-xml php7.0-xmlrpc php7.0-bz2 php7.0-zip libapache2-mod-php7.0

Note:
  1. Configuration folder will change from /etc/php5 to /etc/php/7.0/.
  2. File php.ini will located in /etc/php/7.0/apache2/php.ini.




Wednesday, September 20, 2017

Debian Jessie: change MySql distribution to MySql community

Debian Stretch does not shipped MySql. Before upgrade your Debian Jessie into Stretch, you need to change your MySql Debian distribution into MySql Community.

Install MySql dependency
# apt-get install lsb-release

Download MySql apt configuration from https://dev.mysql.com/get/mysql-apt-config_0.8.7-1_all.deb
# wget --no-check-certificate https://dev.mysql.com/get/mysql-apt-config_0.8.7-1_all.deb
Note: File name may change without notice, check latest mysql-apt-config at https://dev.mysql.com/downloads/repo/apt/

"The MySQL APT repository can only replace distributions of MySQL maintained and distributed by Debian or Ubuntu. It cannot replace any MySQL forks found either inside or outside of the distributions' native repositories. To replace such MySQL forks, you have to uninstall them first before you install MySQL using the MySQL APT repository. Follow the instructions for uninstallation from the forks' distributors and, before you proceed, make sure you back up your data and you know how to restore them to a new server. "

Backup MySql
# mysqldump --all-database > backup_all_201709.sql -u root -p

Remove your MySql Distribution
# apt-get --purge remove mysql-server mysql-client
# apt-get --purge remove mysql-server-5.5 mysql-client-5.5 // if required
# apt-get --purge remove mysql-server-core-5.5 mysql-client-core-5.5
// if required
Note: check your mysql using 

# aptitude search mysql-server

Install MySql apt configuration.
# dpkg -i mysql-apt-config_0.8.7-1_all.deb
Choose MySql 5.7 for stable version and continue by click Ok. It will create apt repository file like this:

# cat /etc/apt/sources.list.d/mysql.list
### THIS FILE IS AUTOMATICALLY CONFIGURED ###
# You may comment out entries below, but any other modifications may be lost.
# Use command 'dpkg-reconfigure mysql-apt-config' as root for modifications.
deb http://repo.mysql.com/apt/debian/ jessie mysql-apt-config
deb http://repo.mysql.com/apt/debian/ jessie mysql-5.7
deb http://repo.mysql.com/apt/debian/ jessie mysql-tools
#deb http://repo.mysql.com/apt/debian/ jessie mysql-tools-preview
deb-src http://repo.mysql.com/apt/debian/ jessie mysql-5.7


Run update and install
# apt-get update
# apt-get install mysql-server mysql-client
At the end of installation, you will be ask for MySql root password (Note: this is not root Linux user)

# service mysql status
● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled)
   Active: active (running) since Wed 2017-09-20 09:24:13 WIB; 8s ago
 Main PID: 8432 (mysqld)
   CGroup: /system.slice/mysql.service
           └─8432 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mys...

Sep 20 09:24:13 igamdeb8 systemd[1]: Started MySQL Community Server.
# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.19 MySQL Community Server (GPL)

Copyright (c) 2000, 2017, 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>


Run mysql_upgrade:
# mysql_upgrade -u root -p
Enter password:
Checking if update is needed.
Checking server version.
Running queries to upgrade MySQL server.
Checking system database.
mysql.columns_priv                                 OK
mysql.db                                           OK
mysql.engine_cost                                  OK
mysql.event                                        OK
mysql.func                                         OK
mysql.general_log                                  OK
mysql.gtid_executed                                OK
mysql.help_category                                OK
mysql.help_keyword                                 OK
mysql.help_relation                                OK
mysql.help_topic                                   OK
mysql.host                                         OK
mysql.innodb_index_stats                           OK
mysql.innodb_table_stats                           OK
mysql.ndb_binlog_index                             OK
mysql.plugin                                       OK
mysql.proc                                         OK
mysql.procs_priv                                   OK
mysql.proxies_priv                                 OK
mysql.server_cost                                  OK
mysql.servers                                      OK
mysql.slave_master_info                            OK
mysql.slave_relay_log_info                         OK
mysql.slave_worker_info                            OK
mysql.slow_log                                     OK
mysql.tables_priv                                  OK
mysql.time_zone                                    OK
mysql.time_zone_leap_second                        OK
mysql.time_zone_name                               OK
mysql.time_zone_transition                         OK
mysql.time_zone_transition_type                    OK
mysql.user                                         OK
Upgrading the sys schema.
Checking databases.
...



Resotre your database
# mysql -u root -p < backup_all_201709.sql
Enter password:


References:
https://dev.mysql.com/doc/mysql-apt-repo-quick-guide/en/
https://dev.mysql.com/doc/refman/5.7/en/backup-and-recovery.html
https://dev.mysql.com/doc/refman/5.7/en/reloading-sql-format-dumps.html