在 CentOS 6.x 上安裝 MariaDB 資料庫

在安裝 Linux 時,大部分人在安裝資料庫時都會安裝 MySQL Server,而比較少安裝 PostgreSQL Server,在 Oracle 購買 MySQL 之後,有些使用者對於 Oracle 保持不信任的態度,轉而支持由 MySQL 公司原創辦人 Michael Widenius 先生另外開發了一個新的資料庫系統,就叫做 MariaDB,並且與原先的 MySQL 保持絕佳的相容性。
MariaDB 官方網站: https://mariadb.com/   https://mariadb.org/en/
[@more@]在 CentOS 6.x 下安裝方式:
1. 最好的方式是在安裝時,不安裝 MySQL 資料庫,否則移除相關套件時,會遇到一些問題,我是採用比較乾淨的方式來安裝
2. 依照官方網站上的 安裝說明 ,建立套件儲存庫,有  5.5 和 10.0 二個版本可以選擇
# vim /etc/yum.repos.d/mariadb.repo

# MariaDB 5.5 CentOS repository list - created 2014-01-10 13:53 UTC  
#
http://mariadb.org/mariadb/repositories/
[mariadb]

name = MariaDB
baseurl = http://yum.mariadb.org/5.5/centos6-amd64
gpgkey = https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1


# MariaDB 10.0 CentOS repository list - created 2014-01-10 13:54 UTC
#
http://mariadb.org/mariadb/repositories/
[mariadb]

name = MariaDB
baseurl = http://yum.mariadb.org/10.0/centos6-amd64
gpgkey = https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

更新套件庫
# yum update

安裝 MariaDB
# yum -y install MariaDB-server MariaDB-client

啟動 MariaDB
# service mysql start

開機後啟動
# chkconfig –level 3 mysql on

安裝完成的設定
# /usr/bin/mysql_secure_installation
/usr/bin/mysql_secure_installation: line 379: find_mysql_client:命令找不到

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MariaDB to secure it, we’ll need the current
password for the root user.  If you’ve just installed MariaDB, and
you haven’t set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on…

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n]
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 … Success!

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n]
 … Success!

Normally, root should only be allowed to connect from ‘localhost’.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n]
 … Success!

By default, MariaDB comes with a database named ‘test’ that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n]
 – Dropping test database…
 … Success!
 – Removing privileges on test database…
 … Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n]
 … Success!

Cleaning up…

All done!  If you’ve completed all of the above steps, your MariaDB
installation should now be secure.

Thanks for using MariaDB!

PXE Client 端的功能表

PXE Client 端的功能表,預設會讀取 /var/lib/tftpboot/pxelinux.cfg 目錄下的 default 當做設定檔,但也可以每一台 PXE Client 端都有自己的功能表設定檔,如果是在電腦教室,每一台電腦的設備都會是一樣,所以使用共用的設定是沒有問題的,但如果像是辦公室,每個人的每一台電腦設備、作業系統……,和要求的功能也有所不同,這時候就有必要,為不同的 PXE Client 端設定不同的設定檔。[@more@]PXE Client 端在開機時,會搜尋 /var/lib/tftpboot/pxelinux.cfg 目錄之下是否有 01-aa-bb-cc-dd-ee-ff 的設定檔,其中 aa-bb-cc-dd-ee-ff 就是 PXE Client 端的網路卡卡號
   01:00:15:58:6b:7d –> 01-00-15-58-6b-7d

如果找不到,接著搜尋是否有 AABBCCDD 的設定檔,其中 AABBCCDD 就是 PXE Client 端的 IP 的 16 進位
   192.168.1.11 –> C0A8010B
   192 –> C0
   168 –> A8
   1 –> 01
   11 –> 0B

如果都找不到,就會抓取 /var/lib/tftpboot/pxelinux.cfg/default 當做是功能表

快速產生 DHCP Server 的 dhcpd.conf 格式檔

從 /var/lib/dhcpd/dhcpd.leases 取出要的網路卡卡號
# cat /var/lib/dhcpd/dhcpd.leases | grep hard | awk ‘{print $3}’
d0:df:c7:f9:5c:ef;
00:26:51:0d:53:40;
00:11:93:88:7a:00;
00:15:58:6b:7d:da;
00:15:58:6b:7d:da;
00:15:58:6b:7d:da;
00:15:58:6b:7d:da;

經過處理,只取出想要的部分
# cat /var/lib/dhcpd/dhcpd.leases | grep hard | awk ‘{print $3}’ | sed ‘s/.$//’ | sort | uniq
00:11:93:88:7a:00
00:15:58:6b:7d:da
00:26:51:0d:53:40
d0:df:c7:f9:5c:ef

整理完的資料檔
# cat /root/mac
server1,00:11:93:88:7a:00,192.168.1.11
server2,00:15:58:6b:7d:da,192.168.1.12
server3,00:26:51:0d:53:40,192.168.1.13
server4,d0:df:c7:f9:5c:ef,192.168.1.14
[@more@]
使用 awk
# cat /usr/local/bin/mkdhcpd
#!/bin/bash
cat /root/mac | awk -F”,” ‘BEGIN{OFS=” “}{print $1,$2,$3 }’ | while read i j k
do
   echo “host $i {“
   echo ”  hardware ethernet $j;”
   echo ”  fixed-address $k;”
   echo “}”
done

使用 sed
# cat /usr/local/bin/mkdhcpd
#!/bin/bash
cat /root/mac | sed ‘s/,/ /g’ | while read i j k
do
   echo “host $i {“
   echo ”  hardware ethernet $j;”
   echo ”  fixed-address $k;”
   echo “}”
done

測試
# sh /usr/local/bin/mkdhcpd
host server1 {
  hardware ethernet 00:11:93:88:7a:00;
  fixed-address 192.168.1.11;
}
host server2 {
  hardware ethernet 00:15:58:6b:7d:da;
  fixed-address 192.168.1.12;
}
host server3 {
  hardware ethernet 00:26:51:0d:53:40;
  fixed-address 192.168.1.13;
}
host server4 {
  hardware ethernet d0:df:c7:f9:5c:ef;
  fixed-address 192.168.1.14;
}

在 Linux Console 做 2 / 10 / 16 進位的轉換

人還是習慣用 10 進位,遇到 2 / 10 / 16 進位的轉換,可能就要藉助紙筆或是計算機的幫忙,底下是在 Linux Console 中使用 Bash Shell 內建的功能來做轉換。

2 進位轉成 10 進位
# echo $((2#111111))
63

16 進位轉成 10 進位
# echo $((16#c0))
192

10 進位轉成 2 進位
# echo “obase=2;17″|bc
10001

10 進位轉成 16 進位
# echo “obase=16;17″|bc
11

多層 PXE 功能表

因為 PXE 功能表的選項愈來愈多,一個頁面放不下,所以修改 PXE 功能表,讓 PXE 功能表可以有很多層。
底下文章參考: http://wiki.centos.org/HowTos/PXE/PXE_Setup/Menus

# vim /var/lib/tftpboot/pxelinux.cfg/default
default menu.c32
prompt 0
timeout 300
ONTIMEOUT local

MENU TITLE Welcom to Tou-Cheng Elementary School PXE Server System

LABEL local
MENU LABEL Boot from local hard drive
LOCALBOOT 0

LABEL Install CentOS 6.5 x86_64 Servers
MENU LABEL Install CentOS 6.5 x86_64 Servers
MENU PASSWD CentOS
KERNEL menu.c32
APPEND pxelinux.cfg/x86_64_Servers

LABEL Install CentOS 6.5 x86 Servers
MENU LABEL Install CentOS 6.5 x86 Servers
MENU PASSWD CentOS
KERNEL menu.c32
APPEND pxelinux.cfg/x86_Servers

LABEL Backup / Restore
MENU LABEL Backup / Restore
MENU PASSWD BR
KERNEL menu.c32
APPEND pxelinux.cfg/Backup_Restore

LABEL Tools
MENU LABEL Tools
KERNEL menu.c32
APPEND pxelinux.cfg/tools[@more@]# cat /var/lib/tftpboot/pxelinux.cfg/x86_64_Servers
MENU TITLE Install CentOS 6.5 x86_64 Server Menu

LABEL Main Menu
MENU LABEL ^Return Main Menu
KERNEL menu.c32
APPEND pxelinux.cfg/default

LABEL Install CentOS 6.5 x86_64 from FTP
MENU LABEL Install CentOS 6.5 x86_64 from FTP
kernel images/CentOS/6.5/x86_64/vmlinuz
append initrd=images/CentOS/6.5/x86_64/initrd.img method=ftp://192.168.1.6/CentOS/6.5/os/x86_64/

LABEL Install CentOS 6.5 x86_64 from HTTP
MENU LABEL Install CentOS 6.5 x86_64 from HTTP
kernel images/CentOS/6.5/x86_64/vmlinuz
append initrd=images/CentOS/6.5/x86_64/initrd.img method=http://192.168.1.6/CentOS/6.5/os/x86_64/

LABEL Install CentOS 6.5 x86_64 from NFS
MENU LABEL Install CentOS 6.5 x86_64 from NFS
kernel images/CentOS/6.5/x86_64/vmlinuz
append initrd=images/CentOS/6.5/x86_64/initrd.img method=http://192.168.1.6/CentOS/6.5/os/x86_64/

LABEL AutoInstall CentOS 6.5 x86_64 from FTP
MENU LABEL AutoInstall CentOS 6.5 x86_64 from FTP
kernel images/CentOS/6.5/x86_64/vmlinuz
append initrd=images/CentOS/6.5/x86_64/initrd.img ks=ftp://192.168.1.6/ks/ks.cfg method=ftp://192.168.1.6/CentOS/6.5/os/x86_64/

LABEL AutoInstall CentOS 6.5 x86_64 from HTTP
MENU LABEL AutoInstall CentOS 6.5 x86_64 from HTTP
kernel images/CentOS/6.5/x86_64/vmlinuz
append initrd=images/CentOS/6.5/x86_64/initrd.img ks=http://192.168.1.6/ks/ks.cfg method=http://192.168.1.6/CentOS/6.5/os/x86_64/

LABEL AutoInstall CentOS 6.5 x86_64 from NFS
MENU LABEL AutoInstall CentOS 6.5 x86_64 from NFS
kernel images/CentOS/6.5/x86_64/vmlinuz
append initrd=images/CentOS/6.5/x86_64/initrd.img ks=http://192.168.1.6/ks/ks.cfg method=http://192.168.1.6/CentOS/6.5/os/x86_64/

# cat /var/lib/tftpboot/pxelinux.cfg/x86_Servers
MENU TITLE Install CentOS 6.5 x86 Server Menu

LABEL Main Menu
MENU LABEL ^Return Main Menu
KERNEL menu.c32
APPEND pxelinux.cfg/default

LABEL Install CentOS 6.5 i386 from FTP
MENU LABEL Install CentOS 6.5 i386 from FTP
kernel images/CentOS/6.5/i386/vmlinuz
append initrd=images/CentOS/6.5/i386/initrd.img method=ftp://192.168.1.6/CentOS/6.5/os/i386/

LABEL Install CentOS 6.5 i386 from HTTP
MENU LABEL Install CentOS 6.5 i386 from HTTP
kernel images/CentOS/6.5/i386/vmlinuz
append initrd=images/CentOS/6.5/i386/initrd.img method=http://192.168.1.6/CentOS/6.5/os/i386/

LABEL Install CentOS 6.5 i386 from NFS
MENU LABEL Install CentOS 6.5 i386 from NFS
kernel images/CentOS/6.5/i386/vmlinuz
append initrd=images/CentOS/6.5/i386/initrd.img method=http://192.168.1.6/CentOS/6.5/os/i386/

LABEL AutoInstall CentOS 6.5 i386 from FTP
MENU LABEL AutoInstall CentOS 6.5 i386 from FTP
kernel images/CentOS/6.5/i386/vmlinuz
append initrd=images/CentOS/6.5/i386/initrd.img ks=ftp://192.168.1.6/ks/ks.cfg method=ftp://192.168.1.6/CentOS/6.5/os/i386/

LABEL AutoInstall CentOS 6.5 i386 from HTTP
MENU LABEL AutoInstall CentOS 6.5 i386 from HTTP
kernel images/CentOS/6.5/i386/vmlinuz
append initrd=images/CentOS/6.5/i386/initrd.img ks=http://192.168.1.6/ks/ks.cfg method=http://192.168.1.6/CentOS/6.5/os/i386/

LABEL AutoInstall CentOS 6.5 i386 from NFS
MENU LABEL AutoInstall CentOS 6.5 i386 from NFS
kernel images/CentOS/6.5/i386/vmlinuz
append initrd=images/CentOS/6.5/i386/initrd.img ks=http://192.168.1.6/ks/ks.cfg method=http://192.168.1.6/CentOS/6.5/os/i386/

# cat /var/lib/tftpboot/pxelinux.cfg/Backup_Restore
MENU TITLE Backup / Restore Menu

LABEL Main Menu
MENU LABEL ^Return Main Menu
KERNEL menu.c32
APPEND pxelinux.cfg/default

LABEL Symantec Ghost
MENU LABEL ^Symantec Ghost
MENU PASSWD Ghost
kernel memdisk
append initrd=images/dos/GHO1151.IMG

LABEL Clonezilla Live tftp
MENU LABEL Clonezilla Live ^tftp
MENU PASSWD CloneZilla
kernel images/Clonezilla/live/vmlinuz
append initrd=images/Clonezilla/live/initrd.img boot=live config username=user quiet noswap edd=on nomodeset noeject locales=”zh_TW.UTF-8″ keyboard-layouts=”NONE” ocs_live_run=”ocs-live-general” ocs_live_extra_param=”” ocs_live_batch=no vga=788 ip=frommedia nosplash fetch=tftp://192.168.1.6/images/Clonezilla/live/filesystem.squashfs

LABEL Clonezilla Livei nfs
MENU LABEL Clonezilla Live ^nfs
MENU PASSWD CloneZilla
kernel images/Clonezilla/live/vmlinuz
append initrd=images/Clonezilla/live/initrd.img boot=live config username=user quiet noswap edd=on nomodeset noeject locales=”zh_TW.UTF-8″ keyboard-layouts=”NONE” ocs_live_run=”ocs-live-general” ocs_live_extra_param=”” ocs_live_batch=no vga=788 ip=frommedia nosplash netboot=nfs nfsroot=192.168.1.6:/var/lib/tftpboot/images/Clonezilla

# cat /var/lib/tftpboot/pxelinux.cfg/tools
MENU TITLE Tools Menu

LABEL Main Menu
MENU LABEL ^Return Main Menu
KERNEL menu.c32
APPEND pxelinux.cfg/default

LABEL Memory Test
MENU LABEL ^Memory Test – memtest86+
kernel images/memtest/memtest86+-5.01

LABEL SPFDisk
MENU LABEL ^SPFDisk
MENU PASSWD SPFDisk
kernel memdisk
append initrd=images/dos/spfdisk.img

label FreeDOS 1.0 Bootdisk
MENU LABEL ^FreeDOS 1.0 bootdisk
MENU PASSWD FreeDOS
kernel memdisk
append initrd=images/dos/balder10.img

由 DHCP Server 的動態 IP 轉成固定 IP – Linux Server 篇

Linux 安裝完成之後,如果沒有在手動或自動安裝中設定好網路組態,通常就要手動設定網路,但如果是用由 DHCP Server 自動取得 IP,會節省許多的時間,但如果是 Server 的話,還是使用固定 IP 會比較好。[@more@]
底下文章內容取自:HowTos/NetworkInstallServer – CentOS Wiki
1. 建立 Script 檔
# vim /usr/local/bin/set_static_ip
#!/bin/bash
echo “Converting DHCP scope to static IP address”

DEVICE=`route -n|grep ‘^0.0.0.0’|awk ‘{print $8}’`
IPADDR=`ifconfig $DEVICE|grep ‘inet addr:’|awk ‘{sub(/addr:/,””); print $2}’`
NETMASK=`ifconfig $DEVICE|grep ‘Mask’|awk ‘{sub(/Mask:/,””); print $4}’`
NETWORK=`ipcalc $IPADDR -n $NETMASK|awk -F= ‘{print $2}’`
GATEWAY=`route -n|grep ‘^0.0.0.0’|awk ‘{print $2}’`
HWADDR=`ifconfig $DEVICE|grep ‘HWaddr’|awk ‘{print $5}’`
HOSTNAME=`hostname`

cat <<EOF >/etc/sysconfig/network
NETWORKING=yes
HOSTNAME=$HOSTNAME
GATEWAY=$GATEWAY
EOF

cat <<EOF >/etc/sysconfig/network-scripts/ifcfg-$DEVICE
DEVICE=$DEVICE
BOOTPROTO=static
IPADDR=$IPADDR
NETMASK=$NETMASK
ONBOOT=yes
HWADDR=$HWADDR
EOF

2. 賦予執行權限
# chmod 700 /usr/local/bin/set_static_ip

3. 執行
# /usr/local/bin/set_static_ip

4. 觀看成果
# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=test.tces.ilc.edu.tw
GATEWAY=192.168.1.254

# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
BOOTPROTO=static
IPADDR=192.168.1.6
NETMASK=255.255.255.0
ONBOOT=yes
HWADDR=6C:62:6D:61:80:81

在 PXE 開機選單中加入 Clonezilla 功能

Clonezilla 是一套類似 Ghost 的備份和還原程式,是由國家高速網路中心所開發,完全免費,支援多種平台的備份及還原,如:Windows / Linux / Mac…等等,一般使用時都是放在 USB 隨身碟(硬碟) 或燒錄成光碟來使用,不過既然有 PXE,就放在 PXE Server 上,更加的方便,完全不用光碟或隨身碟,既方便又環保。
Clonezilla 官方網站: http://clonezilla.nchc.org.tw/clonezilla-live/

參考網站:
【FreeBSD】架設電腦教室大量佈署環境 – PXE + Clonezilla Live + NFS 備份/還原 @ 有為青年生活札記 :: 痞客邦 PIXNET ::
Clonezilla live

下載 Clonezilla: 版本會一直更新,視所需平台而定
# wget http://downloads.sourceforge.net/project/clonezilla/clonezilla_live_alternative_testing/20140107-trusty/clonezilla-live-20140107-trusty-amd64.zip
# wget http://downloads.sourceforge.net/project/clonezilla/clonezilla_live_alternative_testing/20140107-trusty/clonezilla-live-20140107-trusty-i386.zip
# mkdir /var/lib/tftpboot/images/Clonezilla
# unzip clonezilla-live-20140107-trusty-amd64.zip -d /var/lib/tftpboot/images/Clonezilla

[@more@]
修改 PXE 選單
# vim /var/lib/tftpboot/pxelinux.cfg/default
加入下面幾行
使用 tftp
LABEL Clonezilla Live
   MENU LABEL Clonezilla Live
   MENU PASSWD Clonezilla
   kernel images/Clonezilla/live/vmlinuz
   append initrd=images/Clonezilla/live/initrd.img boot=live config noswap nolocales edd=on nomodeset ocs_live_run=”ocs-live-general” ocs_live_extra_param=”” ocs_live_keymap=”NONE” ocs_live_batch=”no” ocs_lang=”zh_TW.UTF-8″ vga=788 nosplash fetch=tftp://192.168.1.6/images/Clonezilla/live/filesystem.squashfs

使用 nfs
LABEL Clonezilla Live
   MENU LABEL Clonezilla Live
   MENU PASSWD Clonezilla
   kernel images/Clonezilla/live/vmlinuz
   append initrd=images/Clonezilla/live/initrd.img boot=live config noswap nolocales edd=on nomodeset ocs_live_run=”ocs-live-general” ocs_live_extra_param=”” ocs_live_keymap=”NONE” ocs_live_batch=”no” ocs_lang=”zh_TW.UTF-8″ vga=788 nosplash  netboot=nfs nfsroot=192.168.1.6:/Clonezilla

PXE 功能表


開機畫面


開機完成

在 PXE 開機選單中加入 SPFDisk / Ghost / FreeDOS 選項

複製 PXE 所需的程式
# cp /usr/share/syslinux/memdisk /var/lib/tftpboot
建立目錄
# mkdir /var/lib/tftpboot/dos
複製檔案到相對應目錄
# cp spfdisk.img /var/lib/tftpboot/dos
# cp ghost.img /var/lib/tftpboot/dos
# cp fdboot.img /var/lib/tftpboot/dos
[@more@]
修改 PXE 選單
# vim /var/lib/tftpboot/pxelinux.cfg/default
加入下面幾行
LABEL SPFDisk
   MENU LABEL SPFDisk
   MENU PASSWD SPFDisk
   kernel memdisk
   append initrd=dos/spfdisk.img

LABEL Symantec Ghost
   MENU LABEL Symantec Ghost
   MENU PASSWD Ghost
   kernel memdisk
   append initrd=dos/ghost.img

LABEL FreeDOS 1.0
   MENU LABEL FreeDOS 1.0
   MENU PASSWD FreeDOS
   kernel memdisk
   append initrd=dos/fdboot.img


選項開機畫面

輸入設定的密碼



SPFDisk 執行畫面


Symantec Ghost 選項


FreeDOS 選項

FreeDOS 開機畫面

在 PXE 開機選單中加入 memtest 選項

有時候覺得電腦的記憶體有問題,想要測試一下,就要用 memtest86 的開機光碟,或是利用隨身碟加上 grub4dos 開機來測試,燒光碟不環保,隨身碟又不一定會隨時放在身上,這時候利用 PXE 開機來執行,就是最方便了!
底下文章參考 memtest86+ PXE boot | panticz.de

Memtest86+ – Advanced Memory Diagnostic Tool 官方網站:http://www.memtest.org/

1. 建立 /var/lib/tftpboot/memtest 目錄
# mkdir /var/lib/tftpboot/memtest

2. 切換目錄
# cd /var/lib/tftpboot/memtest

[@more@]3. 下載 memtest86+ 程式,一定要下載 zip/gz 檔
# wget http://www.memtest.org/download/5.01/memtest86+-5.01.bin.gz

4. 解壓縮
# gunzip memtest86+-5.01.bin.gz
更改檔名
# mv memtest86+-5.01.bin memtest86+-5.01
# ls -l
總計 148
-rw-r–r–. 1 root root 150024 2013-09-28 01:45 memtest86+-5.01

5. 修改 PXE 選單
# vim /var/lib/tftpboot/pxelinux.cfg/default
加入下面幾行
LABEL Memory Test
   MENU LABEL Memory Test – memtest86+
   kernel memtest/memtest86+-5.01

開機畫面

記憶體測試