目录

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的更多相关文章

随机推荐

  1. ThinkPHP验证器验证规则编码要点

    首先验证器要继承框架的think\Validate类. 1.验证规则是一个父类的rule属性,是一个数组. 2.数组的键名是验证字段标识,值是验证规则.多个验证规则要用|分隔,不能有空格,否则可能会验 ...

  2. vue 列表渲染 v-for

    1.数组列表       v-for 块中,我们拥有对父作用域属性的完全访问权限.v-for 还支持一个可选的第二个参数为当前项的索引 1.1 普通渲染       v-for="item ...

  3. 缓存机制总结(JVM内置缓存机制,MyBatis和Hibernate缓存机制,Redis缓存)

    一.JVM内置缓存(值存放在JVM缓存中) 我们可以先了解一下Cookie,Session,和Cache Cookie:当你在浏览网站的时候,WEB 服务器会先送一小小资料放在你的计算机上,Cooki ...

  4. PL/SQL中判断字段为空

    功能写完发现数据库里好多关键字段是空的,可以直接删掉,可直接: DELETE FROM 表名 WHERE 字段 IS NULL OR TRIM(字段) = ''

  5. php产品细节图多图上传示例代码 无刷新

    前台文件代码 upload.html <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " ...

  6. windows 汇编

    int main(){ int a = 1; int c = 2; int b; __asm { MOV EAX, a; MOV EBX, c; ADD EAX, EBX; MOV b, EAX; } ...

  7. TypeError: Cannot read property 'splice' of undefined

    splice是删除数组里的项,报这个错证明你点前面那个并不是个数组,仔细一看,还真是数组名称写错了

  8. python gitlab 学习笔记

    gitlab创建个人访问令牌(personal access token) https://blog.csdn.net/NGU2028070003/article/details/86634474 P ...

  9. Noip2018退役记。

    下面是边考试边写的严肃版退役记\(:D\) Day0 其实我本来想取个这个名字:\(NOIP2018\)提高组复赛试题解析 但是这个博客自己求生欲望太强自己改名了. 先占个坑. noip考前毒奶 \( ...

  10. python绘制国际象棋棋盘核心代码

    import turtle step = 40 for i in range(8): for j in range(8): turtle.penup() turtle.goto(i*step, j*s ...