Linux_LEMP
目录
LEMP
Nginx是一个高性能的HTTP和反向代理服务器,也是一个 IMAP/POP3/SMTP 服务器,因它的稳定性、丰富的功能集、示例配置文件和低系统资源的消耗而闻名。2011年6月1日,nginx 1.0.4发布。Nginx是一款轻量级的Web 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器,并在一个BSD-like 协议下发行。由俄罗斯的程序设计师Igor Sysoev所开发,供俄国大型的入口网站及搜索引擎Rambler(俄文:Рамблер)使用。其特点是占有内存少,并发能力强,事实上nginx的并发能力确实在同类型的网页服务器中表现较好,中国大陆使用nginx网站用户有:百度、新浪、网易、腾讯等。
Nginx
step1. Install Nginx
yum install -y pcre-devel zlib-devel gcc openssl-devel
useradd -M -s /sbin/nologin nginx
tar zxvf nginx-XXX -C /usr/local/
./configure -prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module --with-http_sub_module --with-md5=/usr/lib --with-sha1=/usr/lib --with-http_gzip_static_module
ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin
nginx -v #check nginx version
step2. Use nginx running script to change nginx service status.
################################## Script 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: /opt/nginx/conf/nginx.conf
# pidfile: /opt/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"
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
}
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
#############################SCRIPT END
cp nginx /etc/init.d
chmod +x /etc/init.d/nginx
step3. Edit nginx configure file
vim /usr/local/nginx/conf/nginx.conf
main #Global config label
server #virtual machine label
#For example:
########################## server section
server {
listen 80;
server_name www.baidu.com; #domainName
charset utf-8;
access_log logs/baidu.access.log main;
location / {
root html; #root: website directory; html:website root directory url:/usr/local/nginx/html
index index.html index.htm index.php; #welcome peger
}
error_page 404 /404.html; #error peger
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
server { --> add access flow monitor function
listen 80;
server_name www.nnice.com;
location ~/status { #'~': the meaning is domain(IP) or nginx service root directory
stub_status on;
access_log off;
}
}
###########################
#events --> module setting
#For example:
########################### events section
events {
worker_connections 1024;
use epoll; #use epoll kernel
}
mysql
step1. Install MySQL
tar zxvf cmake-XXX.tar.gz -C /usr/local
cd cmake
./configure && make && make install
tar zxvf mysql-XXX.tar.gz -C /usr/local
mv /usr/local/mysql-XXX /usr/local/mysql
cd mysql
cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DSYSCONFDIR=/etc -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_FEDERATED_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DMYSQL_TCP_PORT=3306 -DENABLED_LOCAL_INFILE=1 -DWITH_SSL=yes -DEXTRA_CHARSETS=all -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_READLINE=on
step2. initialization mysql
cp mysql/support-files/my-medium.cnf /etc/my.cnf
cp mysql/support-files/mysql.server /etc/init.d/mysqld
chmod +x /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
/usr/local/mysql/scripts/mysql_install_db --user=mysql --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql/ --> DB file store to /usr/local/mysql/data
useradd -M -s /sbin/nologin/ mysql
ln -s /usr/local/mysql/bin/* /usr/local/bin
service mysqld restart
mysql_secure_installation #optimization and set the password for mysql service
echo "//usr/local/mysql/lib" >> /etc/ld.so.conf
ldconfig
PHP
step1. Install PHP plugin
Install libmcrypt,mhash,mcrypt
tar jxvf php-XXX.tar.bz2
mv php-XXX.tar.bz2 php
cd php
./configure --prefix=/usr/local/php --with-gd --with-mcrypt --with-zlib --with-mysql=/usr/local/mysql --with-config-file-path=/usr/local/php/etc --enable-mbstring --enable-fpm && make && make install
step2. Initialization PHP
cp php/php.ini.development /usr/local/php/etc/php.ini
cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
vim php-fpm.conf
pid=run/php-fpm.pid #close php-fpm service by find the pid number
user=nginx
group=nginx
pm.max_spare_servers=35
/usr/local/php/sbin/php-fpm #start php-fpm service
cp php-fpm /etc/init.d #php-fpm script is php-fpm service status script
php-fpm Script
#! /bin/sh
#chkconfig:35 25 12
#description:php-fpm
set -e
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DESC="php-fpm daemon"
NAME=php-fpm
DAEMON=/usr/local/php/sbin/$NAME
PIDFILE=/usr/local/php/logs/$NAME.pid
SCRIPTNAME=/etc/init.d/$NAME
# Gracefully exit if the package has been removed.
d_start() {
/usr/local/php/sbin/php-fpm > /dev/null 2>&1
}
d_stop() {
/bin/kill -SIGINT `cat /usr/local/php/logs/php-fpm.pid` > /dev/null 2>&1
}
d_restart() {
/bin/kill -SIGUSE2 `cat /usr/local/php/logs/php-fpm.pid` > /dev/null 2>&1
}
case "$1" in
start)
echo -n "Starting $DESC: $NAME"
d_start
echo "."
;;
stop)
echo -n "Stopping $DESC: $NAME"
d_stop
echo "."
;;
restart)
echo -n "Restarting $DESC: $NAME"
d_stop
sleep 1
d_start
echo "."
;;
*)
echo "Usage: $SCRIPTNAME {start|stop|restart|reload}" >&2
exit 3
;;
esac
exit 0
##################################SCRIPT END
chown +x /etc/init.d/php-fpm
chkconfig --add php-fpm
chkconfig --list php-fpm
chkconfig php-fpm on
step4. Add php plugin to nginx service
vim /usr/local/nginx/conf/nginx.conf
Enable extra "location ~\.php$" section ,use php proxy
location ~\.php$ {
proxy_pass http://NginxServerIP:80
}
Edit original “localtion \” section to “location ~.php$” , do not use proxy
service {
location ~\.php$ {
root html
include fastcgi.conf
}
Index index.php
}
service nginx restart
service php-fpm restart
service nginx restart
Linux_LEMP的更多相关文章
随机推荐
- DSP、SSP、RTB、ADX(概念通俗解释)
DSP:需求方平台 比如小米想要投放一个新机发布的广告,那么他想在各大网站如网易.新浪UC等地方投放这条新机信息,但他不可能一个一个的去谈,费时费财不说,效率非常低. 于是他就去了一个平台,把打广告的 ...
- vue+hbuilder 打包成移动app
查看了很多网上写的改来改去都在手机上运行不起来,运行起来又是白屏:最后放弃,自己结合文档搞吧! 1. 项目目录下的config文件夹里的index.js文件中,将build对象下的assetsPubl ...
- java 统计字符串中连续重复的字符,并得出新字符串
题目: 比如输入为aaabbc,输出a3b2c1 完整解答: public class Other { static String func(String str) { StringBuffer re ...
- C# wpf 使用资源文件 resx
随意新建一个wpf应用 在cs代码编辑,增加 using System.Resources; 放在最上 在方案新建文件夹 名 文件 在 文件 新建资源文件 资源.resx 资源.resx 添加字符串 ...
- docker快速入门01——docker安装与简单应用
1.docker简介 Docker 是一个开源的应用容器引擎,Docker 可以让开发者打包他们的应用以及依赖包到一个轻量级.可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化 ...
- axios 请求常用组件,及其错误
1. var nodeModules = path.join(processPath, 'node_modules') var querystring = require(nodeModules + ...
- python_实现员工信息表
实现员工信息表 文件存储格式如下:id,name,age,phone,job1,Alex,22,13651054608,IT2,Egon,23,13304320533,Tearcher3,nezha, ...
- [易学易懂系列|rustlang语言|零基础|快速入门|(3)|所有权Ownership]
今天我们来讲讲rust最难,也是最重要的概念: Ownership,Borrowing,Lifetimes 首先我们来看看:ownership(所有权) 我们来看看下面的代码: let a = [1, ...
- u-boot bl _main分析
ldr r0, =(CONFIG_SYS_INIT_SP_ADDR): #define CONFIG_SYS_INIT_SP_ADDR (CONFIG_SYS_INIT_RAM_ADDR ...
- canvas 计算文字宽度(常用于文字换行)
var c=document.getElementById("myCanvas"); var ctx=c.getContext("2d"); ctx.font= ...