MySQL學習第一篇:系統準備

1. 系統準備
克隆一臺CentOS 6.5

1、依次查看需要修改的內容

[root@demo ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
[root@demo ~]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=demo.centos.com
GATEWAY=172.16.16.1
NTPSERVERARGS=iburst
[root@demo ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 
DEVICE=eth0
TYPE=Ethernet
UUID=32c2dda1-55e9-453a-ab82-4ec5dbef8036
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
HWADDR=00:0C:29:21:FE:2C
IPADDR=172.16.16.186
PREFIX=24
GATEWAY=172.16.16.1
DNS1=202.101.172.35
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no
NAME="System eth0"
[root@demo ~]# cat /etc/selinux/config 
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=enforcing
# SELINUXTYPE= can take one of these two values:
#     targeted - Targeted processes are protected,
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted 

2、編寫並執行初始化系統腳本initsystem.sh

#!/bin/bash

export hostname=mysql.master
export mac=`ifconfig $NIC | awk '/HWaddr/{ print $5 }' `
export ipaddr=`ifconfig|grep "inet addr:"|grep -v "127.0.0.1"|cut -d: -f2|awk '{print $1}'`
export selinux=disabled

# set up /etc/hosts
echo ${ipaddr} mysql.master mysql.master >> /etc/hosts

# set up /etc/sysconfig/network
sed -i s/^HOSTNAME.*/HOSTNAME=${hostname}$i/ /etc/sysconfig/network

#set up /etc/sysconfig/network-scripts/ifcfg-eth0
grep -q "HWADDR=" /etc/sysconfig/network-scripts/ifcfg-eth0||echo "HWADDR=" >> /etc/sysconfig/network-scripts/ifcfg-eth0
sed -i s/^HWADDR.*/HWADDR=${mac}$i/ /etc/sysconfig/network-scripts/ifcfg-eth0

grep -q "IPADDR=" /etc/sysconfig/network-scripts/ifcfg-eth0||echo "IPADDR=" >> /etc/sysconfig/network-scripts/ifcfg-eth0
sed -i s/^IPADDR.*/IPADDR=${ipaddr}$i/ /etc/sysconfig/network-scripts/ifcfg-eth0

#set up /etc/selinux/config
sed -i s/^SELINUX=.*/SELINUX=${selinux}$i/ /etc/selinux/config

echo "***********************************************
inited system as bellow,please reboot system to take effect...
hostname=${hostname}
mac=${mac}
ip=${ipaddr}
selinux=${selinux}
****************************************************"

3、執行初始化腳本,初始化系統

[root@demo ~]# bash inisystem.sh
***********************************************
inited system as bellow,please reboot system to take effect...
hostname=mysql.master
mac=00:0C:29:40:78:36
ip=172.16.16.102
selinux=disabled
****************************************************

2016-11-08 BUG修復:

使用中發現有一處Bug ,具體語句爲:

#set up /etc/selinux/config
sed -i s/^SELINUX.*/SELINUX=${selinux}$i/ /etc/selinux/config
修改的內容爲:

[root@demo ~]# cat /etc/selinux/config 
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=enforcing
# SELINUXTYPE= can take one of these two values:
#     targeted - Targeted processes are protected,
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted
此語句執行之後變成了:

[root@demo ~]# cat /etc/selinux/config 
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
#     targeted - Targeted processes are protected,
#     mls - Multi Level Security protection.
SELINUX=disabled
很明顯正則寫錯了,修復成現在的版本即可(其他地方由於沒有兩個類似的變量,所以無需更改也可以,嚴格來說,都改比較好)




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章