主从节点的基本环境配置: node1.ws.cn 网卡1:192.168.2.10 心跳线:172.16.10.1 主节点
node2.ws.cn 网卡1:192.168.2.20 心跳线:172.16.10.2 从节点
修改主机名: vim /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=node1.ws.cn
节点2则设置为node2.ws.cn
修改hosts文件 为了实验方便这里不再安装DNS服务器,只是更改hosts文件
[root@node1 ~]# cat /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1 localhost.localdomain localhost
::1 localhost6.localdomain6 localhost6
192.168.2.10 node1.ws.cn
192.168.2.20 node2.ws.cn
节点2与节点1同样的设置不再重复
增加一块新的磁盘用来做冗余备份 [root@node1 ~]# fdisk -l
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 261 2096451 83 Linux
/dev/sda2 262 656 3172837+ 82 Linux swap / Solaris
/dev/sda3 657 787 1052257+ 83 Linux
/dev/sda4 788 2610 14643247+ 5 Extended
/dev/sda5 788 2610 14643216 83 Linux
Disk /dev/sdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/sdb doesn't contain a valid partition table
[root@node1 ~]# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
Command (m for help): p
Disk /dev/sdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4):
Value out of range.
Partition number (1-4):
Value out of range.
Partition number (1-4): 1
First cylinder (1-652, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-652, default 652):
Using default value 652
Command (m for help): p
Disk /dev/sdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 652 5237158+ 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@node1 ~]# 在主从节点上执行: hwclock -s 同步节点时区
下面用源码来搭建lamp环境,用于操作管理mysql
为了使实验的顺利进行,首先检查系统是否安装了apache,php及mysql的软件包,
Rpm –qa 服务名称(例:如apache,rpm –qa httpd)
如果安装了就将其卸载: rpm –e 服务名称
也可以用yum来卸载,可以很好的解决依赖性关系
在主从服务器上
配置mysql-5.5.22.tar.gz 的绿色安装包 解压压缩包
Tar -zxvf mysql-5.5.15-linux2.6-i686.tar.gz -C /usr/local/
进入目录:
cd /usr/local/
为了以后的操作方便添加以下连接
ln -s mysql-5.5.15-linux2.6-i686 mysql
进入mysql主目录
cd mysql
查看主目录下的所有文件
ll
[root@node1 mysql]# ll
总计 76
drwxr-xr-x 2 root root 4096 05-18 15:19 bin
-rw-r--r-- 1 7161 wheel 17987 2011-07-14 COPYING
drwxr-xr-x 4 root root 4096 05-18 15:21 data
drwxr-xr-x 2 root root 4096 05-18 15:22 docs
drwxr-xr-x 3 root root 4096 05-18 15:21 include
-rw-r--r-- 1 7161 wheel 7604 2011-07-14 INSTALL-BINARY
drwxr-xr-x 3 root root 4096 05-18 15:22 lib
drwxr-xr-x 4 root root 4096 05-18 15:19 man
drwxr-xr-x 10 root root 4096 05-18 15:22 mysql-test
-rw-r--r-- 1 7161 wheel 2552 2011-07-14 README
drwxr-xr-x 2 root root 4096 05-18 15:22 scripts
drwxr-xr-x 27 root root 4096 05-18 15:21 share
drwxr-xr-x 4 root root 4096 05-18 15:22 sql-bench
drwxr-xr-x 2 root root 4096 05-18 15:22 support-files
添加mysql用户组
Groupadd mysql
在mysql组内添加一个mysql用户
Useradd –r -g mysql mysql
更改当前目录下的所有文件的所有者和所属组
Chown –R mysql .
Chgrp –R mysql .
更改后的文件属性
[root@node1 mysql]# ll
总计 76
drwxr-xr-x 2 mysql mysql 4096 05-18 15:19 bin
-rw-r--r-- 1 mysql mysql 17987 2011-07-14 COPYING
drwxr-xr-x 4 mysql mysql 4096 05-18 15:21 data
drwxr-xr-x 2 mysql mysql 4096 05-18 15:22 docs
drwxr-xr-x 3 mysql mysql 4096 05-18 15:21 include
-rw-r--r-- 1 mysql mysql 7604 2011-07-14 INSTALL-BINARY
drwxr-xr-x 3 mysql mysql 4096 05-18 15:22 lib
drwxr-xr-x 4 mysql mysql 4096 05-18 15:19 man
drwxr-xr-x 10 mysql mysql 4096 05-18 15:22 mysql-test
-rw-r--r-- 1 mysql mysql 2552 2011-07-14 README
drwxr-xr-x 2 mysql mysql 4096 05-18 15:22 scripts
drwxr-xr-x 27 mysql mysql 4096 05-18 15:21 share
drwxr-xr-x 4 mysql mysql 4096 05-18 15:22 sql-bench
drwxr-xr-x 2 mysql mysql 4096 05-18 15:22 support-files
Scripts/mysql_install_db --user=mysql
Chown –R root .
Chown –R mysql data
[root@node1 mysql]# ll
总计 76
drwxr-xr-x 2 root mysql 4096 05-18 15:19 bin
-rw-r--r-- 1 root mysql 17987 2011-07-14 COPYING
drwxr-xr-x 5 mysql mysql 4096 05-18 15:31 data
drwxr-xr-x 2 root mysql 4096 05-18 15:22 docs
drwxr-xr-x 3 root mysql 4096 05-18 15:21 include
-rw-r--r-- 1 root mysql 7604 2011-07-14 INSTALL-BINARY
drwxr-xr-x 3 root mysql 4096 05-18 15:22 lib
drwxr-xr-x 4 root mysql 4096 05-18 15:19 man
drwxr-xr-x 10 root mysql 4096 05-18 15:22 mysql-test
-rw-r--r-- 1 root mysql 2552 2011-07-14 README
drwxr-xr-x 2 root mysql 4096 05-18 15:22 scripts
drwxr-xr-x 27 root mysql 4096 05-18 15:21 share
drwxr-xr-x 4 root mysql 4096 05-18 15:22 sql-bench
drwxr-xr-x 2 root mysql 4096 05-18 15:22 support-files
添加mysql的环境变量
Vim /etc/profile
. /etc/profile //重新读取文件,使变量生效
查看
[root@node1 httpd-2.2.19]# echo $PATH
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin:/usr/local/mysql/bin:/usr/local/apache/bin
Mysql变量 ,apache变量
配置头文件
Cd /etc/ld.so.conf.d/
Vim httpd.conf
插入:/usr/local/apache/bin
Ldconfig -v //重新加载头文件
配置库文件
Cd /usr/include/
Ln -s /usr/local/apache/include httpd
查看
[root@node1 include]# ll |grep httpd
lrwxrwxrwx 1 root root 25 05-18 23:51 httpd -> /usr/local/apache/include
[root@node1 include]#
添加启动项:
cd /etc/init.d/
cp /usr/local/apache/bin/apachectl /etc/init.d/httpd
启动apache
service httpd start
查看监听端口:
[root@node1 include]# netstat -tupln |grep httpd
tcp 0 0 :::80 :::* LISTEN 30070/httpd
安装并配置php-5.3.7.tar.bz2源码压缩包 。
Tar -jxvf php-5.3.7.tar.bz2 -C /usr/local/src //解压缩
Cd /usr/local/src/php-5.3.7/ //切换目录
./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --enable-mbstring=all //配置
Make //编译
Make install //安装
编辑主配置文件
vim /etc/httpd/httpd.conf
手工编译安装php后,如果一切顺利解决了的话,重启apache时,libphp5.so: cannot restore segment prot after reloc: Permission denied 错误:如果你是开着seliunx 的话,运行下面的命令: chcon -t texrel_shlib_t /usr/local/apache/modules/libphp5.so 如果 没有开selinux 的话,找到libphp5.so,然后chmod 777 libphp5.so 源自:http://www.phpfreaks.com/forums/index.php?topic=133131.0;wap2
重启apache服务确保更新的配置都能起作用
service httpd restart
测试: Mv index.html index.php
Cd /usr/local/apache/htdocs/
Vim index.php
结果:
测试 php 与 mysql 的连接
修改网页文件如下:
Vim index.php
结果:
基本环境搭建完成
命令行登录如下:
[root@node1 Server]# /usr/local/mysql/bin/mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.5.15-log MySQL Community Server (GPL)
Copyright (c) 2000, 2010, 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>
mysql>
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.22 sec)
mysql>
添加web管理平台 往往为了管理的方便还可以加载一个phpmyadmin管理平台
解压缩包
unzip -xvf phpMyAdmin-2.11.10.1-all-languages.zip
更改包名并移动到主站点下
mv phpMyAdmin-2.11.10.1-all-languages /usr/local/apache/htdocs/
在本地浏览器输入:http://localhost/phpmyadmin