1 2 3 4 5 6 7 8 | [root@NFS ~] # hsotname NFS [root@NFS ~] # vim/etc/sysconfig/network NETWORKING= yes HOSTNAME=NFS [root@NFS ~] # vim /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 IPADDR=172.16.100.1 ONBOOT= yes |
1 2 3 4 5 6 7 8 9 | [root@node1 ~] # hostname node1.sange.com [root@node1 ~] #vim/etc/sysconfig/network NETWORKING= yes HOSTNAME=node1.sange.com [root@node1 ~] # vim/etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 BOOTPROTO=static ONBOOT= yes IPADDR=172.16.100.11 |
1 2 3 4 5 6 7 8 9 | [root@node2 ~]# hostnamenode2.sange.com [root@node2 ~]# vim/etc/sysconfig/network NETWORKING=yes HOSTNAME=node2.sange.com [root@node2 ~]#vim/etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 BOOTPROTO= static IPADDR= 172.16 . 100.12 ONBOOT=yes |
2:在MySQL1和MySQL2上实现双机互信
1 2 3 4 5 | #Do not remove the following line, or var ious programs #that require network functionality will fail. 127.0 . 0.1 localhost.localdomain localhost 172.16 . 100.11 node1.sange.com node1 172.16 . 100.12 node2.sange.com node2 |
1 2 3 4 5 6 | [root@node2 ~]#vim/etc/hosts #Do not remove the following line, or var ious programs #that require network functionality will fail. 127.0 . 0.1 localhost.localdomain localhost 172.16 . 100.11 node1.sange.com node1 172.16 . 100.12 node2.sange.com node2 |
1 | [root@node1~]# ssh-keygen -t rsa |
1 | [root@node1 ~]#ssh-copy-id-i .ssh/id_rsa.pub root@ 172.16 . 100.12 |
1 | [root@node2~]#ssh-keygen -t rsa |
1 | [root@node2 ~]#ssh-copy-id-i .ssh/id_rsa.pub root@ 172.16 . 100.11 |
3:在NFS Server上通过建立逻辑卷共享数据
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 | [root@NFS ~]# fdisk /dev/sda //对磁盘分区 The number of cylinders for this disk is set to 15665 . There is nothing wrong with that, but this is larger than 1024 , and could in certain setups cause problems with : 1 ) software that runs at boot time (e.g., old versions of LILO) 2 ) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/ 2 FDISK) Command (m for help): n //新建一个磁盘 Command action
e extended
p primary partition ( 1 - 4 ) e //扩展分区 Selected partition 4 First cylinder ( 5359 - 15665 , default 5359 ): Using default value 5359 Last cylinder or +size or +sizeM or +sizeK ( 5359 - 15665 , default 15665 ): Using default value 15665 Command (m for help): n First cylinder ( 5359 - 15665 , default 5359 ): Using default value 5359 Last cylinder or +size or +sizeM or +sizeK ( 5359 - 15665 , default 15665 ): +20G //大小为20G Command (m for help): P // 显示磁盘分区 Disk /dev/sda: 128.8 GB, 128849018880 bytes 255 heads, 63 sectors/track, 15665 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System /dev/sda1 * 1 13 104391 83 Linux /dev/sda2 14 5235 41945715 8e Linux LVM /dev/sda3 5236 5358 987997 + 83 Linux /dev/sda4 5359 15665 82790977 + 5 Extended /dev/sda5 5359 7791 19543041 83 Linux Command (m for help): T //设定磁盘类型 Partition number ( 1 - 5 ): 5 Hex code (type L to list codes): 8e //创建LVM时的专用格式 Changed system type of partition 5 to 8e (Linux LVM) Command (m for help): w //保存新建的磁盘分区 The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error 16 : Device or resource busy. The kernel still uses the old table. The new table will be used at the next reboot. Syncing disks. [root@NFS ~]# partprobe /dev/sda //重新格式化一下 要建立逻辑卷,先要建立物理卷,然后建立卷组,最后才能建立逻辑卷。 [root@NFS ~]# pvcreate /dev/sda5 //创建物理卷 [root@NFS ~]# vgcreate myvg /dev/sda5 //创建卷组 [root@NFS ~]# vgs //显示新建的卷组
VG #PV #LV #SN Attr VSize VFree
myvg 1 0 0 wz--n- 18 .64G 18 .64G
vg0 1 4 0 wz--n- 40 .00G 0 [root@NFS ~]# lvcreate -L 10G -n mydata myvg //创建逻辑卷 [root@NFS ~]# lvs //显示新建的卷组
LV VG Attr LSize Origin Snap% Move Log Copy% Convert
mydata myvg -wi-a- 10 .00G [root@NFS ~]#mke2fs –j –L MYDATA /dev/myvg/mydata [root@NFS ~]# mkdir /mydata [root@NFS ~]#vim /etc/fstab //添加如下内容 LABEL=MYDATA /mydata ext3 defaults 0 0 [root@NFS ~]#mount –a //重新挂载一下 |
1 2 3 4 5 6 | [root@NFS ~]# groupadd -g 306 -r mysql [root@NFS ~]# useradd -g mysql -r -u 306 -s /sbin/nologin mysql 将/mydata的属主和属组改为mysql: [root@NFS ~]# chown -R mysql:mysql /mydata/ [root@NFS ~]# vim /etc/exports //将/mydata目录导出出去,172.16.0.0网段内的用户可以读写/mydata目录中的文件。 /mydata 172.16 . 0.0 / 16 (rw,no_root_squash) |
1 | [root@NFS ~]# service nfs start |
1 | [root@NFS ~]# chkconfig nfs on |
1 2 3 | [root@node1 ~]# groupadd -r -g 306 mysql [root@node1 ~]# useradd -g mysql -u 306 -r mysql [root@node1 ~]# mkdir /mydata |
1 | [root@node1 ~]# mount -t nfs 172.16 . 100.1 :/mydata/mydata/ |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | [root@node1~]# tar xf mysql- 5.5 . 22 -linux2. 6 -i686.tar.gz -C /usr/local [root@node1 ~]# cd /usr/local [root@node1 local]# ln -sv mysql- 5.5 . 22 -linux2. 6 -i686 mysql [root@node1 local]# cd mysql [root@node1 mysql]# chown -R mysql:mysql . [root@node1 mysql]# scripts/mysql_install_db --user=mysql --datadir=/mydata/data [root@node1 mysql]# cp support-files/my-large.cnf /etc/my.cnf //为mysql提供主配置文件 [root@node1 mysql]# vim /etc/my.cnf //修改mysqld的主配置文件,添加如下两行: thread_concurrency = 2 datadir = /mydata/data [root@node1mysql]#cp support-files/mysql.server /etc/init.d/mysqld // 为mysql提供sysv服务脚本 [root@node1 mysql]# vim /etc/profile //修改PATH环境变量,让系统可以直接使用mysql的相关命令,添加如下行 PATH=$PATH:/usr/local/mysql/bin [root@node1 mysql]# chown -R root . //将属主重新改为root [root@node1 mysql]# chkconfig --add mysqld //将mysqld添加至服务列表 [root@node1 mysql]# service mysqld start //启动mysqld服务 |
1 2 | [root@node1 ~]# service mysqld stop [root@node1 ~]# chkconfig mysqld off |