目录

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. C语言_扫雷代码

    本文详细讲述了基于C语言实现的扫雷游戏代码,代码中备有比较详细的注释,便于读者阅读和理解.希望对学习游戏开发的朋友能有一点借鉴价值. 完整的实例代码如下: ? 1 2 3 4 5 6 7 8 9 10 ...

  2. Codeforces 899 1-N两非空集合最小差 末尾最多9对数计算 pair/链表加优先队列最少次数清空

    A /*Huyyt*/ #include<bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a)) #define pb push_bac ...

  3. associate.py 源代码 及 使用方法

    ORB_SLAM2运行RGBD数据集需要使用图片序列信息 使用以下代码进行汇集: #!/usr/bin/python # Software License Agreement (BSD License ...

  4. 超级大佬已提前布局AI域名,人工智能时代真的来临了?

    近日,郭盛华公司巨资收购的ai域名引起了业界深度关注,ai人工智能行业想必大家都熟悉不会陌生,但是ai域名你知道吗?了解域名行业的米友,对于ai域名肯定都熟悉,为什么今天小编要突然提到ai域名?因为a ...

  5. ZROI 19.08.03 DP入门

    \(n\)个点,要求连一棵树,设点\(i\)的度数为\(d_i\),则其贡献为\(f(d_i)\mod 59393\),其中\(f(x)\)是一个\(k\)次多项式.最大化总贡献.\(n\leq 30 ...

  6. numpy模块、matplotlib模块、pandas模块

    目录 1. numpy模块 2. matplotlib模块 3. pandas模块 1. numpy模块 numpy模块的作用 用来做数据分析,对numpy数组(既有行又有列)--矩阵进行科学计算 实 ...

  7. python接口自动化一(发送get请求)

    一.环境安装 1.用pip安装requests模块 >>pip install requests 二.get请求 1.导入requests后,用get方法就能直接访问url地址,如:htt ...

  8. mysql——二级索引(辅助索引)

    二级索引:叶子节点中存储主键值,每次查找数据时,根据索引找到叶子节点中的主键值,根据主键值再到聚簇索引中得到完整的一行记录. 问题: 1.相比于叶子节点中存储行指针,二级索引存储主键值会占用更多的空间 ...

  9. Python pickle模块学习(超级详细)

    from  http://blog.csdn.net/sxingming/article/details/52164249

  10. 【leetcode】Submission Details

    Given two sentences words1, words2 (each represented as an array of strings), and a list of similar ...