大纲@H_404_2@
一、编译安装Apache @H_404_2@
五、安装Xcache加速器@H_404_2@
六、启用服务器状态@H_404_2@
八、安装Discuz论坛(Discuz_X3.0_SC_GBK)@H_404_2@
注:所有软件版本 CentOS6.4+httpd2.4.4+MysqL5.6.12+PHP5.4.16+xcache3.03 都是目前最新(所有的安装包点击这里下载)@H_404_2@
一、编译安装Apache @H_404_2@
1. 安装前准备@H_404_2@
123@H_301_65@ 456789101112131415161718192021222324252627282930313233343536373839404142[root@web ~]
# yum install wget
[root@web ~]
# wget http://mirrors.163.com/.help/CentOS6-Base-163.repo
@H_301_65@--2013-06-29 18:39:02-- http:
//mirrors
.163.com/.help
/CentOS6-Base-163
.repo
Resolving mirrors.163.com... 123.58.173.106
Connecting to mirrors.163.com|123.58.173.106|:80... connected.
HTTP request sent,awaiting response... 200 OK
Length: 2006 (2.0K) [application
/octet-stream
]
Saving to: a?CentOS6-Base-163.repo?
100%[================>] 2,006 --.-K
/s
in
0s
2013-06-29 18:39:02 (152 MB
/s
) - a?CentOS6-Base-163.repoa? saved [2006
/2006
]
[root@web ~]
# cd /etc/yum.repos.d/
[root@web yum.repos.d]
# mv CentOS-Base.repo CentOS-Base.repo.bak
[root@web yum.repos.d]
# mv /root/CentOS6-Base-163.repo CentOS-Base.repo
[root@web yum.repos.d]
# ls
CentOS-Base.repo CentOS-Media.repo
CentOS-Base.repo.bak CentOS-Vault.repo
CentOS-Debuginfo.repo
[root@web yum.repos.d]
# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: base extras updates
Cleaning up Everything
Cleaning up list of fastest mirrors
[root@web yum.repos.d]
# yum makecache
Loaded plugins: fastestmirror
Determining fastest mirrors
base | 3.7 kB 00:00
base
/group_gz
| 212 kB 00:00
base
/filelists_db
| 5.9 MB 00:01
base
/primary_db
| 4.4 MB 00:01
base
/other_db
| 2.7 MB 00:00
extras | 3.4 kB 00:00
extras
/filelists_db
| 10 kB 00:00
extras
/prestodelta
| 905 B 00:00
extras
/primary_db
| 18 kB 00:00
extras
/other_db
| 5.7 kB 00:00
updates | 3.4 kB 00:00
updates
/filelists_db
| 2.9 MB 00:00
updates
/prestodelta
| 617 kB 00:02
updates
/primary_db
| 3.2 MB 00:00
updates
/other_db
| 419 kB 00:00
Metadata Cache Created
[root@web yum.repos.d]
#
安装编译工具@H_404_2@
123@H_301_65@ 456789101112131415[root@web yum.repos.d]
#yum groupinstall "Development Tools" "Development Libraries" �y
[root@web yum.repos.d]
# yum grouplist
@H_301_65@Loaded plugins: fastestmirror
Setting up Group Process
Loading mirror speeds from cached hostfile
Installed Groups:
Development tools
E-mail server
Fonts
General Purpose Desktop
Graphical Administration Tools
Input Methods
Legacy X Window System compatibility
MysqL Database client
Perl Support
123@H_301_65@ 456789101112[root@web ~]
# vim /etc/selinux/config
# This file controls the state of SELinux on the system.
@H_301_65@# 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.
SELINUXTYPE=targeted
[root@web ~]
# reboot
123@H_301_65@ 45678[root@web ~]
# service iptables stop
[root@web ~]
# service ip6tables stop
@H_301_65@[root@web ~]
# chkconfig iptables off
[root@web ~]
# chkconfig ip6tables off
[root@web ~]
# chkconfig iptables --list
iptables 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[root@web ~]
# chkconfig ip6tables --list
ip6tables 0:off 1:off 2:off 3:off 4:off 5:off 6:off
123@H_301_65@ 4567[root@web ~]
# vim /etc/sysconfig/network
NETWORKING=
yes
@H_301_65@HOSTNAME=web.
test
.com
~
[root@web ~]
# vim /etc/hosts
127.0.0.1 web web.
test
.com localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
httpd-2.4.4需要较新版本的apr和apr-util,因此需要事先对其进行升级。升级方式有两种,一种是通过源代码编译安装,一种是直接升级rpm包。@H_404_2@
(1). 编译安装apr@H_404_2@
@H_404_2@
1
2
3
@H_301_65@
4
5
6
|
[root@web src]
# tar xf apr-1.4.6.tar.bz2
[root@web src]
# cd apr-1.4.6
[root@web src]
# ./configure --help | less (可以查看帮助文件)
[root@web src]
# ./configure --prefix=/usr/local/apr (指定安装路径)
[root@web src]
# make
[root@web src]
# make install
|
@H_404_2@
(2). 编译安装apr-util@H_404_2@
1
2
3
@H_301_65@
4
5
6
7
|
[root@web src]
# tar xf apr-util-1.5.2.tar.bz2
[root@web src]
# cd apr-util-1.5.2
[root@web src]
# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
(--prefix指定安装路径;--with-apr指定apr的安装路径,apr-util依赖于apr)
[root@web src]
# make && make install
附:apache官方对APR的介绍:
The mission of the Apache Portable Runtime (APR) project is to create and maintain software libraries that provide a predictable and consistent interface to underlying platform-specific implementations. The primary goal is to provide an API to
which
software developers may code and be assured of predictable
if
not identical behavIoUr regardless of the platform on
which
their software is built,relieving them of the need to code special-
case
conditions to work around or take advantage of platform-specific deficiencies or features.
|
(3). httpd-2.4.4编译过程也要依赖于pcre-devel软件包,需要事先安装。@H_404_2@
1
|
[root@web ~]
# yum install pcre-devel -y
|
3. 编译安装httpd-2.4.4@H_404_2@
1
2
3
@H_301_65@
4
5
6
7
8
9
10
11
12
13
|
[root@web src]
# tar xf httpd-2.4.4.tar.gz
[root@web src]
# cd httpd-2.4.4
[root@web httpd-2.4.4]
# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-cgi --enable-cgid --enable-modules=most --enable-mods-shared=most --enable-rewrite --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-mpms-shared=all --with-mpm=event
--sysconfdir=
/etc/httpd
:指定配置文件安装位置
--with-zlib :压缩库,在互联网上传播时可节约带宽
--with-apr=
/usr/local/apr
:指定apr路径
--with-apr-util=
/usr/local/apr-util
:指定apr-util路径
--with-mpm=event :设定默认的模块
|
1
|
checking whether to
enable
mod_ssl... configure: error: mod_ssl has been requested but can not be built due to prerequisite failures
|
1
|
[root@web httpd-2.4.4]
# yum install -y openssl-devel
|
补充说明:@H_404_2@
(1)构建MPM为静态模块
在 全部平台中,MPM都可以构建为静态模块。在构建时选择一种MPM,链接到服务器中。如果要改变MPM,必须重新构建。为了使用指定的MPM,请在执行 configure脚本 时,使用参数 --with-mpm=NAME。NAME是指定的MPM名称。编译完成后,可以使用 httpd -l 来确定选择的MPM。 此命令会列出编译到服务器程序中的所有模块,包括 MPM。 @H_404_2@
(2)构建 MPM 为动态模块
在 Unix或类似平台中,MPM可以构建为动态模块,与其它动态模块一样在运行时加载。 构建 MPM 为动态模块允许通过修改LoadModule指令内容来改变MPM,而不用重新构建服务器程序。在执行configure脚本时,使用--enable- mpms-shared选项即可启用此特性。当给出的参数为all时,所有此平台支持的MPM模块都会被安装。还可以在参数中给出模块列表。默认MPM, 可以自动选择或者在执行configure脚本时通过--with-mpm选项来指定,然后出现在生成的服务器配置文件中。编辑LoadModule指令 内容可以选择不同的MPM。@H_404_2@
4. 修改httpd的主配置文件,设置其Pid文件的路径@H_404_2@
说明:手动编译安装后,httpd.pid文件是存放在/usr/local/apache/logs/目录下的,这个位置未免有些不方便。@H_404_2@
1
2
3
@H_301_65@
4
5
6
|
[root@web httpd-2.4.4]
# cd
[root@web ~]
# cd /etc/httpd/
[root@web httpd]
# ls
conf conf.d extra httpd.conf logs magic mime.types modules original run
[root@web httpd]
# cp httpd.conf httpd.conf.bak
[root@web httpd]
# vim httpd.conf
|
#在配置文件中找一个位置定义一下Pid文件路径就可以了@H_404_2@
1
|
Pidfile
"/var/run/httpd.pid"
|
5. 提供SysV服务脚本/etc/rc.d/init.d/httpd@H_404_2@
1
2
3
@H_301_65@
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
@H_802_1404@
78
79
80
81
82
83
84
85
|
[root@web httpd]
# vim /etc/init.d/httpd
#!/bin/bash
#
# chkconfig: - 85 15
# description: Apache is a World Wide Web server. It is used to serve \
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 swallowing up a pass-phrase prompt if
# mod_ssl needs a pass-phrase from the user.
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 may not
# work correctly with a thread-based MPM; notably PHP will refuse to start.
# Path to the apachectl script,server binary,and short-form for messages.
apachectl=
/usr/local/apache/bin/apachectl
# -----指定apachectl程序位置
httpd=${HTTPD-
/usr/local/apache/bin/httpd
}
#-------httpd程序位置
prog=httpd
RETVAL=0
start() {
echo
-n $
"Starting $prog: "
RETVAL=$?
#------定义执行状态返回值
echo
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=$?
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|help|configtest|fullstatus)
$apachectl $@
RETVAL=$?
;;
*)
echo
$
"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"
exit
1
esac
exit
$RETVAL
|
[root@web httpd]# chmod +x /etc/init.d/httpd #添加执行权限 @H_404_2@
#设置开机自启动@H_404_2@
1
2
3
@H_301_65@
4
5
|
[root@web httpd]
# chkconfig httpd --add
[root@web httpd]
# chkconfig httpd on
[root@web httpd]
# chkconfig httpd --list
httpd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@web httpd]
#
|
6. 启动apache并测试@H_404_2@
1
2
3
@H_301_65@
4
5
6
7
8
9
10
11
12
13
14
|
[root@web httpd]
# service httpd start
Starting httpd: AH00558: httpd: Could not reliably determine the server
's fully qualified domain name,using web.test.com. Set the '
ServerName' directive globally to suppress this message
[ OK ]
[root@web httpd]
#
[root@web httpd]
# netstat -ntulp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID
/Program
name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 990
/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1066
/master
tcp 0 0 :::80 :::* LISTEN 36920
/httpd
tcp 0 0 :::22 :::* LISTEN 990
/sshd
tcp 0 0 ::1:25 :::* LISTEN 1066
/master
udp 0 0 0.0.0.0:68 0.0.0.0:* 890
/dhclient
[root@web httpd]
#
|
启动成功了,但似乎有警告,我们看一下!@H_404_2@
1
|
Starting httpd: AH00558: httpd: Could not reliably determine the server
's fully qualified domain name,using web.test.com. Set the '
ServerName' directive globally to suppress this message
|
编辑httpd.conf文件,搜索"/ServerName",添加ServerName localhost:80@H_404_2@
1
2
3
@H_301_65@
4
5
6
|
[root@web httpd]
# vim /etc/httpd/httpd.conf
再重新启动apache 即可。
[root@web httpd]
# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
[root@web httpd]
#
|
好了问题解决,下面我们用Windows 7访问一下!效果如下:@H_404_2@
好了测试成功,下面我们继续!@H_404_2@
7. 为httpd服务的相关命令添加环境变量@H_404_2@
1
2
3
|
[root@web httpd]
# httpd
-
bash
: httpd:
command
not found
[root@web httpd]
#
|
大 家看到了,虽然我们可以使用 service httpd restart 来重新启动Apache,是我们无法使用httpd命令,下面我们就来解决一下!直接在/etc/profile.d目录下创建的httpd.sh环境变 量文件,因为在默认的情况下这个目录下定义的环境变量都是profile文件的组成部分。@H_404_2@
1
2
3
@H_301_65@
4
5
6
|
[root@web httpd]
# vim /etc/profile.d/httpd.sh
export
PATH=$PATH:
/usr/local/apache/bin
[root@web httpd]
# source /etc/profile #重新读取一下环境变量
[root@web httpd]
# httpd �t #测试一下
Syntax OK
[root@web httpd]
#
|
现在httpd服务的相关命令就可以直接使用了,嘿嘿!@H_404_2@
说明:新建一个逻辑卷,并将其挂载至特定目录即可。这里假设其逻辑卷的挂载目录为/mydata,而后需要创建/mydata/data目录做为MysqL数据的存放目录。@H_404_2@
(1). 先确认下系统里是否有LVM工具,默认没有安装 @H_404_2@
1
2
|
[root@web httpd]
# rpm -qa | grep lvm
[root@web httpd]
# yum install -y lvm2
|
(2). 查看一下磁盘@H_404_2@
1
2
3
@H_301_65@
4
5
6
7
8
9
10
11
12
13
14
15
|
[root@web httpd]
# fdisk -l
Disk
/dev/sda
: 21.5 GB,21474836480 bytes
255 heads,63 sectors
/track
,2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical
/physical
): 512 bytes / 512 bytes
I
/O
size (minimum
/optimal
): 512 bytes / 512 bytes
Disk identifier: 0x0000a0a2
Device Boot Start End Blocks Id System
/dev/sda1
* 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2
26 1301 10240000 83 Linux
/dev/sda3
1301 1938 5120000 83 Linux
/dev/sda4
1938 2611 5405696 5 Extended
/dev/sda5
1939 2066 1024000 82 Linux swap / Solaris
[root@web httpd]
#
|
(3). 创建逻辑分区 @H_404_2@
1
2
3
@H_301_65@
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
|
[root@web ~]
# fdisk /dev/sda
/dev/sda7
2066 2327 2099724 8e Linux LVM
#我这里是测试环境就创建了一个2G分区
[root@web ~]
# partx -a /dev/sda #告诉内核有关存在和磁盘上的分区的编号
[root@web ~]
# pvcreate /dev/sda7 #创建物理卷
Physical volume
"/dev/sda7"
successfully created
[root@web ~]
# vgcreate myvg /dev/sda7 #创建卷组
Volume group
"myvg"
successfully created
[root@web ~]
#
[root@web ~]
# lvcreate -n mydata -L 1G myvg #创建一个1G的逻辑卷
Logical volume
"mydata"
created
[root@web ~]
# lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
mydata myvg -wi-a---- 1.00g
[root@web ~]
#
[root@web ~]
# mkfs.ext4 /dev/myvg/mydata #格式化
[root@web ~]
# mkdir /mydata #创建挂载目录
[root@web ~]
# mount /dev/myvg/mydata /mydata/ #挂载
[root@web ~]
# vim /etc/fstab
[root@web ~]
# mount �a #测试挂载是否成功
[root@web ~]
# mount
/dev/sda2
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)
/dev/sda1
on
/boot
type
ext4 (rw)
/dev/sda3
on
/data
type
ext4 (rw)
none on
/proc/sys/fs/binfmt_misc
type
binfmt_misc (rw)
/dev/mapper/myvg-mydata
on
/mydata
type
ext4 (rw)
[root@web ~]
#
|
(4). 为了便于管理在/mydata目录下再创建个子目录data用于存放数据@H_404_2@
1
2
3
@H_301_65@
4
|
[root@web ~]
# mkdir /mydata/data
[root@web ~]
# ls /mydata/
data lost+found
[root@web ~]
#
|
1
2
3
|
[root@web ~]
# groupadd -r MysqL
|
(1). 说明:MysqL 安装包有三种式,rpm,源码包,二进制包(已编译好,解压后简单配置一下就可以用),我这里用的就是二进制包@H_404_2@
1
2
3
@H_301_65@
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
[root@web src]
# tar -xf MysqL-5.6.12-linux-glibc2.5-x86_64.tar.gz -C /usr/local/ #-C指定解压目录
[root@web
local
]
# cd MysqL
[root@web MysqL]
# ls
COPYING docs INSTALL-BINARY
man
README share support-files
[root@web MysqL]
#
[root@web MysqL]
# ll
total 76
|
(2). 执行MysqL 初始化的data存放位置的准备@H_404_2@
1
2
3
@H_301_65@
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
|
[root@web MysqL]
# scripts/MysqL_install_db --user=MysqL --datadir=/mydata/data #执行MysqL 初始化的data存放位置的准备
Installing MysqL system tables....
/bin/MysqLd
: error
while
loading shared libraries: libaio.so.1: cannot
open
shared object
file
: No such
file
or directory
#初始化时报错说缺少libaio.so我们安装一下
[root@web MysqL]
# yum install libaio
[root@web MysqL]
# scripts/MysqL_install_db --user=MysqL --datadir=/mydata/data #再次执行MysqL 初始化的data存放位置的准备
PLEASE REMEMBER TO SET A PASSWORD FOR THE MysqL root USER !
To
do
so,start the server,
then
issue the following commands:
Alternatively you can run:
which
will also give you the option of removing the
test
databases and anonymous user created by default. This is
strongly recommended
for
production servers.
See the manual
for
more
instructions.
You can start the MysqL daemon with:
The latest information about MysqL is available on the web at
WARNING: Found existing config
file
.
/my
.cnf on the system.
Because this
file
might be
in
use,it was not replaced,
but was used
in
bootstrap (unless you used --defaults-
file
)
and when you later start the server.
The new default config
file
was created as .
/my-new
.cnf,
please compare it with your
file
and take the changes you need.
WARNING: Default config
file
/etc/my
.cnf exists on the system
If you
do
not want to use this,either remove it,or use the
[root@web MysqL]
#
ibdata1 ib_logfile0 ib_logfile1 MysqL performance_schema
test
|
(3). 初始化完成后MysqL中目录文件的属主应改回成root,以免被别人攻破MysqL用户密码而带来数据破坏等@H_404_2@
1
2
3
@H_301_65@
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
[root@web MysqL]
# ll
total 84
drwxr-xr-x 2 root MysqL 4096 Jun 29 21:12 bin
-rw-r--r-- 1 root MysqL 17987 May 21 23:18 COPYING
drwxr-xr-x 3 root MysqL 4096 Jun 29 21:12 data
drwxr-xr-x 2 root MysqL 4096 Jun 29 21:12 docs
drwxr-xr-x 3 root MysqL 4096 Jun 29 21:12 include
-rw-r--r-- 1 root MysqL 7469 May 21 23:18 INSTALL-BINARY
drwxr-xr-x 3 root MysqL 4096 Jun 29 21:12 lib
drwxr-xr-x 4 root MysqL 4096 Jun 29 21:12
man
-rw-r--r-- 1 root root 943 Jun 29 21:18 my.cnf
-rw-r--r-- 1 root root 943 Jun 29 21:23 my-new.cnf
-rw-r--r-- 1 root MysqL 2496 May 21 23:18 README
drwxr-xr-x 2 root MysqL 4096 Jun 29 21:12 scripts
drwxr-xr-x 28 root MysqL 4096 Jun 29 21:12 share
drwxr-xr-x 3 root MysqL 4096 Jun 29 21:12 support-files
[root@web MysqL]
#
|
初始化后会自动在当前目录下创建一个my.cnf配置文件,直接修改就可以(在MysqL 5.6 以后配置文件自动生成,不需要我们再进行复制)@H_404_2@
1
2
3
@H_301_65@
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
|
[root@web MysqL]
# ll
total 84
drwxr-xr-x 2 root MysqL 4096 Jun 29 21:12 bin
-rw-r--r-- 1 root MysqL 17987 May 21 23:18 COPYING
drwxr-xr-x 3 root MysqL 4096 Jun 29 21:12 data
drwxr-xr-x 2 root MysqL 4096 Jun 29 21:12 docs
drwxr-xr-x 3 root MysqL 4096 Jun 29 21:12 include
-rw-r--r-- 1 root MysqL 7469 May 21 23:18 INSTALL-BINARY
drwxr-xr-x 3 root MysqL 4096 Jun 29 21:12 lib
drwxr-xr-x 4 root MysqL 4096 Jun 29 21:12
man
-rw-r--r-- 1 root root 943 Jun 29 21:18 my.cnf
-rw-r--r-- 1 root root 943 Jun 29 21:23 my-new.cnf
-rw-r--r-- 1 root MysqL 2496 May 21 23:18 README
drwxr-xr-x 2 root MysqL 4096 Jun 29 21:12 scripts
drwxr-xr-x 28 root MysqL 4096 Jun 29 21:12 share
drwxr-xr-x 3 root MysqL 4096 Jun 29 21:12 support-files
[root@web MysqL]
#
[root@web MysqL]
# cat my.cnf
# For advice on how to change settings please see
# http://dev.MysqL.com/doc/refman/5.6/en/server-configuration-defaults.html
[MysqLd]
# Remove leading # and set to the amount of RAM for the most important data
# cache in MysqL. Start at 70% of total RAM for dedicated server,else 10%.
# innodb_buffer_pool_size = 128M
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
# log_bin
# These are commonly set,remove the # and set as required.
# basedir = .....
# datadir = .....
# port = .....
# server_id = .....
# socket = .....
# Remove leading # to set options mainly useful for reporting servers.
# The server defaults are faster for transactions and fast SELECTs.
# Adjust sizes as needed,experiment to find the optimal values.
# join_buffer_size = 128M
# sort_buffer_size = 2M
# read_rnd_buffer_size = 2M
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
[root@web MysqL]
#
|
大家可以看到生成的配置文件很简单,我们得添加一些内容!@H_404_2@
1
2
3
@H_301_65@
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
[root@web MysqL]
# vim my.cnf
binlog-
format
=ROW
log-bin=master-bin.log
log-slave-updates=
true
gtid-mode=on
enforce-gtid-consistency=
true
master-info-repository=TABLE
relay-log-info-repository=TABLE
sync
-master-info=1
slave-parallel-workers=2
binlog-checksum=CRC32
master-verify-checksum=1
slave-sql-verify-checksum=1
binlog-rows-query-log_events=1
server-
id
=1
report-port=3306
port=3306
datadir=
/mydata/data
report-host=master.
test
.com
|
5. 为MysqL提供sysv服务脚本并启动服务@H_404_2@
1
2
3
@H_301_65@
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
@H_301_65@
[root@web MysqL]
# chkconfig MysqLd --list
MysqLd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
Starting MysqL.... SUCCESS!
[root@web MysqL]
# netstat -ntulp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID
/Program
name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 990
/sshd
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1066
/master
tcp 0 0 :::80 :::* LISTEN 37120
/httpd
tcp 0 0 :::22 :::* LISTEN 990
/sshd
tcp 0 0 ::1:25 :::* LISTEN 1066
/master
udp 0 0 0.0.0.0:68 0.0.0.0:* 890
/dhclient
|
6. 输出MysqL的man手册至man命令的查找路径@H_404_2@
1
2
|
[root@web MysqL]
# vim /etc/man.config
|
7. 输出MysqL的头文件至系统头文件路径/usr/include@H_404_2@
1
2
3
|
8. 输出MysqL的库文件给系统库查找路径@H_404_2@
1
2
3
@H_301_65@
4
5
6
7
8
9
10
|
~
[root@web MysqL]
# ldconfig �v# 让系统重新读取库文件
/usr/local/MysqL/lib
:
libtcmalloc_minimal.so.0 -> libtcmalloc_minimal.so (changed)
/usr/lib64/MysqL
:
|
9. 修改PATH环境变量,让系统可以直接使用MysqL的相关命令@H_404_2@
1
2
3
|
[root@web MysqL]
# source /etc/profile #重新读取一下环境变量
|
1
2
3
@H_301_65@
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
Welcome to the MysqL monitor. Commands end with ; or \g.
Server version: 5.6.12-log MysqL Community Server (GPL)
Copyright (c) 2000,2013,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> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| MysqL |
| performance_schema |
|
test
|
+--------------------+
4 rows
in
set
(0.02 sec)
|
说明:
(1). 这里为了支持apache的worker或event这两个MPM,编译时使用了--enable-maintainer-zts选项。
(2). 如果使用PHP5.3以上版本,为了链接MysqL数据库,可以指定MysqLnd,这样在本机就不需要先安装MysqL或MysqL开发包了。 MysqLnd从PHP 5.3开始可用,可以编译时绑定到它(而不用和具体的MysqL客户端库绑定形成依赖),但从PHP 5.4开始它就是默认设置了。
@H_404_2@
1
2
3
@H_301_65@
4
|
# make
# make test
# make intall
|
@H_404_2@
1
|
[root@web PHP-5.4.16]
# yum -y install gd gd-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel
|
(2). 安装libxml(扩展标记语言)库@H_404_2@
1
|
[root@web PHP-5.4.16]
# yum -y install libxml2 libxml2-devel
|
(3). 安装bzip2压缩库@H_404_2@
1
|
[root@web PHP-5.4.16]
# yum install -y bzip2 bzip2-devel
|
(4). 安装mcrypt加密库@H_404_2@
1
2
3
@H_301_65@
4
5
6
7
8
9
|
[root@web src]
# rpm -ivh libmcrypt-2.5.8-4.3.x86_64.rpm
warning: libmcrypt-2.5.8-4.3.x86_64.rpm: Header V3 DSA
/SHA1
Signature,key ID 04b8b50a: NOKEY
Preparing...
########################################### [100%]
1:libmcrypt
########################################### [100%]
[root@web src]
# rpm -ivh libmcrypt-devel-2.5.8-4.3.x86_64.rpm
warning: libmcrypt-devel-2.5.8-4.3.x86_64.rpm: Header V3 DSA
/SHA1
Signature,key ID 04b8b50a: NOKEY
Preparing...
########################################### [100%]
1:libmcrypt-devel
########################################### [100%]
[root@web src]
#
|
1
2
3
@H_301_65@
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
[root@web PHP-5.4.16]
# ./configure --prefix=/usr/local/PHP --with-MysqL=/usr/local/MysqL --with-openssl --with-MysqLi=/usr/local/MysqL/bin/MysqL_config --enable-mbstring --with-gd --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir=/usr --enable-xml --enable-sockets --with-apxs2=/usr/local/apache/bin/apxs --with-mcrypt --with-config-file-path=/etc --with-config-file-scan-dir=/etc/PHP.d --with-bz2 --enable-maintainer-zts
--with-MysqL=
/usr/local/MysqL
:MysqL相关
--with-MysqLi=
/usr/local/MysqL/bin/MysqL_config
:MysqL的另外一个接口,让MysqL与PHP交互的接口;接口程序是MysqL_config,是个二进制程序
--with-gd : 支持gd库
--with-zlib:互联网上常用的,通用格式的压缩库,让数据文件先压缩再传送给客户端
--with-apxs2:基于apxs实现让PHP编译成apace模块
--with-bz2 :压缩库
--
enable
-maintainer-zts :这一项的使用取决于apache是什么类型的,apache使用的是prefork就不需要;如果使用的是event或者是worker就要添加这一项;apache以线程工作就必须编译这一项
Generating files
configure: creating .
/config
.status
creating main
/internal_functions
.c
creating main
/internal_functions_cli
.c
+--------------------------------------------------------------------+
| License: |
| distribution
in
the
file
LICENSE. By continuing this installation |
| process,you are bound by the terms of this license agreement. |
| If you
do
not agree with the terms of this license,you must abort |
| the installation process at this point. |
+--------------------------------------------------------------------+
config.status: creating PHP5.spec
config.status: creating main
/build-defs
.h
config.status: creating scripts
/PHPize
config.status: creating scripts
/PHP-config
config.status: executing default commands
#编译完成
[root@web PHP-5.4.16]
# make && make install
Installing PHP SAPI module: apache2handler
/usr/local/apache/build/instdso
.sh SH_LIBTOOL=
'/usr/local/apr/build-1/libtool'
libPHP5.la
/usr/local/apache/modules
Installing helper programs:
/usr/local/PHP/bin/
program: PHPize
program: PHP-config
page: PHPize.1
page: PHP-config.1
[PEAR] Archive_Tar - installed: 1.3.11
[PEAR] Console_Getopt - installed: 1.3.1
warning: pear
/PEAR
requires package
"pear/Structures_Graph"
(recommended version 1.0.4)
warning: pear
/PEAR
requires package
"pear/XML_Util"
(recommended version 1.2.1)
[PEAR] PEAR - installed: 1.9.4
[PEAR] Structures_Graph- installed: 1.0.4
[PEAR] XML_Util - installed: 1.2.1
[root@web PHP-5.4.16]
#
|
#安装完成@H_404_2@
1
2
3
@H_301_65@
4
5
6
7
8
|
PHP.ini-development
PHP.ini-production
[root@web PHP-5.4.16]
#
PHP.ini-development :用于开发环境
|
(在编译的时候已经指定了配置文件的路径,所以PHP会自动到/etc/目录下去找其配置文件)@H_404_2@
1. 编辑apache配置文件httpd.conf,以apache支持PHP@H_404_2@
(1). 首先要在apache配置文件中定义,使apache能够处理PHP结尾的文件,全文查找AddType字段,添加一下内容@H_404_2@
1
2
3
@H_301_65@
4
|
[root@web PHP-5.4.16]
# vim /etc/httpd/httpd.conf
PHPIniDir
"/usr/local/PHP"
|
(2). 定位至DirectoryIndex index.html修改为:
@H_404_2@
1
|
DirectoryIndex index.PHP index.html
|
@H_404_2@
2. 重启apache并测试@H_404_2@
1
2
3
@H_301_65@
4
|
[root@web PHP-5.4.16]
# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
[root@web PHP-5.4.16]
#
|
1
2
3
@H_301_65@
4
|
<?
PHPinfo();
?>
|
@H_404_2@
5. 问题@H_404_2@
在用PHP5.3以上的PHP版本时,只要是涉及时间的会报一个错!@H_404_2@
1
|
Warning: PHPinfo(): It is not safe to rely on the system
's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning,you most likely misspelled the timezone identifier. We selected the timezone '
UTC'
for
now,but please
set
date
.timezone to
select
your timezone.
in
/usr/local/apache/htdocs/test
.PHP on line 2
|
(1). 在页头使用date_default_timezone_set()设置 date_default_timezone_set('PRC'); //东八时区 echo date('Y-m-d H:i:s');@H_404_2@
1
2
3
@H_301_65@
4
5
|
<?
date_default_timezone_set(
"PRC"
);
PHPinfo();
?>
|
@H_404_2@
(2). 在页头使用 ini_set('date.timezone','Asia/Shanghai');@H_404_2@
(3). 修改PHP.ini。打开PHP.ini查找date.timezone 去掉前面的分号修改成为:date.timezone ="PRC" PRC注意加上双引号,要不还会出错!@H_404_2@
1
2
|
date
.timezone =
"PRC"
|
五、安装Xcache加速器@H_404_2@
1
2
3
@H_301_65@
4
5
6
7
8
|
[root@web src]
# tar -xf xcache-3.0.3.tar.gz
[root@web src]
# cd xcache-3.0.3
Configuring
for
:
PHP Api Version: 20100412
Zend Module Api No: 20100525
Zend Extension Api No: 220100525
[root@web xcache-3.0.3]
#
|
2. 编译安装Xcache 3.0.3@H_404_2@
1
2
3
@H_301_65@
4
5
|
[root@web xcache-3.0.3]
# ./configure --enable-xcache --with-PHP-config=/usr/local/PHP/bin/PHP-config
[root@web xcache-3.0.3]
# make && make install
Installing shared extensions:
/usr/local/PHP/lib/PHP/extensions/no-debug-zts-20100525/
[root@web xcache-3.0.3]
#
|
3. 编辑PHP.ini,整合PHP和xcache@H_404_2@
1
2
3
@H_301_65@
4
5
6
7
8
9
10
11
|
[root@web xcache-3.0.3]
# mkdir /etc/PHP.d
[root@web xcache-3.0.3]
# ls /etc/PHP.d/
xcache.ini
[root@web xcache-3.0.3]
# vim /etc/PHP.d/xcache.ini #
[xcache-common]
;; non-Windows example:
;; Windows example:
; extension = PHP_xcache.dll
|
4. 重启apache并测试@H_404_2@
1
2
3
@H_301_65@
4
|
[root@web xcache-3.0.3]
# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
[root@web xcache-3.0.3]
#
|
说明:测试可以使用windows主机访问linux主机IP,查看PHP.info中是否有xcache模块相关信息 @H_404_2@
六、启用服务器状态@H_404_2@
说明:@H_404_2@
mod_status模块可以让管理员查看服务器的执行状态,它通过一个HTML页面展示了当前服务器的统计数据。这些数据通常包括但不限于:
(1) 处于工作状态的worker进程数;
(2) 空闲状态的worker进程数;
(3) 每个worker的状态,包括此worker已经响应的请求数,及由此worker发送的内容的字节数;
(4) 当前服务器总共发送的字节数;
(5) 服务器自上次启动或重启以来至当前的时长;
(6) 平均每秒钟响应的请求数、平均每秒钟发送的字节数、平均每个请求所请求内容的字节数;@H_404_2@
启用状态页面的方法很简单,只需要在主配置文件中添加如下内容即可:@H_404_2@
1
2
3
@H_301_65@
4
5
|
[root@web xcache-3.0.3]
# vim /etc/httpd/httpd.conf
<Location
/server-status
>
SetHandler server-status
Require all granted
<
/Location
>
|
需要提醒的是,这里的状态信息不应该被所有人随意访问,因此,应该限制仅允许某些特定地址的客户端查看。比如使用Require ip 172.16.0.0/16来限制仅允许指定网段的主机查看此页面 。@H_404_2@
(1). 编辑apache的默认页面/usr/local/apache/htdocs/test.PHP@H_404_2@
1
2
3
@H_301_65@
4
5
6
7
8
|
[root@web xcache-3.0.3]
# vim /usr/local/apache/htdocs/test.PHP
<?
if
($conn)
echo
"Success"
;
else
echo
"Failure"
;
?>
|
(2). 测试@H_404_2@
连接成功!@H_404_2@
八、安装Discuz论坛(Discuz_X3.0_SC_GBK最新版)@H_404_2@
1
2
3
@H_301_65@
4
|
Query OK,0 rows affected (0.03 sec)
MysqL> FLUSH PRIVILEGES;
Query OK,0 rows affected (0.02 sec)
|
(2). 准备Discuz 3.0@H_404_2@
1
2
|
[root@web src]
# unzip Discuz_X3.0_SC_GBK.zip
[root@web src]
# mv upload/* /usr/local/apache/htdocs/
|
(3). 安装@H_404_2@
1
2
|
[root@web htdocs]
# chmod 777 ./data ./config/ ./data/cache/ ./data/avatar/ ./data/plugindata/ ./data/download/ ./data/addonmd5/ ./data/template/ ./ data/threadcache/ ./data/attachment/ ./data/attachment/album/ ./data/attachment/forum/ ./data/attachment/group/ ./data/log/ ./uc_client/data/cache/ ./uc_server/data ./uc_server/data/avatar/ ./uc_server/data/backup/ ./uc_server/data/logs/ ./uc_server/data/tmp/ ./uc_server/data/view/ ./uc_server/data/cache/
[root@web htdocs]
#
|
(5). 选择全新安装 @H_404_2@
(7). 安装完成@H_404_2@
所有演示全部完成 !@H_404_2@