一、配置防火墙,开启80端口、3306端口,关闭SELINUX[root@Zabbix~]#vim/etc/sysconfig/iptables
-AINPUT-ilo-jACCEPT
-AINPUT-mstate--stateNEW-mtcp-ptcp--dport22-jACCEPT
-AINPUT-mstate--stateNEW-mtcp-ptcp--dport80-jACCEPT
-AINPUT-mstate--stateNEW-mtcp-ptcp--dport3306-jACCEPT
-AINPUT-jREJECT--reject-withicmp-host-prohibited
[root@Zabbix~]#vim/etc/selinux/config
#disabled-NoSELinuxpolicyisloaded.
SELINUX=disabled
#SELINUXTYPE=cantakeoneofthesetwovalues:
#targeted-Targetedprocessesareprotected,
#mls-MultiLevelSecurityprotection.
SELINUXTYPE=targeted
[root@Zabbix~]#reboot
二、软件包下载[root@Zabbix~]#cd/usr/local/src/
[root@Zabbixsrc]#ls
cmake-3.0.2.tar.gzMySQL编译工具
libgd-2.1.0.tar.gzgd库安装包
libvpx-v1.3.0.tar.bz2gd库需要
openssl-1.0.1j.tar.gznginx扩展
t1lib-5.1.2.tar.gzphp扩展
zlib-1.2.8.tar.gznginx扩展
freetype-2.5.4.tar.gzgd库需要
libmcrypt-2.5.8.tar.gzphp扩展
mysql-5.6.21.tar.gz
pcre-8.36.tar.gz支持nginx伪静态
tiff-4.0.3.tar.gzgd库需要
jpegsrc.v9a.tar.gzgd库需要
libpng-1.6.7.tar.gzgd库需要
nginx-1.6.2.tar.gz
php-5.6.3.tar.gz
yasm-1.3.0.tar.gzphp扩展
[root@Zabbixsrc]#
三、安装编译工具及库文件yuminstall-yapr*autoconfautomakebisonbzip2bzip2*cloog-pplcompat*
cppcurlcurl-develfontconfigfontconfig-develfreetypefreetype*
freetype-develgccgcc-c++gtk+-develgdgettextgettext-develglibckernel
kernel-headerskeyutilskeyutils-libs-develkrb5-devellibcom_err-devellibpng
libpng*libpng-devellibjpeg*libsepol-devellibselinux-devellibstdc++-devel
libtool*libgomplibxml2libxml2-devellibXpm*libX*libtifflibtiff*makempfr
ncurses*ntpopensslnasmnasm*openssl-develpatchpcre-develperlphp-common
php-gdpolicycoreutilsppltelnett1libt1lib*wgetzlib-devel
四、安装MySQL
1、安装cmake[root@Zabbixsrc]#tarzxvfcmake-3.0.2.tar.gz
[root@Zabbixsrc]#cdcmake-3.0.2
[root@Zabbixcmake-3.0.2]#./configure
[root@Zabbixcmake-3.0.2]#make&&makeinstall
2、安装MySQL[root@Zabbixcmake-3.0.2]#groupaddmysql
[root@Zabbixcmake-3.0.2]#useradd-gmysqlmysql-s/sbin/nologin
[root@Zabbixcmake-3.0.2]#mkdir-p/opt/data/mysql#MySQL数据库存放目录
[root@Zabbixcmake-3.0.2]#chown-Rmysql:mysql/opt/data/mysql/
[root@Zabbixcmake-3.0.2]#mkdir-p/app/mysql#MySQL安装目录
[root@Zabbixcmake-3.0.2]#cd..
[root@Zabbixsrc]#tarzxvfmysql-5.6.21.tar.gz
[root@Zabbixsrc]#cdmysql-5.6.21
[root@Zabbixmysql-5.6.21]#cmake.-DCMAKE_INSTALL_PREFIX=/app/mysql-DMYSQL_DATADIR=/opt/data/mysql-DSYSCONFDIR=/etc
[root@Zabbixmysql-5.6.21]#make&&makeinstall
[root@Zabbixmysql-5.6.21]#rm-rf/etc/f#删除系统默认的配置文件
[root@Zabbixmysql-5.6.21]#cd/app/mysql/#进入MySQL安装目录
[root@Zabbixmysql]#./scripts/mysql_install_db--user=mysql--basedir=/app/mysql--datadir=/opt/data/mysql#生成mysql系统数据库
[root@Zabbixmysql]#ln-s/app/mysql/f/etc/f#添加到/etc目录的软连接
[root@Zabbixmysql]#cp./support-files/mysql.server/etc/rc.d/init.d/mysqld#把Mysql加入系统启动
[root@Zabbixmysql]#chmod755/etc/rc.d/init.d/mysqld
[root@Zabbixmysql]#chkconfigmysqldon
[root@Zabbixmysql]#vim/etc/rc.d/init.d/mysqld
basedir=/app/mysql
datadir=/opt/data/mysql
[root@Zabbixmysql]#servicemysqldstart
StartingMySQL.[OK]
[root@Zabbixmysql]#
[root@Zabbixmysql]#vim/etc/profile
exportPATH=$PATH:/app/mysql/bin#把mysql服务加入系统环境变量:在最后添加下面这一行
[root@Zabbixmysql]#source/etc/profile
#把myslq的库文件链接到系统默认的位置,这样你在编译类似PHP等软件时可以不用指定mysql的库文件地址。
[root@Zabbixmysql]#ln-s/app/mysql/include/mysql/usr/include/mysql
[root@Zabbixmysql]#ln-s/app/mysql/lib/mysql/usr/lib/mysql
[root@Zabbixmysql]#mkdir/var/lib/mysql
[root@Zabbixmysql]#ln-s/tmp/mysql.sock/var/lib/mysql/mysql.sock
[root@Zabbixmysql]#mysql_secure_installation#设置Mysql密码,根据提示回车、输入Y回车输入2次密码,一路回车
[root@Zabbixmysql]#servicemysqldrestart
ShuttingdownMySQL.[OK]
StartingMySQL.[OK]
[root@Zabbixmysql]#
五、安装Nginx
1、安装pcre[root@Zabbixmysql]#cd/usr/local/src/
[root@Zabbixsrc]#mkdir/app/pcre
[root@Zabbixsrc]#tarzxvfpcre-8.36.tar.gz
[root@Zabbixsrc]#cdpcre-8.36
[root@Zabbixpcre-8.36]#./configure--prefix=/app/pcre
[root@Zabbixpcre-8.36]#make&&makeinstall
2、安装openssl[root@Zabbixpcre-8.36]#cd..
[root@Zabbixsrc]#mkdir/app/openssl
[root@Zabbixsrc]#tarzxvfopenssl-1.0.1j.tar.gz
[root@Zabbixsrc]#cdopenssl-1.0.1j
[root@Zabbixopenssl-1.0.1j]#./config--prefix=/app/openssl/
[root@Zabbixopenssl-1.0.1j]#make&&makeinstall
[root@Zabbixopenssl-1.0.1j]#vim/etc/profile
exportPATH=$PATH:/app/openssl/bin
[root@Zabbixopenssl-1.0.1j]#source/etc/profile
3、安装zlib[root@Zabbixopenssl-1.0.1j]#cd/usr/local/src/
[root@Zabbixsrc]#mkdir/app/zlib
[root@Zabbixsrc]#tarzxvfzlib-1.2.8.tar.gz
[root@Zabbixsrc]#cdzlib-1.2.8
[root@Zabbixzlib-1.2.8]#./configure--prefix=/app/zlib/
[root@Zabbixzlib-1.2.8]#make&&makeinstall
4、安装Nginx[root@Zabbixzlib-1.2.8]#cd/usr/local/src/
[root@Zabbixsrc]#groupaddwww
[root@Zabbixsrc]#useradd-gwwwwww-s/sbin/nologin
[root@Zabbixsrc]#tarzxvfnginx-1.6.2.tar.gz
[root@Zabbixsrc]#cdnginx-1.6.2
[root@Zabbixnginx-1.6.2]#./configure--prefix=/app/nginx--without-http_memcached_module--user=www--group=www--with-http_stub_status_module--with-http_ssl_module--with-http_gzip_static_module--with-openssl=/usr/local/src/openssl-1.0.1j--with-zlib=/usr/local/src/zlib-1.2.8--with-pcre=/usr/local/src/pcre-8.36
[root@Zabbixnginx-1.6.2]#make&&makeinstall
注意:--with-openssl=/usr/local/src/openssl-1.0.1j --with-zlib=/usr/local/src/zlib-1.2.8 --with-pcre=/usr/local/src/pcre-8.36指向的是源码包解压的路径,而不是安装的路径,否则会报错[root@Zabbixnginx-1.6.2]#cd/app/nginx/sbin/
[root@Zabbixsbin]#./nginx#启动
[root@Zabbixsbin]#ps-ef|grep-inginx
root234081012:21?00:00:00nginx:masterprocess./nginx
www2340923408012:21?00:00:00nginx:workerprocess
root23411223:22pts/000:00:00grep-inginx
[root@Zabbixsbin]#./nginx-sreload#重启
[root@Zabbixsbin]#./nginx-t-c/app/nginx/conf/nginx.conf#检查配置文件
nginx:theconfigurationfile/app/nginx/conf/nginx.confsyntaxisok
nginx:configurationfile/app/nginx/conf/nginx.conftestissuccessful
[root@Zabbixsbin]#./nginx-v#查版本号
nginxversion:nginx/1.6.2
[root@Zabbixsbin]#./nginx-V#查编译配置
nginxversion:nginx/1.6.2
builtbygcc4.4.70313(RedHat4.4.7-16)(GCC)
TLSSNIsupportenabled
configurearguments:--prefix=/app/nginx--without-http_memcached_module--user=www--group=www--with-http_stub_status_module--with-http_ssl_module--with-http_gzip_static_module--with-openssl=/usr/local/src/openssl-1.0.1j--with-zlib=/usr/local/src/zlib-1.2.8--with-pcre=/usr/local/src/pcre-8.36
[root@Zabbixsbin]#
5、设置nginx开机启动[root@Zabbixsbin]#vim/etc/rc.d/init.d/nginx
#!/bin/sh
#
#nginx-thisscriptstartsandstopsthenginxdaemon
#
#chkconfig:-8515
#description:NginxisanHTTP(S)server,HTTP(S)reverse\
#proxyandIMAP/POP3proxyserver
#processname:nginx
#config:/etc/nginx/nginx.conf
#config:/app/nginx/conf/nginx.conf
#pidfile:/app/nginx/logs/nginx.pid
#Sourcefunctionlibrary.
./etc/rc.d/init.d/functions
#Sourcenetworkingconfiguration.
./etc/sysconfig/network
#Checkthatnetworkingisup.
["$NETWORKING"="no"]&&exit0
nginx="/app/nginx/sbin/nginx"
prog=$(basename$nginx)
NGINX_CONF_FILE="/app/nginx/conf/nginx.conf"
[-f/etc/sysconfig/nginx]&&./etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
make_dirs(){
#makerequireddirectories
user=`$nginx-V2>&1|grep"configurearguments:"|sed's/[^*]*--user=\([^]*\).*/\1/g'-`
if[-z"`grep$user/etc/passwd`"];then
useradd-M-s/bin/nologin$user
fi
options=`$nginx-V2>&1|grep'configurearguments:'`
foroptin$options;do
if[`echo$opt|grep'.*-temp-path'`];then
value=`echo$opt|cut-d"="-f2`
if[!-d"$value"];then
#echo"creating"$value
mkdir-p$value&&chown-R$user$value
fi
fi
done
}
start(){
[-x$nginx]||exit5
[-f$NGINX_CONF_FILE]||exit6
make_dirs
echo-n$"Starting$prog:"
daemon$nginx-c$NGINX_CONF_FILE
retval=$?
echo
[$retval-eq0]&&touch$lockfile
return$retval
}
stop(){
echo-n$"Stopping$prog:"
killproc$prog-QUIT
retval=$?
echo
[$retval-eq0]&&rm-f$lockfile
return$retval
}
restart(){
#configtest||return$?
stop
sleep1
start
}
reload(){
#configtest||return$?
echo-n$"Reloading$prog:"
killproc$nginx-HUP
RETVAL=$?
echo
}
force_reload(){
restart
}
configtest(){
$nginx-t-c$NGINX_CONF_FILE
}
rh_status(){
status$prog
}
rh_status_q(){
rh_status>/dev/null2>&1
}
case"$1"in
start)
rh_status_q&&exit0
$1
;;
stop)
rh_status_q||exit0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q||exit7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q||exit0
;;
*)
echo$"Usage:$0{start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit2
esac
[root@Zabbixsbin]#chmod+x/etc/rc.d/init.d/nginx
[root@Zabbixsbin]#chkconfignginxon
[root@Zabbixsbin]#servicenginxrestart
Stoppingnginx:[OK]
Startingnginx:[OK]
[root@Zabbixsbin]#
六、安装php
1、安装yasm[root@Zabbixsbin]#cd/usr/local/src/
[root@Zabbixsrc]#tarzxvfyasm-1.3.0.tar.gz
[root@Zabbixsrc]#cdyasm-1.3.0
[root@Zabbixyasm-1.3.0]#./configure
[root@Zabbixyasm-1.3.0]#make&&makeinstall
2、安装libmcrypt[root@Zabbixyasm-1.3.0]#cd/usr/local/src/
[root@Zabbixsrc]#tarzxvflibmcrypt-2.5.8.tar.gz
[root@Zabbixsrc]#cdlibmcrypt-2.5.8
[root@Zabbixlibmcrypt-2.5.8]#./configure
[root@Zabbixlibmcrypt-2.5.8]#make&&makeinstall
3、安装libvpx[root@Zabbixlibmcrypt-2.5.8]#cd/usr/local/src/
[root@Zabbixsrc]#tarxvflibvpx-v1.3.0.tar.bz2
[root@Zabbixsrc]#cdlibvpx-v1.3.0
[root@Zabbixlibvpx-v1.3.0]#./configure--prefix=/app/libvpx--enable-shared--enable-vp9
[root@Zabbixlibvpx-v1.3.0]#make&&makeinstall
4、安装tiff[root@Zabbixlibvpx-v1.3.0]#cd/usr/local/src/
[root@Zabbixsrc]#tarzxvftiff-4.0.3.tar.gz
[root@Zabbixsrc]#cdtiff-4.0.3
[root@Zabbixtiff-4.0.3]#./configure--prefix=/app/tiff--enable-shared
[root@Zabbixtiff-4.0.3]#make&&makeinstall
5、安装libpng[root@Zabbixtiff-4.0.3]#cd/usr/local/src/
[root@Zabbixsrc]#tarzxvflibpng-1.6.7.tar.gz
[root@Zabbixsrc]#cdlibpng-1.6.7
[root@Zabbixlibpng-1.6.7]#./configure--prefix=/app/libpng--enable-shared
configure:error:zlibnotinstalled
[root@Zabbixlibpng-1.6.7]#exportLDFLAGS="-L/app/zlib/lib"
[root@Zabbixlibpng-1.6.7]#exportCPPFLAGS="-I/app/zlib/include"
[root@Zabbixlibpng-1.6.7]#make&&makeinstall
6、安装freetype[root@Zabbixlibpng-1.6.7]#cd/usr/local/src/
[root@Zabbixsrc]#tarzxvffreetype-2.5.4.tar.gz
[root@Zabbixsrc]#cdfreetype-2.5.4
[root@Zabbixfreetype-2.5.4]#./configure--prefix=/app/freetype-enable-shared
make:Nothingtobedonefor`unix'.
[root@Zabbixfreetype-2.5.4]#cdbuilds/unix/
[root@Zabbixunix]#./configure--prefix=/app/freetype-enable-shared
[root@Zabbixbuilds]#cd../..
[root@Zabbixfreetype-2.5.4]#make
[root@Zabbixfreetype-2.5.4]#makeinstall
rmdir:failedtoremove`/app/freetype/include/freetype2/freetype/config':Nosuchfileordirectory
make:[install]Error1(ignored)
rm-f/app/freetype/include/freetype2/freetype/*
rmdir/app/freetype/include/freetype2/freetype
rmdir:failedtoremove`/app/freetype/include/freetype2/freetype':Nosuchfileordirectory
make:[install]Error1(ignored)
[root@Zabbixfreetype-2.5.4]#
7、安装jpeg[root@Zabbixfreetype-2.5.4]#cd/usr/local/src/
[root@Zabbixsrc]#tarzxvfjpegsrc.v9a.tar.gz
[root@Zabbixsrc]#cdjpeg-9a/
[root@Zabbixjpeg-9a]#./configure--prefix=/app/jpeg--enable-shared
[root@Zabbixjpeg-9a]#make&&makeinstall
8、安装libgd[root@Zabbixjpeg-9a]#cd/usr/local/src/
[root@Zabbixsrc]#tarzxvflibgd-2.1.0.tar.gz
[root@Zabbixsrc]#cdlibgd-2.1.0
[root@Zabbixlibgd-2.1.0]#./configure--prefix=/app/libgd--enable-shared--with-jpeg=/app/jpeg/--with-png=/app/libpng/--with-freetype=/app/freetype/--with-fontconfig=/app/freetype/--with-xpm=/usr/--with-tiff=/app/tiff/--with-vpx=/app/libvpx/
[root@Zabbixlibgd-2.1.0]#make&&makeinstall
9、安装t1lib[root@Zabbixlibgd-2.1.0]#cd/usr/local/src/
[root@Zabbixsrc]#tarzxvft1lib-5.1.2.tar.gz
[root@Zabbixsrc]#cdt1lib-5.1.2
[root@Zabbixt1lib-5.1.2]#./configure--prefix=/app/t1lib--enable-shared
[root@Zabbixt1lib-5.1.2]#makewithout_doc
[root@Zabbixt1lib-5.1.2]#makeinstall
10、安装php[root@Zabbixt1lib-5.1.2]#cd/usr/local/src/
[root@Zabbixsrc]#cp-frp/usr/lib64/libltdl.so*/usr/lib/
[root@Zabbixsrc]#cp-frp/usr/lib64/libXpm.so*/usr/lib/
[root@Zabbixsrc]#tarzxvfphp-5.6.3.tar.gz
[root@Zabbixphp-5.6.3]#exportLD_LIBRARY_PATH=/app/libgd/lib/
[root@Zabbixphp-5.6.3]#./configure--prefix=/app/php--with-config-file-path=/app/php/etc--with-mysql=/app/mysql/--with-mysqli=/app/mysql/bin/mysql_config--with-mysql-sock=/tmp/mysql.sock--with-pdo-mysql=/app/mysql/--with-gd--with-png-dir=/app/libpng/--with-jpeg-dir=/app/jpeg/--with-freetype-dir=/app/freetype/--with-xpm-dir=/usr/--with-vpx-dir=/app/libvpx/--with-zlib-dir=/app/zlib/--with-t1lib=/app/t1lib/-with-iconv--enable-libxml--enable-xml--enable-bcmath--enable-shmop--enable-sysvsem--enable-inline-optimization--enable-opcache--enable-mbregex--enable-fpm--enable-mbstring--enable-ftp--enable-gd-native-ttf--with-openssl--enable-pcntl--enable-sockets--with-xmlrpc--enable-zip--enable-soap--without-pear--with-gettext-enable-session--with-mcrypt--with-curl--enable-ctype
[root@Zabbixphp-5.6.3]#make&&makeinstall
[root@Zabbixphp-5.6.3]#cpphp.ini-production/app/php/etc/php.ini#复制php配置文件到安装目录
[root@Zabbixphp-5.6.3]#rm-rf/etc/php.ini#删除系统自带配置文件
[root@Zabbixphp-5.6.3]#ln-s/app/php/etc/php.ini/etc/php.ini#添加软链接到/etc目录
[root@Zabbixphp-5.6.3]#cp/app/php/etc/php-fpm.conf.default/app/php/etc/php-fpm.conf#拷贝模板文件为php-fpm配置文件
[root@Zabbixphp-5.6.3]#ln-s/app/php/etc/php-fpm.conf/etc/php-fpm.conf#添加软连接到/etc目录
[root@Zabbixphp-5.6.3]#vim/app/php/etc/php-fpm.conf
user=www
group=www
pid=run/php-fpm.pid
[root@Zabbixphp-5.6.3]#cp/usr/local/src/php-5.6.3/sapi/fpm/init.d.php-fpm/etc/rc.d/init.d/php-fpm#拷贝php-fpm到启动目录
[root@Zabbixphp-5.6.3]#chmod+x/etc/rc.d/init.d/php-fpm
[root@Zabbixphp-5.6.3]#chkconfigphp-fpmon
[root@Zabbixphp-5.6.3]#vim/app/php/etc/php.ini
#disable_functions=passthru,exec,system,chroot,scandir,chgrp,chown,shell_exec,proc_open,proc_get_status,ini_alter,ini_alter,ini_restore,dl,openlog,syslog,readlink,symlink,popepassthru,stream_socket_server,escapeshellcmd,dll,popen,disk_free_space,checkdnsrr,checkdnsrr,getservbyname,getservbyport,disk_total_space,posix_ctermid,posix_get_last_error,posix_getcwd,posix_getegid,posix_geteuid,posix_getgid,posix_getgrgid,posix_getgrnam,posix_getgroups,posix_getlogin,posix_getpgid,posix_getpgrp,posix_getpid,posix_getppid,posix_getpwnam,posix_getpwuid,posix_getrlimit,posix_getsid,posix_getuid,posix_isatty,posix_kill,posix_mkfifo,posix_setegid,posix_seteuid,posix_setgid,posix_setpgid,posix_setsid,posix_setuid,posix_strerror,posix_times,posix_ttyname,posix_uname#列出PHP可以禁用的函数,如果某些程序需要用到这个函数,可以删除,取消禁用。
date.timezone=PRC#设置时区
expose_php=Off#禁止显示php版本的信息
short_open_tag=ON#支持php短标签
opcache.enable=1#php支持opcode缓存
opcache.enable_cli=1#php支持opcode缓存
zend_extension=opcache.so#文末添加此行,开启opcode缓存功能
[root@Zabbixphp-5.6.3]#
11、配置Nginx支持PHP[root@Zabbixphp-5.6.3]#cp/app/nginx/conf/nginx.conf{,bak}
[root@Zabbixphp-5.6.3]#vim/app/nginx/conf/nginx.conf
userwwwwww;#首行user去掉注释,修改Nginx运行组为wwwwww;必须与/usr/local/php/etc/php-fpm.conf中的user,group配置相同,否则php运行出错
location/{
roothtml;
indexindex.htmlindex.htmindex.php;#添加index.php
}
63#passthePHPscriptstoFastCGIserverlisteningon127.0.0.1:9000
64#取消FastCGIserver部分location的注释,
65location~\.php${
66roothtml;
67fastcgi_pass127.0.0.1:9000;
68fastcgi_indexindex.php;
69fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;#fastcgi_param行的参数,改为$document_root$fastcgi_script_name,或者使用绝对路径
70includefastcgi_params;
71}
[root@Zabbixphp-5.6.3]#/etc/init.d/nginxrestart
Stoppingnginx:[OK]
Startingnginx:[OK]
[root@Zabbixphp-5.6.3]#/etc/init.d/php-fpmstart
Startingphp-fpmdone
[root@Zabbixphp-5.6.3]#
七、测试[root@Zabbixphp-5.6.3]#cd/app/nginx/html/
[root@Zabbixhtml]#ls
50x.htmlindex.html
[root@Zabbixhtml]#rm-rf*
[root@Zabbixhtml]#vimindex.php
phpinfo();
?>
[root@Zabbixhtml]#ll-d
drwxr-xr-x2rootroot4096Mar214:33.
[root@Zabbixhtml]#chown-Rwww:www.
[root@Zabbixhtml]#chmod-R700.
[root@Zabbixhtml]#ll-d
drwx------2wwwwww4096Mar214:33.
[root@Zabbixhtml]#
在浏览器中打开服务器IP地址,会看到下面的界面说明安装配置正常
CentOS 6.5编译安装Nginx+MySQL+PHP