配置yum源
cd /etc/yum.repos.d/
yum clean all
yum list
yum update
关闭firewalld(这里使用iptables)
systemctl stop firewalld.service
systemctl disable firewalld.service
yum -y install iptables-services
vi /etc/sysconfig/iptables
# sample configuration for iptables service
# you can edit this manually or use system-config-firewall
# please do not ask us to add additional ports/services to this default configuration
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 3306 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
systemctl restart iptables.service
systemctl enable iptables.service
关闭selinux
vi /etc/selinux/config
修改主机名
hostnamectl set-hostname zabbix
reboot
创建数据目录
mkdir -p /usr/local/src
yum -y install wget
下载软件包到指定目录
cd /usr/local/src
wget http://nginx.org/download/nginx-1.8.0.tar.gz
wget http://mirrors.sohu.com/mysql/MySQL-5.6/mysql-5.6.35.tar.gz
wget http://cn2.php.net/distributions/php-5.5.14.tar.gz
pcre-8.39(支持Nginx伪静态)
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.39.tar.gz
openssl-1.0.1h(Nginx扩展)
wget http://www.openssl.org/source/openssl-1.0.1h.tar.gz
cmake(MySQL编译工具)
wget http://www.cmake.org/files/v2.8/cmake-2.8.11.2.tar.gz
zlib-1.2.11(Nginx扩展)
wget http://zlib.net/zlib-1.2.11.tar.gz
libmcrypt-2.5.8(php扩展)
wget http://nchc.dl.sourceforge.net/project/mcrypt/Libmcrypt/2.5.8/libmcrypt-2.5.8.tar.gz
yasm-1.2.0(php扩展)
wget http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gz
t1lib-5.1.2(php扩展)
wget http://pkgs.fedoraproject.org/repo/pkgs/t1lib/t1lib-5.1.2.tar.gz/md5/a5629b56b93134377718009df1435f3c/t1lib-5.1.2.tar.gz
libgd-2.1.0(gd库安装包)
wget https://bitbucket.org/libgd/gd-libgd/downloads/libgd-2.1.0.tar.gz
libvpx-v1.3.0(gd库需要)
wget http://storage.googleapis.com/downloads.webmproject.org/releases/webm/libvpx-v1.3.0.tar.bz2
tiff-4.0.3(gd库需要)
wget http://download.osgeo.org/libtiff/tiff-4.0.3.tar.gz
libpng-1.6.29(gd库需要)
wget ftp://ftp.simplesystems.org/pub/png/src/libpng16/libpng-1.6.29.tar.gz
freetype(gd库需要)
wget https://sourceforge.net/projects/freetype/files/freetype2/2.5.3/freetype-2.5.3.tar.gz/download
jpegsrc(gd库需要)
wget http://www.ijg.org/files/jpegsrc.v9a.tar.gz
安装编译工具和库文件
yum install -y apr* autoconf automake bison bzip2 bzip2* \
cloog-ppl compat* cpp curl curl-devel fontconfig \
fontconfig-devel freetype freetype* freetype-devel \
gcc gcc-c++ gtk+-devel gd gettext gettext-devel \
glibc kernel kernel-headers keyutils keyutils-libs-devel \
krb5-devel libcom_err-devel libpng libpng-devel libjpeg* \
libsepol-devel libselinux-devel libstdc++-devel libtool* \
libgomp libxml2 libxml2-devel libXpm* libtiff libtiff* make \
mpfr ncurses* ntp openssl openssl-devel patch pcre-devel \
perl php-common php-gd policycoreutils telnet t1lib t1lib* \
nasm nasm* wget zlib-devel
一、安装MySQL
安装Cmake
[root@zabbix src]# tar zxvf cmake-2.8.11.2.tar.gz
[root@zabbix src]# cd cmake-2.8.11.2
[root@zabbix cmake-2.8.11.2]# ./configure
[root@zabbix cmake-2.8.11.2]# make
[root@zabbix cmake-2.8.11.2]# make install
安装MySQL
[root@zabbix cmake-2.8.11.2]# groupadd mysql
[root@zabbix cmake-2.8.11.2]# useradd -g mysql mysql -s /bin/false
[root@zabbix cmake-2.8.11.2]# mkdir -p /data/mysql
[root@zabbix cmake-2.8.11.2]# chown -R mysql:mysql /data/mysql
[root@zabbix cmake-2.8.11.2]# mkdir -p /usr/local/mysql
[root@zabbix cmake-2.8.11.2]# cd /usr/local/src
[root@zabbix src]# tar zxvf mysql-5.6.35.tar.gz
[root@zabbix src]# cd mysql-5.6.35
[root@zabbix mysql-5.6.35]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/etc
[root@zabbix mysql-5.6.35]# make
[root@zabbix mysql-5.6.35]# make install
[root@zabbix ~]# rm -f /etc/my.cnf(有则删、没有则不删)
[root@zabbix mysql-5.6.35]# cd /usr/local/mysql/
生成MySQL系统数据库(初始化)
[root@zabbix mysql]# ./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql
为mysql配置文件创建软链接
[root@zabbix mysql]# ln -s /usr/local/mysql/my.cnf /etc/my.cnf
把mysql加入系统启动
[root@zabbix mysql]# cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld
[root@zabbix mysql]# chmod 755 /etc/init.d/mysqld
[root@zabbix mysql]# chkconfig mysqld on
[root@zabbix mysql]# vim /etc/rc.d/init.d/mysqld
basedir=/usr/local/mysql
datadir=/data/mysql
[root@zabbix mysql]# service mysqld start
Starting MySQL.Logging to '/data/mysql/zabbix.err'.
SUCCESS!
将mysql服务加入环境变量
[root@zabbix mysql]# vim /etc/profile
export PATH=$PATH:/usr/local/mysql/bin
[root@zabbix mysql]# source /etc/profile
将mysql的库文件连接到系统默认的位置,这样编译类似PHP等软件时可以不用指定mysql的库文件地址
[root@zabbix mysql]# ln -s /usr/local/mysql/lib/mysql /usr/lib/mysql
[root@zabbix mysql]# ln -s /usr/local/mysql/include/mysql /usr/include/mysql
[root@zabbix mysql]# mkdir /var/lib/mysql
[root@zabbix mysql]# ln -s /tmp/mysql.sock /var/lib/mysql/mysql.sock
设置mysql密码
[root@zabbix mysql]# mysql_secure_installation
Enter current password for root (enter for none): 输入现在的ROOT密码(为空直接按回车)
Set root password? [Y/n] Y 是否设定root密码(是)
New password:
Re-enter new password:
Password updated successfully!
Remove anonymous users? [Y/n] Y 是否删除所有匿名用户(是)
Disallow root login remotely? [Y/n] Y 是否禁止root用户远程登录(是)
Remove test database and access to it? [Y/n] Y 是否删除测试数据库test(是)
Reload privilege tables now? [Y/n] Y 刷新权限
二、安装Nginx
安装pcre
[root@zabbix mysql]# cd /usr/local/src
[root@zabbix src]# mkdir /usr/local/pcre
[root@zabbix src]# tar zxvf pcre-8.39.tar.gz
[root@zabbix src]# cd pcre-8.39
[root@zabbix pcre-8.39]# ./configure --prefix=/usr/local/pcre
[root@zabbix pcre-8.39]# make
[root@zabbix pcre-8.39]# make install
安装openssl
[root@zabbix pcre-8.39]# cd /usr/local/src
[root@zabbix src]# mkdir /usr/local/openssl
[root@zabbix src]# tar zxvf openssl-1.0.1h.tar.gz
[root@zabbix src]# cd openssl-1.0.1h
[root@zabbix openssl-1.0.1h]# ./config --prefix=/usr/local/openssl/
[root@zabbix openssl-1.0.1h]# make
[root@zabbix openssl-1.0.1h]# make install
[root@zabbix openssl-1.0.1h]# cd /usr/local/src/
[root@zabbix src]# mkdir /usr/local/openssl
[root@zabbix src]# vim /etc/profile
export PATH=$PATH:/usr/local/openssl/bin
[root@zabbix src]# source /etc/profile
安装zlib
[root@zabbix src]# cd /usr/local/src
[root@zabbix src]# mkdir /usr/local/zlib
[root@zabbix src]# tar zxvf zlib-1.2.11.tar.gz
[root@zabbix src]# cd zlib-1.2.11
[root@zabbix zlib-1.2.11]# ./configure --prefix=/usr/local/zlib
[root@zabbix zlib-1.2.11]# make
[root@zabbix zlib-1.2.11]# make install
安装Nginx
[root@zabbix zlib-1.2.11]# groupadd www
[root@zabbix zlib-1.2.11]# useradd -g www www -s /bin/false
[root@zabbix zlib-1.2.11]# cd /usr/local/src
[root@zabbix src]# tar zxvf nginx-1.8.0.tar.gz
[root@zabbix src]# cd nginx-1.8.0
[root@zabbix nginx-1.8.0]# ./configure --prefix=/usr/local/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.1h --with-zlib=/usr/local/src/zlib-1.2.11 \
--with-pcre=/usr/local/src/pcre-8.39
[root@zabbix nginx-1.8.0]# make
[root@zabbix nginx-1.8.0]# make install
开启Nginx
[root@zabbix nginx-1.8.0]# /usr/local/nginx/sbin/nginx
[root@zabbix nginx-1.8.0]# vim /etc/rc.d/init.d/nginx
############################################################
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemon
#
# chkconfig: - 85 15
# description: Nginx is an HTTP(S) server, HTTP(S) reverse \
# proxy and IMAP/POP3 proxy server
# processname: nginx
# config: /etc/nginx/nginx.conf
# config: /usr/local/nginx/conf/nginx.conf
# pidfile: /usr/local/nginx/logs/nginx.pid
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="/usr/local/nginx/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf"
[ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx
lockfile=/var/lock/subsys/nginx
############################################################
#!/bin/sh
# chkconfig: - 85 15
# description: nginx is a World Wide Web server. It is used to serve
#NGINX_HOME=`dirname $(cd "$(dirname "$0")"; pwd)`
NGINX_HOME='/usr/local/nginx'
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
nginx="$NGINX_HOME/sbin/nginx"
prog=$(basename $nginx)
NGINX_CONF_FILE="$NGINX_HOME/conf/nginx.conf"
lockfile=/var/lock/subsys/nginx
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
echo -n $"Starting $prog: "
daemon $nginx -c $NGINX_CONF_FILE
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}
stop() {
echo -n $"Stopping $prog: "
killproc $prog -QUIT
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
return $retval
}
restart() {
configtest || return $?
stop
start
}
reload() {
configtest || return $?
echo -n $"Reloading $prog: "
killproc $nginx -HUP
RETVAL=$?
echo :wq
}
force_reload() {
restart
}
configtest() {
$nginx -t -c $NGINX_CONF_FILE
}
rh_status() {
status $prog
}
rh_status_q() {
rh_status >/dev/null 2>&1
}
case "$1" in
start)
rh_status_q && exit 0
$1
;;
stop)
rh_status_q || exit 0
$1
;;
restart|configtest)
$1
;;
reload)
rh_status_q || exit 7
$1
;;
force-reload)
force_reload
;;
status)
rh_status
;;
condrestart|try-restart)
rh_status_q || exit 0
;;
*)
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}"
exit 2
esac
############################################################
[root@zabbix nginx-1.8.0]# chmod 775 /etc/rc.d/init.d/nginx
[root@zabbix nginx-1.8.0]# chkconfig nginx on
三、安装PHP
安装yasm
[root@zabbix nginx-1.8.0]# cd /usr/local/src
[root@zabbix src]# tar zxvf yasm-1.2.0.tar.gz
[root@zabbix src]# cd yasm-1.2.0
[root@zabbix yasm-1.2.0]# ./configure
[root@zabbix yasm-1.2.0]# make && make install
安装libmcrypt
[root@zabbix yasm-1.2.0]# cd /usr/local/src/
[root@zabbix src]# tar zxvf libmcrypt-2.5.8.tar.gz
[root@zabbix src]# cd libmcrypt-2.5.8
[root@zabbix libmcrypt-2.5.8]# ./configure
[root@zabbix libmcrypt-2.5.8]# make && make install
安装libvpx
[root@zabbix libmcrypt-2.5.8]# cd /usr/local/src/
[root@zabbix src]# tar xvf libvpx-v1.3.0.tar.bz2
[root@zabbix src]# cd libvpx-v1.3.0
[root@zabbix libvpx-v1.3.0]# ./configure --prefix=/usr/local/libvpx --enable-shared --enable-vp9
[root@zabbix libvpx-v1.3.0]# make && make install
安装tiff
[root@zabbix libvpx-v1.3.0]# cd /usr/local/src/
[root@zabbix src]# tar zxvf tiff-4.0.3.tar.gz
[root@zabbix src]# cd tiff-4.0.3
[root@zabbix tiff-4.0.3]# ./configure --prefix=/usr/local/tiff --enable-shared
[root@zabbix tiff-4.0.3]# make && make install
安装libpng
[root@zabbix tiff-4.0.3]# cd /usr/local/src/
[root@zabbix src]# tar zxvf libpng-1.6.29.tar.gz
[root@zabbix src]# cd libpng-1.6.29
[root@zabbix libpng-1.6.29]# ./configure --prefix=/usr/local/libpng --enable-shared
[root@zabbix libpng-1.6.29]# make && make install
安装freetype
[root@zabbix libpng-1.6.29]# cd /usr/local/src/
[root@zabbix src]# tar zxvf freetype-2.5.3.tar.gz
[root@zabbix src]# cd freetype-2.5.3
[root@zabbix freetype-2.5.3]# ./configure --prefix=/usr/local/freetype --enable-shared
[root@zabbix freetype-2.5.3]# make && make install
安装jpeg
[root@zabbix freetype-2.5.3]# cd /usr/local/src/
[root@zabbix src]# tar zxvf jpegsrc.v9a.tar.gz
[root@zabbix src]# cd jpeg-9a/
[root@zabbix jpeg-9a]# ./configure --prefix=/usr/local/jpeg --enable-shared
[root@zabbix jpeg-9a]# make && make install
安装libgd
[root@zabbix jpeg-9a]# cd /usr/local/src
[root@zabbix src]# tar zxvf libgd-2.1.0.tar.gz
[root@zabbix src]# cd libgd-2.1.0
[root@zabbix libgd-2.1.0]# ./configure --prefix=/usr/local/libgd --enable-shared \
--with-jpeg=/usr/local/jpeg --with-png=/usr/local/libpng --with-freetype=/usr/local/freetype \
--with-fontconfig=/usr/local/freetype --with-xpm=/usr/ --with-tiff=/usr/local/tiff \
--with-vpx=/usr/local/libvpx
[root@zabbix libgd-2.1.0]# make
[root@zabbix libgd-2.1.0]# make install
安装t1lib
[root@zabbix libgd-2.1.0]# cd /usr/local/src/
[root@zabbix src]# tar zxvf t1lib-5.1.2.tar.gz
[root@zabbix src]# cd t1lib-5.1.2
[root@zabbix t1lib-5.1.2]# ./configure --prefix=/usr/local/t1lib --enable-shared
[root@zabbix t1lib-5.1.2]# make without_doc
[root@zabbix t1lib-5.1.2]# make install
安装PHP
64位系统执行以下命令
[root@zabbix t1lib-5.1.2]# ln -s /usr/lib64/libltdl.so /usr/lib/libltdl.so
[root@zabbix t1lib-5.1.2]# \cp -frp /usr/lib64/libXpm.so /usr/lib
安装
[root@zabbix t1lib-5.1.2]# cd /usr/local/src
[root@zabbix src]# tar -zxvf php-5.5.14.tar.gz
[root@zabbix src]# cd php-5.5.14
[root@zabbix php-5.5.14]# export LD_LIBRARY_PATH=/usr/local/libgd/lib
[root@zabbix php-5.5.14]# ./configure --prefix=/usr/local/php \
--with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql \
--with-mysqli=/usr/local/mysql/bin/mysql_config --with-mysql-sock=/tmp/mysql.sock \
--with-pdo-mysql=/usr/local/mysql --with-gd --with-png-dir=/usr/local/libpng \
--with-jpeg-dir=/usr/local/jpeg --with-freetype-dir=/usr/local/freetype \
--with-xpm-dir=/usr/ --with-vpx-dir=/usr/local/libvpx/ --with-zlib-dir=/usr/local/zlib \
--with-t1lib=/usr/local/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@zabbix php-5.5.14]# make
[root@zabbix php-5.5.14]# make install
[root@zabbix php-5.5.14]# cp php.ini-production /usr/local/php/etc/php.ini
[root@zabbix php-5.5.14]# rm -rf /etc/php.ini
[root@zabbix php-5.5.14]# ln -s /usr/local/php/etc/php.ini /etc/php.ini
[root@zabbix php-5.5.14]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
[root@zabbix php-5.5.14]# ln -s /usr/local/php/etc/php-fpm.conf /etc/php-fpm.conf
[root@zabbix php-5.5.14]# vim /usr/local/php/etc/php-fpm.conf
user = www #设置php-fpm运行账号为www
group = www #设置php-fpm运行组为www
pid = run/php-fpm.pid #取消前面的分号
[root@zabbix php-5.5.14]# cp /usr/local/src/php-5.5.14/sapi/fpm/init.d.php-fpm /etc/rc.d/init.d/php-fpm
[root@zabbix php-5.5.14]# chmod +x /etc/rc.d/init.d/php-fpm
[root@zabbix php-5.5.14]# chkconfig php-fpm on
[root@zabbix php-5.5.14]# vim /usr/local/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
date.timezone = PRC
short_open_tag = On
opcache.enable=1
opcache.enable_cli=0
最后一行添加zend_extension=opcache.so
配置nginx支持php
vim /usr/local/nginx/conf/nginx.conf
user www www; #首行user去掉注释,修改Nginx运行组为www www;必须与/usr/local/php/etc/php-fpm.conf中的user,group配置相同,否则php运行出错
index index.html index.htm index.php; #添加index.php
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
#取消FastCGI server部分location的注释,注意fastcgi_param行的参数,改为$document_root$fastcgi_script_name,或者使用绝对路径
[root@zabbix php-5.5.14]# /etc/init.d/nginx restart
Restarting nginx (via systemctl): [ OK ]
[root@zabbix php-5.5.14]# service php-fpm start
Starting php-fpm done
[root@zabbix php-5.5.14]# cd /usr/local/nginx/html
[root@zabbix html]# vim index.php
<?php
phpinfo();
?>
[root@zabbix html]# chown www.www /usr/local/nginx/html -R
[root@zabbix html]# chmod 700 /usr/local/nginx/html -R
访问主机IP,出现php测试页面为正确
#######测试MySQL数据库连接
vim /usr/local/nginx/html/test.php
<?php
$link=mysql_connect('localhost','root','DATA__PASSWORD');
if($link)
echo "恭喜你,数据库连接成功!";
mysql_close();
?>
访问http://IP/test.php
如果是乱码的话修改NGINX配置文件支持中文
vim /usr/local/nginx/conf/nginx.conf
charset utf-8;
再次访问测试。