LNMP环境搭建(基于zabbix监控软件)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了LNMP环境搭建(基于zabbix监控软件)相关的知识,希望对你有一定的参考价值。
LNMP环境搭建(基于zabbix监控软件)
安装依赖包:
yum -y install pcre pcre-devel openssl openssl-devel
安装nginx
[[email protected] media]# tar zxvf nginx-1.6.0.tar.gz
[[email protected] media]# cd nginx-1.6.0
[[email protected] nginx-1.6.0]# ./configure --prefix=/usr/local/nginx-1.6.0 --with-http_ssl_module --with-http_spdy_module --with-http_stub_status_module --with-pcre
--with-http_stub_status_module:支持nginx状态查询
--with-http_ssl_module:支持https
--with-http_spdy_module:支持google的spdy,想了解请百度spdy,这个必须有ssl的支持
--with-pcre:为了支持rewrite重写功能,必须制定pcre
[[email protected] nginx-1.6.0]# make
[[email protected] nginx-1.6.0]# make install
启动:
[[email protected] nginx-1.6.0]# /usr/local/nginx-1.6.0/sbin/nginx
关闭:
[[email protected] nginx-1.6.0]# /usr/local/nginx-1.6.0/sbin/nginx -s stop
加载配置文件:
[[email protected] nginx-1.6.0]# /usr/local/nginx-1.6.0/sbin/nginx -s reload
开机启动:
[[email protected] ~]# vim /etc/init.d/nginx
#!/bin/bash
# nginx Startup script for the Nginx HTTP Server
# chkconfig: - 85 15
# description: Nginx is a high-performance web and proxy server.
# It has a lot of features, but it‘s not for everyone.
# processname: nginx
# pidfile: /var/run/nginx.pid
# config: /usr/local/nginx/conf/nginx.conf
nginxd=/usr/local/nginx-1.6.0/sbin/nginx
nginx_config=/usr/local/nginx-1.6.0/conf/nginx.conf
nginx_pid=/var/run/nginx.pid
RETVAL=0
prog="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
[ -x $nginxd ] || exit 0
# Start nginx daemons functions.
start() {
if [ -e $nginx_pid ];then
echo "nginx already running...."
exit 1
fi
echo -n $"Starting $prog: "
daemon $nginxd -c ${nginx_config}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch /var/lock/subsys/nginx
return $RETVAL
}
# Stop nginx daemons functions.
stop() {
echo -n $"Stopping $prog: "
killproc $nginxd
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid
}
# reload nginx service functions.
reload() {
echo -n $"Reloading $prog: "
#kill -HUP `cat ${nginx_pid}`
killproc $nginxd -HUP
RETVAL=$?
echo
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
stop
start
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $prog {start|stop|restart|reload|status|help}"
exit 1
esac
exit $RETVAL
[[email protected] ~]# chmod +x /etc/init.d/nginx #执行权限
[[email protected] ~]chkconfig nginx on #设置开机启动
安装依赖包
[[email protected] php-5.5.14]# yum install gcc make gd-devel libjpeg-devel libpng-devel libxml2-devel bzip2-devel libcurl-devel -y
安装php
[[email protected] media]# tar zxvf php-5.5.14.tar.gz
[[email protected] php-5.5.14]# ./configure --prefix=/usr/local/php-5.5.0 --with-config-file-path=/usr/local/php-5.5.0/etc --with-bz2 --with-curl --enable-ftp --enable-sockets --disable-ipv6 --with-gd --with-jpeg-dir=/usr/local --with-png-dir=/usr/local --with-freetype-dir=/usr/local --enable-gd-native-ttf --with-iconv-dir=/usr/local --enable-mbstring --enable-calendar --with-gettext --with-libxml-dir=/usr/local --with-zlib --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-mysql=mysqlnd --enable-dom --enable-xml --enable-fpm --with-libdir=lib64 --enable-bcmath
[[email protected] php-5.5.14]# make && make install
[[email protected] php-5.5.14]# cp php.ini-production /usr/local/php-5.5.0/etc/php.ini #复制php配置文件到安装目录
[[email protected] php-5.5.14]# cp /usr/local/php-5.5.0/etc/php-fpm.conf.default /usr/local/php-5.5.0/etc/php-fpm.conf #拷贝模板文件为php-fpm配置文件
启动:
[[email protected] php-5.5.14]# /usr/local/php-5.5.0/sbin/php-fpm
开机启动:
[[email protected] ~]# vi /etc/init.d/php-fpm
#!/bin/sh
# chkconfig: - 84 16
# Source function library.
. /etc/rc.d/init.d/functions
# Source networking configuration.
. /etc/sysconfig/network
# Check that networking is up.
[ "$NETWORKING" = "no" ] && exit 0
phpfpm="/usr/local/php-5.5.0/sbin/php-fpm"
prog=$(basename ${phpfpm})
lockfile=/var/lock/subsys/phpfpm
start() {
[ -x ${phpfpm} ] || exit 5
echo -n $"Starting $prog: "
daemon ${phpfpm}
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 ${phpfpm} -HUP
RETVAL=$?
echo
}
force_reload() {
restart
}
configtest() {
${phpfpm} -t
}
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
;;
status)
rh_status
;;
*)
echo $"Usage: $0 {start|stop|status|restart|reload|configtest}"
exit 2
esac
[[email protected] ~]# chmod +x /etc/init.d/php-fpm
[[email protected] ~]# chkconfig php-fpm on
测试篇
修改/usr/local/nginx/conf/nginx.conf 配置文件,需做如下修改
cd /usr/local/nginx/html/ #进入nginx默认网站根目录
43 location / {
44 root html;
45 index index.html index.htm ;
46 fastcgi_pass 127.0.0.1:9000;
47 fastcgi_index index.php;
48 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
49 include fastcgi_params;
50
51 }
[[email protected] ~]# rm -rf /usr/local/nginx1.6.0/html/* #删除默认测试页
[[email protected] ~]# vi index.php #新建index.php文件
<?php
phpinfo();
?>
安装mysql
安装依赖包:
[[email protected] media]yum install -y autoconf automake imake libxml2-devel expat-devel cmake gcc gcc-c++ libaio libaio-devel bzr bison libtool ncurses5-devel ncurses-devel
[[email protected] ~]# groupadd mysql #添加mysql组
[[email protected] ~]# useradd -g mysql mysql -s /bin/false #创建用户mysql并加入到mysql组,不允许mysql用户直接登录系统
[[email protected] ~]# mkdir -p /data/mysql #创建MySQL数据库存放目录
[[email protected] ~]# chown -R mysql:mysql /data/mysql #设置MySQL数据库存放目录权限
[[email protected] ~]# mkdir -p /usr/local/mysql #创建MySQL安装目录
[[email protected] media]# tar zxvf mysql-5.6.19.tar.gz
[[email protected] mysql-5.6.19]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/etc
[[email protected] media]# make && make install
[email protected] media]#rm -rf /etc/my.cnf #删除系统默认的配置文件(如果默认没有就不用删除)
[[email protected] ~]# cd /usr/local/mysql #进入MySQL安装目录
./scripts/mysql_install_db --user=mysql --basedir=/usr/local/mysql --datadir=/data/mysql #生成mysql系统数据库
[[email protected] mysql]# cp ./support-files/mysql.server /etc/rc.d/init.d/mysqld #把Mysql加入系统启动
[[email protected] ~]# chmod 755 /etc/init.d/mysqld #增加执行权限
[[email protected] ~]# chkconfig mysqld on #加入开机启动
[[email protected] ~]# vi /etc/rc.d/init.d/mysqld #编辑
46basedir=/usr/local/mysql #MySQL程序安装路径
47datadir=/data/mysql #MySQl数据库存放目录
ps
ln -s /usr/local/mysql/bin/mysql /usr/bin
mysql_secure_installation #设置Mysql密码,根据提示按Y 回车输入2次密码
本文出自 “Dream chaser” 博客,请务必保留此出处http://dreamchaser.blog.51cto.com/7756851/1774420
以上是关于LNMP环境搭建(基于zabbix监控软件)的主要内容,如果未能解决你的问题,请参考以下文章