Linuxnginxphpmysqlmemcache服务器安装配置与优化.docx
《Linuxnginxphpmysqlmemcache服务器安装配置与优化.docx》由会员分享,可在线阅读,更多相关《Linuxnginxphpmysqlmemcache服务器安装配置与优化.docx(25页珍藏版)》请在冰豆网上搜索。
Linuxnginxphpmysqlmemcache服务器安装配置与优化
Linuxwapgame服务器安装与配置
(author:
yubingxing)
一、准备安装
1、下载软件:
以上是需要下载并安装的软件,最新版本请自行从Google搜索下载。
2、解压缩有压缩包
使用tarzxvf和tarjxvf来解压缩。
二、安装步骤
1、检查网络配置:
更改/etc/sysconfig/network-script/ifcfg-eth0文件来实现更改网卡工作参数。
其中eth0代表要更改的是系统的第一块网卡,如果更改的是系统的其他网卡请自行选择要更改的文件。
例如:
#BroadcomCorporationNetXtremeIIBCM5709GigabitEthernet
DEVICE=eth0
BOOTPROTO=none
HWADDR=00:
24:
E8:
60:
47:
67
ONBOOT=yes
NETMASK=修改完毕保存后使用
#ifconfigeth0down或者ifdowneth0,停止eth0接口
#ifconfigeth0up或者ifupeth0,开启eth0接口
来重新更新网络配置。
更改主机名需要修改以下两个文件,分别是/etc/sysconfig/network和/etc/hosts,使用vi/etc/sysconfig/network打开network文件,将HOSTNAME一项的值改为你想要更改为的主机名,保存退出后使用vi/etc/hosts打开hosts文件,在文件末尾添加<你的Linux主机IP>你想要更改为的主机名,注意IP地址和主机名之间必须用空格隔开,并且在原文件中localhost一行的一行前面添加你想要修改为的主机名。
注意:
你想要修改为的主机名和之间必须有至少一个空格。
完成编辑后保存退出。
注意这两个文件中的三处的主机名必须一致。
2、检查防火墙配置:
设置防火墙
vim/etc/sysconfig/iptables
重启防火墙
/etc/iptablesrestart
查看防火墙
/etc/iptablesstatus
配置例如:
#Firewallconfigurationwrittenbysystem-config-securitylevel
#Manualcustomizationofthisfileisnotrecommended.
*filter
:
INPUTACCEPT[0:
0]
:
FORWARDACCEPT[0:
0]
:
OUTPUTACCEPT[0:
0]
:
RH-Firewall-1-INPUT-[0:
0]
-AINPUT-jRH-Firewall-1-INPUT
-AFORWARD-jRH-Firewall-1-INPUT
-ARH-Firewall-1-INPUT-ilo-jACCEPT
-ARH-Firewall-1-INPUT-picmp--icmp-typeany-jACCEPT
-ARH-Firewall-1-INPUT-p50-jACCEPT
-ARH-Firewall-1-INPUT-p51-jACCEPT
-ARH-Firewall-1-INPUT-pudp--dport5353-d-jACCEPT
-ARH-Firewall-1-INPUT-pudp-mudp--dport631-jACCEPT
-ARH-Firewall-1-INPUT-ptcp-mtcp--dport631-jACCEPT
-ARH-Firewall-1-INPUT-mstate--stateESTABLISHED,RELATED-jACCEPT
-ARH-Firewall-1-INPUT-mstate--stateNEW-mtcp-ptcp--dport80-jACCEPT
-ARH-Firewall-1-INPUT-mstate--stateNEW-mtcp-ptcp--dport21-jACCEPT
-ARH-Firewall-1-INPUT-mstate--stateNEW-mtcp-ptcp--dport22-jACCEPT
-ARH-Firewall-1-INPUT-mstate--stateNEW-mtcp-ptcp--dport23-jACCEPT
-ARH-Firewall-1-INPUT-mstate--stateNEW-mtcp-ptcp--dport3389-jACCEPT
-ARH-Firewall-1-INPUT-jREJECT--reject-withicmp-host-prohibited
COMMIT
3、设置时间:
tzselect
选择Asia/Shanghai
cp/usr/share/zoneinfo/Asia/Shanghai/etc/localtime
vim/etc/sysconfig/clock修改ZONE="Asia/Shanghai"UTC=falseARC=false
ntpdate--systohc
4、设置默认字符集:
修改/etc/sysconfig/i18n:
LANG=""
SUPPORTED="en_US:
en:
"
SYSFONT="latarcyrheb-sun16"
修改/etc/:
加入exportLANG=uc_EN
5、安装MySQL:
建立用户:
groupaddmysql
useradd–gmysqlmysql
安装:
cdmysql-5.4.3-beta
./configure--prefix=/usr/local/mysql–with-extra-charsets=utf8–with-plugins=all
make
makeinstall
配置:
cpsupport-files//etc/
scripts/mysql_install_db
cpsupport-files//etc/mysqld
chmod750/etc/mysqld
chmod–R750/usr/local/mysql
chgrp–Rmysql/usr/local/mysql/var
cp/usr/local/mysql/libexec/mysqld/usr/local/mysql/libexec/
启动服务:
/etc/mysqldstart
设置root密码:
mysqladmin–urootpassword“root147258369”
cp/usr/local/mysql/include/mysql//usr/local/mysql/
设置开机自启动:
vim/etc/
在最后面加上
/etc/mysqldstart
6、安装libevent:
cdlibevent-1.4.12-stable
./configure–prefix=/usr/&&make&&makeinstall
7、安装memcached:
cdmemcached-1.4.2
./configure–prefix=/usr/local/memcached–with-libevent=/usr/&&make&&makeinstall
启动服务:
/usr/local/memcached/bin/memcached–l–d–p10000–uroot–m256
设置开机启动,在/etc/中加入上面这行
编写/etc/脚本:
vim/etc/memcached
内容如下:
#!
/bin/bash
MEMCACHED=/usr/local/memcached/bin/memcache
RETVAL=0
caseAVG"$1"in
AVGstart)
echo"Startingmemcached..."
$MEMCACHED–l–d–p10000–uroot–m256
RETVAL=$?
;;
AVGstop)
echo"Stoppingmemcached..."
killall-QUITmemcached
RETVAL=$?
;;
AVGrestart)
echo"Restartingmemcached..."
killall-HUPmemcached
RETVAL=$?
;;
AVG)
$MEMCACHED
RETVAL=$?
;;
*)
echo"Usage:
memcache{start|stop|restart}"
exit1
;;
esac
保存退出
chmod700/etc/memcache
8、安装zlib
cdzlib-1.2.3
./configure&&make&&makeinstall
9、安装jpeg6
建立目录:
mkdir-p/usr/local/jpeg6
mkdir-p/usr/local/jpeg6/bin
mkdir-p/usr/local/jpeg6/lib
mkdir-p/usr/local/jpeg6/include
mkdir-p/usr/local/jpeg6/man
mkdir-p/usr/local/jpeg6/man1
mkdir-p/usr/local/jpeg6/man/man1
cdjpeg-7/
./configure--prefix=/usr/local/jpeg6/--enable-shared--enable-static
make&&makeinstall
10、安装libpng
cdlibpng-1.2.41beta04
cpscripts/makefile
make&&makeinstall
11、安装freetype
cdfreetype-2.1.10
./configure–prefix=/usr/local/freetype&&make&&makeinstall
12、安装gettext
cd
./configure–prefix=/usr
cp/usr/lib/libattr.*/lib/
make
makeinstall
13、安装gd2
cdgd-2.0.36RC1
./configure–prefix=/usr/local/gd–with-jpeg=/usr/local/jpeg6/--with-png–with-zlib–with-freetype=/usr/local/freetype
make&&makeinstall
14、安装libiconv
cdlibiconv-1.13.1
./configure–prefix=/usr/local/iconv&&make&&makeinstall
15、安装libmcrypt
cdlibmcrypt-2.5.7
./configure&&make&&makeinstall
/sbin/ldconfig
cdlibltdl/
./configure–enable-ltdl-install
make
makeinstall
16、ln-s/usr/local/lib//usr/lib/
17、ln-s/usr/local/lib//usr/lib/
18、ln-s/usr/local/lib//usr/lib/
19、ln-s/usr/local/lib/.4.4.8/usr/lib/
20、ln-s/usr/local/lib//usr/lib/
21、ln-s/usr/local/lib//usr/lib/
22、ln-s/usr/local/lib//usr/lib/
23、ln-s/usr/local/lib//usr/lib/
24、ln-s/usr/local/lib//usr/lib/安装mhash
cdmhash
./configure&&make&&makeinstall
25、安装mcrypt
cdmcrypt-2.6.8
/sbin/ldconfig
./configure&&make&&makeinstall
26、安装libexpat
cdexpat-2.0.1
./configure--prefix=/usr/local/expat
make&&makeinstall
27、安装libxml2
cdlibxml2-2.7.6
./configure--prefix=/usr/local/libxml2&&make&&makeinstall
28、安装libxslt(不必安装该扩展库)
cdlibxslt-1.1.26
./configure--prefix=/usr/local/libxslt–with-libxml-prefix=/usr/local/libxml2
make&&makeinstall
29、安装php
添加php-fpm补丁,使支持php-fastcgi和fpm创建cgi进程。
对于php需要下载:
5.2.11-cd5.2.11|patch-d-p1
对于php需要下载:
5.3.0–cd5.3.0|patch–d–p1
i.安装php5.3.0
tarjxvf5.2.11-cd5.2.11|patch-d-p1
cdphp-5.2.11
./configure--prefix=/usr/local/php--with-mysql=/usr/local/mysql--with-gd=/usr/local/gd--with-jpeg-dir=/usr/local/jpeg6--with-png-dir=/usr/local/--with-zlib--with-freetype-dir=/usr/local/freetype--with-libxml-dir=/usr/local/libxml2--enable-shared--enable-magic-quotes--with-iconv--without-sqlite--with-mcrypt--with-iconv=/usr/local/iconv--without-pdo-sqlite--with-gettext=/usr--with-curl--with-curlwrappers--enable-mbregex--enable-fastcgi--enable-fpm--enable-force-cgi-redirect--enable-mbstring--with-mhash--enable-pcntl--enable-sockets--with-config-file-path=/usr/local/php/etc--enable-dom--with-xsl=/usr/local/libxslt--disable-simplexml--enable-roxen-zts
如果编译碰到错误:
errorwhileloadingsharedlibraries:
/usr/local/gd/lib/cannotrestoresegmentprotafterreloc:
Permissiondenied
这个错误是因为打开了RedHat的SELinux,但是关闭会导致其他访问权限问题。
所以可以修改
/etc/selinux/config文件中的SELINUX=""为disabled,然后重启。
chcon-ttextrel_shlib_t/usr/local/gd/lib/*
编译安装:
makeZEND_EXTRA_LIBS='-liconv'
makeinstall
maketest
cp/usr/local/php/etc/
~
30、编译安装PHP5扩展模块2.2.5
cdmemcache-2.2.5/
/usr/local/php/bin/phpize
./configure--with-php-config=/usr/local/php/bin/php-config
make
makeinstall
编译安装PHP5扩展模块0.9.50.9.5
/usr/local/php/bin/phpize
./configure--enable-eaccelerator=shared--with-php-config=/usr/local/php/bin/php-config
make
makeinstall
31、编译安装PHP5扩展模块1.0.2
cdPDO_MYSQL-1.0.2/
/usr/local/php/bin/phpize
./configure--with-php-config=/usr/local/php/bin/php-config--with-pdo-mysql=/usr/local/mysql
make
makeinstall
三、优化配置
1、配置eAccelerator加速PHP
mkdir–p/usr/local/eaccelerator_cache
修改
vim/usr/local/php/etc/
手工修改:
查找/usr/local/php/etc/中的extension_dir="./"修改为extension_dir="/usr/local/php/lib/php/extensions/no-debug-non-zts-/"并在此行后增加以下几行,然后保存:
extension=""
extension=""
再查找output_buffering=Off
修改为output_buffering=On
按]]键跳到配置文件的最末尾,加上以下配置信息:
[eaccelerator]
zend_extension="/usr/local/php/lib/php/extensions/no-debug-non-zts-/"
="128"
="/usr/local/eaccelerator_cache"
="1"
="1"
="1"
="0"
=""
="0"
="300"
="120"
="0"
="1"
="9"
修改配置文件
vi/etc/
输入以下内容
=95
然后执行以下命令使配置生效
/sbin/sysctl–p
创建www用户和组,虚拟主机使用的目录:
/usr/sbin/groupaddwww
/usr/sbin/useradd-gwwwwww
mkdir-p/var/www
chmod750/var/www
chown-Rwww:
www/var/www
创建php-fpm配置文件(php-fpm是为PHP打的一个FastCGI管理补丁,可以平滑变更配置而无需重启php-cgi):
在/usr/local/php/etc/目录中创建文件:
rm-f/usr/local/php/etc/
vi/usr/local/php/etc/
输入以下内容(如果您安装Nginx+PHP用于程序调试,请将以下的0改为1,以便显示PHP错误信息,否则,Nginx会报状态为500的空白错误页):
xmlversion=""?
>
Allrelativepathsinthisconfigarerelativetophp'sinstallprefix
Pidfile
/usr/local/php/logs/
Errorlogfile
/usr/local/php/logs/
Loglevel
notice
WhenthisamountofphpprocessesexitedwithSIGSEGVorSIGBUS...
10
...inalessthanthisintervaloftime,agracefulrestartwillbeinitiated.
Usefultoworkaroundaccidentalcurruptionsinaccelerator'ssharedmemory.
1m
Timelimitonwaitingchild'sreactiononsignalsfrommaster
5s
Setto'no'todebugfpm
yes
Nameofpool.Usedinlogsandstats.
default
Addresstoacceptfastcgirequestson.
Validsyntaxis''orjust'port'or'/path/to/unix/socket'
Setlisten
(2)backlog
-1