(2). 更改mysql目录中的文件的属主、属组为mysql用户和mysql组:
[iyunv@mysql mysql]# pwd
/usr/local/mysql
[iyunv@mysql mysql]# chown -R mysql:mysql *
[iyunv@mysql mysql]# ll
total 172
drwxr-xr-x. 2 mysql mysql 4096 Jul 13 22:49bin
-rw-r--r--. 1 mysql mysql 17987 Mar 26 00:34COPYING
drwxr-xr-x. 3 mysql mysql 4096 Jul 13 22:49data
drwxr-xr-x. 2 mysql mysql 4096 Jul 13 22:49docs
drwxr-xr-x. 3 mysql mysql 4096 Jul 13 22:49include
-rw-r--r--. 1 mysql mysql 102986 Mar 26 00:35 INSTALL-BINARY
drwxr-xr-x. 3 mysql mysql 4096 Jul 13 22:49lib
drwxr-xr-x. 4 mysql mysql 4096 Jul 13 22:49man
drwxr-xr-x. 10 mysql mysql 4096 Jul 13 22:49 mysql-test
-rw-r--r--. 1 mysql mysql 2496 Mar 26 00:34README
drwxr-xr-x. 2 mysql mysql 4096 Jul 13 22:49scripts
drwxr-xr-x. 28 mysql mysql 4096 Jul 13 22:49 share
drwxr-xr-x. 4 mysql mysql 4096 Jul 13 22:49sql-bench
drwxr-xr-x. 2 mysql mysql 4096 Jul 13 22:49support-files
[iyunv@mysql mysql]#
4、初始化mysql数据库:
执行scripts目录下的脚本,该文件作用:mysql需要初始化,这个步骤就是完成初始化的,我们需要手动完成。
[iyunv@mysql mysql]# scripts/mysql_install_db --user=mysql --datadir=/mydata/data/
Installing MySQL systemtables..../bin/mysqld: error while loading shared libraries: libaio.so.1:cannot open shared object file: No such file or directory
[iyunv@mysql mysql]#
[iyunv@mysql mysql]# yum install -y libaio
[iyunv@mysql mysql]# scripts/mysql_install_db --user=mysql--datadir=/mydata/data/ 为了安全,需要把mysql目录下文件属主更改回root用户:
[iyunv@mysql mysql]# chown -R root /usr/local/mysql/*
8、为mysql添加密码:
[iyunv@make ~]# mysqladmin -u root password '123456'
Warning: Using a password on the commandline interface can be insecure.
[iyunv@make ~]# 说明: mysql-5.6会提示命令行使用密码不安全的。
(1)安装apr:
[iyunv@httpa bao]# tar xf apr-1.5.2.tar.bz2
[iyunv@httpa bao]# cd apr-1.5.2
[iyunv@httpa apr-1.5.2]# ./configure--prefix=/usr/local/apr
[iyunv@httpa apr-1.5.2]# make
[iyunv@httpa apr-1.5.2]# make install
(2)安装apr-util:
[iyunv@httpa bao]# tar xf apr-util-1.5.4.tar.bz2
[iyunv@httpa bao]# cd apr-util-1.5.4
[iyunv@httpa apr-util-1.5.4]# ./configure--prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[iyunv@httpa apr-util-1.5.4]# make
[iyunv@httpa apr-util-1.5.4]# make install
2、启动服务进行简单测试
[iyunv@httpa ~]# /usr/local/apache/bin/apachectl start
[iyunv@httpa ~]# setenforce 0
[iyunv@httpa ~]# service iptables stop
iptables: Setting chains to policy ACCEPT:filter [ OK ]
iptables: Flushing firewall rules: [ OK ]
iptables: Unloading modules: [ OK ]
[iyunv@httpa ~]#
[iyunv@httpa ~]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 :::80 :::* LISTEN 51267/httpd
[iyunv@httpa ~]#
网页192.168.217显示It works!
3、为了更好的管理和使用httpd服务,可为其提供PATH环境变量和SysV风格的脚本。
(1) 提供PATH环境变量:
[iyunv@httpa ~]# vim /etc/profile.d/httpd.sh
export PATH=$PATH:/usr/local/apache/bin
"/etc/profile.d/httpd.sh" [New]1L, 40C written
[iyunv@httpa ~]# . /etc/profile.d/httpd.sh
[iyunv@httpa ~]#
(2) 提供SysV风格的脚本:
[iyunv@httpa ~]# vim /etc/init.d/httpd
#!/bin/bash
#
# chkconfig: - 85 15
# description: Apache is a World Wide Webserver. It is used to serve \
. /etc/rc.d/init.d/functions
if [ -f /etc/sysconfig/httpd ]; then
./etc/sysconfig/httpd
fi
# Start httpd in the C locale by default.
HTTPD_LANG=${HTTPD_LANG-"C"}
# This will prevent initlog from swallowingup a pass-phrase prompt if
# mod_ssl needs a pass-phrase from theuser.
INITLOG_ARGS=""
# Set HTTPD=/usr/sbin/httpd.worker in/etc/sysconfig/httpd to use a server
# with the thread-based "worker"MPM; BE WARNED that some modules mays not
# work correctly with a thread-based MPM;notably PHP will refuse to start.
# Path to the apachectl script, serverbinary, and short-form for messages.
apachectl=/usr/local/apache/bin/apachectl
httpd=${HTTPD-/usr/local/apache/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/var/run/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd}
RETVAL=0
start() {
echo -n $"Starting $prog: "
LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch ${lockfile}
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc -p ${pidfile} -d 10 $httpd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}
reload() {
echo -n $"Reloading $prog: "
if! LANG=$HTTPD_LANG $httpd $OPTIONS -t &> /dev/null; then
RETVAL=$?
echo $"not reloading due to configuration sysntax error"
else
killproc -p ${pidfile} $httpd -HUP
RETVAL=$?
fi
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status -p ${pidfile} $httpd
RETVAL=$?
;;
restart)
stop
start
;;
condrestart)
if [ -f ${pidfile} ]; then
stop
start
fi
;;
reload)
reload
;;
graceful|htlp|configtest|fullstatus)
$apachectl $@
RETVAL=$?
;;
*)
echo "Usage: $prog {start|stop|restart|reload|status|help}"
exit 1
;;
esac
exit $RETVAL
"/etc/rc.d/init.d/httpd" [New]85L, 2084C written
[iyunv@httpa ~]# chmod +x /etc/init.d/httpd
[iyunv@httpa ~]# chkconfig --add httpd
[iyunv@httpa ~]# chkconfig httpd on
[iyunv@httpa ~]#
4、更换pid进程文件存放目录: 每个进程启动后都会有个pid文件,编译安装httpd的pid文件在logs目录里面,系统进程一般pid文件都放在/var/run目录下,如果想更换pid进程文件存放目录,需要在主配置文件中加入PidFile "/var/run/httpd.pid"项,注意:编译安装默认没有该项,需要手工加入:
[iyunv@httpa ~]# vim /etc/httpd/httpd.conf
34 pidfile "/var/run/httpd.pid"
[iyunv@httpa ~]# netstat -lntp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 :::80 :::* LISTEN 51563/httpd
[iyunv@httpa ~]# kill 51563
[iyunv@httpa ~]# service httpd start
[iyunv@httpa ~]# ll -d /var/run/httpd.pid
-rw-r--r--. 1 root root 6 Jul 13 23:43/var/run/httpd.pid
[iyunv@httpa ~]#
5、为httpd添加man帮助及输出头文件:
(1) 为httpd添加man帮助:
[iyunv@http ~]# yum install -y man pages (最小化安装系统如果没有man手册需要安装)
[iyunv@http ~]# vim /etc/man.config
48 MANPATH /usr/local/apache/man
[iyunv@http ~]# man httpd
4、重启httpd服务,测试PHP网页:
[iyunv@httpa ~]# vim /usr/local/apache/htdocs/index.php
<?php
phpinfo();
?>
"/usr/local/apache/htdocs/index.php"[New] 4L, 21C written
[iyunv@httpa ~]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
[iyunv@httpa ~]#
浏览器测试是否出现PHP网页!
在192.168.1.218主机上安装apache和php,和192.168.1.217安装一样!
五、配置安装Discuz并验证
1.分别在192.168.1.217和192.168.1.218两台主机上挂载nfs共享目录:
[iyunv@httpa ~]# mount -t nfs 192.168.1.219:/shared /usr/local/apache/htdocs/
mount: wrong fs type, bad option, badsuperblock on 192.168.1.219:/shared,
missing codepage or helper program, or other error
(for several filesystems (e.g. nfs, cifs) you might
need a /sbin/mount.<type> helper program)
In some cases useful info is found in syslog - try
dmesg | tail or so
[iyunv@httpa ~]#
需要安装nfs-utils:
[iyunv@httpa ~]# yum install -y nfs-utils
[iyunv@httpa ~]# mount -t nfs 192.168.1.219:/shared/usr/local/apache/htdocs/
[iyunv@httpa ~]# mount
/dev/mapper/vg_httpa-lv_root on / type ext4(rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts(rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs(rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc typebinfmt_misc (rw)
192.168.1.219:/shared on/usr/local/apache/htdocs type nfs(rw,vers=4,addr=192.168.1.219,clientaddr=192.168.1.217)
[iyunv@httpa ~]#
授权两台web服务器可以连接数据库:
mysql> use mysql;
Reading table information for completion oftable and column names
You can turn off this feature to get aquicker startup with -A
Database changed
mysql> grant all privileges on *.* to'root'@'192.168.1.217' identified by '123456';
Query OK, 0 rows affected (0.00 sec)
mysql> grant all privileges on *.* to'root'@'192.168.1.218' identified by '123456';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql>