标签:linux企业常用服务---部署lnmp环境 lnmp
部署前准备;
nginx的安装参考其他博文
本文只针对mysql+php
iptables和selinux不做配置,关掉
系统光盘作为yum源,配置yum文件
从网络获取源码包,ip地址能上网
mysql使用cmake编译安装的,先编译安装cmake
编译安装及配置mysql:
[root@www ~]# wget http://down1.chinaunix.net/distfiles/mysql-5.5.22.tar.gz
[root@www ~]# tar zxvf mysql-5.5.22.tar.gz -C /usr/src/
[root@www ~]# cd /usr/src/mysql-5.5.22/
[root@www mysql-5.5.22]# cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DSYSCONFDIR=/etc/
[root@www mysql-5.5.22]# make &&make install
[root@www mysql-5.5.22]# cp support-files/my-medium.cnf /etc/my.cnf
cp:是否覆盖"/etc/my.cnf"? y
root@www mysql-5.5.22]# cp support-files/mysql.server /etc/init.d/mysqld
[root@www mysql-5.5.22]# chmod +x /etc/init.d/mysqld
[root@www mysql-5.5.22]# chkconfig --add mysqld
[root@www mysql-5.5.22]# echo "PATH=$PATH:/usr/local/mysql/bin" >>/etc/profile
[root@www mysql-5.5.22]# source /etc/profile
[root@www mysql-5.5.22]# groupadd mysql
[root@www mysql-5.5.22]# useradd -M -s /sbin/nologin mysql -g mysql
[root@www mysql-5.5.22]# cd /usr/local/mysql/scripts/
[root@www scripts]# ./mysql_install_db --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --user=mysql
Installing MySQL system tables...
OK
Filling help tables...
OK
[root@www scripts]# cd
[root@www ~]# /etc/init.d/mysqld start
Starting MySQL...[确定]
[root@www ~]# mysqladmin -uroot password 123123
[root@www ~]# mysql -uroot -p123123
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.5.22-log Source distribution
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
Type ‘help;‘ or ‘\h‘ for help. Type ‘\c‘ to clear the current input statement.
mysql> quit;
安装php:
[root@www ~]# yum -y install libxml2-devel gd-devel zlib-devel
[root@www ~]# wget http://cn2.php.net/distributions/php-5.4.36.tar.bz2
[root@www ~]# tar jxvf php-5.4.36.tar.bz2 -C /usr/src/
[root@www ~]# cd /usr/src/php-5.4.36/
[root@www php-5.4.36]# ./configure --prefix=/usr/local/php5 --with-gd --with-zlib --with-mysql=/usr/local/mysql --with-config-file-path=/usr/local/php5 --enable-mbstring --enable-fpm --with-jpeg-dir=/usr/lib
[root@www php-5.4.36]# make &&make install
[root@www php-5.4.36]# ls /usr/local/php5/
bin etc include lib php sbin var
[root@www php-5.4.36]# cp php.ini-development /usr/local/php5/php.ini
[root@www ~]# ln -s /usr/local/php5/bin/* /usr/local/bin/
[root@www ~]# ln -s /usr/local/php5/sbin/* /usr/local/sbin/
安装ZendGuardLoader:
[root@www ~]# tar zxvf ZendGuardLoader-70429-PHP-5.4-linux-glibc23-x86_64.tar.gz
ZendGuardLoader-70429-PHP-5.4-linux-glibc23-x86_64/
ZendGuardLoader-70429-PHP-5.4-linux-glibc23-x86_64/php-5.4.x/
ZendGuardLoader-70429-PHP-5.4-linux-glibc23-x86_64/php-5.4.x/ZendGuardLoader.so
ZendGuardLoader-70429-PHP-5.4-linux-glibc23-x86_64/README.txt
[root@www ~]# cp ZendGuardLoader-70429-PHP-5.4-linux-glibc23-x86_64/php-5.4.x/ZendGuardLoader.so /usr/local/php5/
[root@www ~]#
编辑php.ini(/usr/local/php/etc )文件,在最后位置添加以下内容:
[root@www ~]# vi /usr/local/php5/php.ini
[Zend Guard]
zend_extension=/usr/local/php5/ZendGuardLoader.so
; Enables loading encoded scripts. The default value is On
zend_loader.enable=1
; Optional: following lines can be added your php.ini file for ZendGuardLoader configuration
zend_loader.disable_licensing=0
zend_loader.obfuscation_level_support=3
:wq
配置nginx支持php:
[root@www ~]# cd /usr/local/php5/etc/
[root@www etc]# vi php-fpm.conf ##新建配置文件
[global]
pid = run/php-fpm.pid
[www]
listen = 127.0.0.1:9000
user = nginx
group = nginx
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
[root@www ~]# /usr/local/sbin/php-fpm ##启动php-fpm
[root@www ~]# netstat -utpln |grep php
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 5587/php-fpm
编写启动LNMP脚本:
[root@www ~]# vi /etc/init.d/lnmp
#!/bin/bash
# chkconfig: 35 95 30
# description: This script is for LNMP Management!
NGF=/usr/local/nginx/sbin/nginx
NGP=/usr/local/nginx/logs/nginx.pid
FPMF=/usr/local/php5/sbin/php-fpm
FPMP=/usr/local/php5/var/run/php-fpm.pid
case $1 in
start)
$NGF &&echo "nginx is starting! "
$FPMF && echo "php-fpm is starting! "
;;
stop)
kill -QUIT $(cat $NGP) &&echo "nginx is stoped! "
kill -QUIT $(cat $FPMP) &&echo "php-fpm is stoped! "
;;
restart)
$0 stop
$0 start
;;
reload)
kill -HUP $(cat $NGP)
kill -HUP $(cat $FPMP)
;;
status)
netstat -utpln |grep nginx &>/dev/null
if [ $? -eq 0 ]
then
echo "nginx is running! "
else
echo "nginx is not running! "
fi
netstat -upltn |grep php-fpm &>/dev/null
if [ $? -eq 0 ]
then
echo "php-fpm is runing! "
else
echo "php-fpm is not running! "
fi
;;
*)
echo "Usage $0 {start|stop|status|restart}"
exit 1
;;
esac
:wq
[root@www ~]# chmod +x /etc/init.d/lnmp
[root@www ~]# chkconfig --add lnmp
[root@www ~]# /etc/init.d/lnmp status
nginx is running!
php-fpm is runing!
本文出自 “LP-linux” 博客,请务必保留此出处http://linuxlp.blog.51cto.com/11463376/1773559
标签:linux企业常用服务---部署lnmp环境 lnmp
原文地址:http://linuxlp.blog.51cto.com/11463376/1773559