12.1 LNMP架构介绍
12.2 MySQL安装
12.3 PHP安装(上)
12.4 PHP安装(下)
12.5 Nginx介绍
12.6 Nginx安装
12.1 LNMP架构介绍
LNMP与LAMP差别
12.2 MySQL安装
查看之前是否有安装mysql或者mysql的进程、
[root@localhost ~]# ps aux |grep mysql
[root@localhost ~]# service mysqld stop //关闭之前安装的mysqld
[root@localhost ~]# rm -rf /etc/init.d/mysqld //删除之前安装的目录
[root@localhost ~]# rm -rf /etc/init.d/mysqld //删除之前安装的mysql启动脚本
[root@localhost ~]# rm -rf /data/mysql //删除之前安装的mysql目录
安装mysql
1,我们依然把下载安装包放到
[root@localhost ~]# cd /usr/local/src/
2,这里我们安装mysql-5.6的包
http://mirrors.163.com/mysql/Downloads/MySQL-5.6/mysql-5.6.39-linux-glibc2.12-x86_64.tar.gz //二进制包
[root@localhost src]# yum -y install wget //使用weget 命令
[root@localhost src]# wget http://mirrors.163.com/mysql/Downloads/MySQL-5.6/mysql-5.6.39-linux-glibc2.12-x86_64.tar.gz
3,解压文件 tar zxvf
[root@localhost src]# tar zxvf mysql-5.6.39-linux-glibc2.12-x86_64.tar.gz
4,解压的mysql包,移动到/usr/local/目录下,并重命名为mysql
[root@localhost src]# mv mysql-5.6.39-linux-glibc2.12-x86_64 /usr/local/mysql
5,查看文件[root@hao-01 local]# ls /usr/local/mysql
6,进入mysql文件夹 cd /usr/local/mysql,创建myslq用户useradd mysql
7,根目录下,创建data目录,如果有/data/目录了,可以不在创建
mkdir: 无法创建目录"data": 文件已存在
[root@localhost ~]# mkdir /data/
[root@localhost ~]# mkdir /data/mysql
8,安装依赖包
[root@localhost mysql]# yum install -y perl-Data-Dumper
[root@localhost mysql]# yum install -y libaio
安装mysql
[root@localhost mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
并且用echo $?确认
9,更改vim /etc/my.cnf 配置文件
默认为
改成
datadir=/data/mysql
socket=/tmp/mysql.sock
并且把下面的注释掉
10,拷贝mysql.server配置文件,并改名为mysqld
[root@localhost mysql]# cp support-files/mysql.server /etc/init.d/mysqld
11,编辑启动配置文件如下图
vim /etc/init.d/mysqld
basedir=/usr/local/mysql
datadir=/data/mysql
12,[root@localhost mysql]# 15. 启动mysqld服务
[root@localhost mysql]# /etc/init.d/mysqld start 启动mysqld服务
查询,发现是没有权限的原因
[root@localhost ~]# chown -R mysql:mysql /usr/local/mysql/data/
[root@localhost ~]# chmod -R 755 /usr/local/mysql/data/
[root@localhost mysql]# chown -R mysql:mysql /tmp/mysql/
然后mysql启动成功
13,配置开机启动
[root@localhost ~]# chkconfig --add mysqld
[root@localhost ~]# chkconfig mysqld on
这时候我们就可以用service mysqld stop/restart 等命令了
[root@localhost ~]# service mysqld stop
Shutting down MySQL.. SUCCESS!
[root@localhost ~]#
查看占用端口 3306
netstat –lntp
12.3 PHP安装(上)
安装方法类似,不需要依赖ngix
如果之前设备安装过其他的东西,可以优先make clean
1 ,进入cd /usr/local/src/,并且下载二进制源码包
[root@localhost src]# wget http://cn2.php.net/distributions/php-5.6.32.tar.bz2
2,解压bz2的文件
记得安装bzip2的包
yum install -y bzip2
解压文件tar -jxvf php-5.6.32.tar.bz2
3,进入php-5.6.32目录,并且安装
[root@localhost src]# cd php-5.6.32
[root@localhost php-5.6.32]# ./configure --prefix=/usr/local/php-fpm --with-config-file-path=/usr/local/php-fpm/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-pdo-mysql=/usr/local/mysql --with-mysql-sock=/tmp/mysql.sock --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --with-pear --with-curl --with-openssl
直接安装,安装肯定会报错,少什么就装什么
这里不做详细解说,我们直接安装
yum -y install gcc
也可以用yum list |grep xml2去搜索
继续安装
[root@localhost php-5.6.32]# yum install libxml2-devel.x86_64
少了openssl
yum install openssl openssl-devel
继续
[root@localhost php-5.6.32]# yum install -y bzip2-devel
继续
[root@localhost php-5.6.32]# yum -y install libcurl-devel.x86_64
依然还有问题,继续
[root@localhost php-5.6.32]# yum install -y libpng-devel
继续
yum -y install freetype-devel
居然还有包
yum install -y epel-release
yum -y install libtomcrypt-devel
默认的yum源没有 libmcrypt-devel这个包,只能借助epel的yum源,所以先安装epel,再安装
libmcrypt。
安装成功!
make &&make install
PHP安装成功
4,如果需要启动php-fpm的服务,那么要有配置文件
[root@localhost php-5.6.32]# cp php.ini-production /usr/local/php-fpm/etc/php-ini
这里注意
Development 适合在开发环境中用,production是适合在生产环境中用,区别在错误日志的配置上
5,创建一个php.conf的文件,当然也可以用php-fpm.conf.default去改
[root@localhost php-5.6.32]# vim /usr/local/php-fpm/etc/php-fpm.conf
6,拷贝启动脚本
[root@localhost php-5.6.32]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
加入到服务列表中中去
[root@localhost php-5.6.32]# chmod 755 /etc/init.d/php-fpm //更改一下权限
[root@localhost php-5.6.32]# chkconfig --add php-fpm
[root@localhost php-5.6.32]# chkconfig php-fpm on
7,启动php-fpm
[root@localhost php-5.6.32]# service php-fpm start
发现少了用户php-fpm
[root@localhost php-5.6.32]# useradd php-fpm
文件属性666
12.5 Nginx介绍
越来越多的用户使用nginx,Nginx处理静态文件更好, tomcat(跑java)处理静态文件不太好,也是用nginx配合使用,nginx本身的功能不是很多,但是可以支持很多的模块
12.6 Nginx安装
1,依然下载到,下载文件
[root@localhost nginx-1.8.0]# cd /usr/local/src/
[root@localhost nginx-1.8.0]# wget http://nginx.org/download/nginx-1.8.0.tar.gz
2,解压
tar zxf nginx-1.8.0.tar.gz
3,安装
cd nginx-1.8.0
[root@localhost nginx-1.8.0]# ./configure --prefix=/usr/local/nginx
4,make和make install, 查看目录
5,查看安装情况
[root@localhost nginx-1.8.0]# ls /usr/local/nginx/sbin/nginx
/usr/local/nginx/sbin/nginx
[root@localhost nginx-1.8.0]# /usr/local/nginx/sbin/nginx -t
6,在/etc/init.d/目录下,创建nginx启动脚本,复制下面网址的内容即可
https://coding.net/u/aminglinux/p/aminglinux-book/git/blob/master/D15Z/etc_init.d_nginx
#!/bin/bash
# chkconfig: - 30 21
# description: http service.
# Source Function Library
. /etc/init.d/functions
# Nginx Settings
NGINX_SBIN="/usr/local/nginx/sbin/nginx"
NGINX_CONF="/usr/local/nginx/conf/nginx.conf"
NGINX_PID="/usr/local/nginx/logs/nginx.pid"
RETVAL=0
prog="Nginx"
start()
{
echo -n $"Starting $prog: "
mkdir -p /dev/shm/nginx_temp
daemon $NGINX_SBIN -c $NGINX_CONF
RETVAL=$?
echo
return $RETVAL
}
stop()
{
echo -n $"Stopping $prog: "
killproc -p $NGINX_PID $NGINX_SBIN -TERM
rm -rf /dev/shm/nginx_temp
RETVAL=$?
echo
return $RETVAL
}
reload()
{
echo -n $"Reloading $prog: "
killproc -p $NGINX_PID $NGINX_SBIN -HUP
RETVAL=$?
echo
return $RETVAL
}
restart()
{
stop
start
}
configtest()
{
$NGINX_SBIN -c $NGINX_CONF -t
return 0
}
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
restart
;;
configtest)
configtest
;;
*)
echo $"Usage: $0 {start|stop|reload|restart|configtest}"
RETVAL=1
esac
exit $RETVAL
设置完了更改权限:
[root@localhost nginx-1.8.0]# chmod 755 /etc/init.d/nginx
[root@localhost nginx-1.8.0]# chkconfig --add nginx
[root@localhost nginx-1.8.0]# chkconfig nginx on
7,更改配置文件
[root@localhost nginx-1.8.0]# cd /usr/local/nginx/conf/
nginx.conf 实际是用这个配置文件,我们重新定义个配置文件
https://coding.net/u/aminglinux/p/aminglinux-book/git/blob/master/D15Z/nginx.conf
user nobody nobody; //以哪个用户的身份去读取
worker_processes 2; //进程数
error_log /usr/local/nginx/logs/nginx_error.log crit;
pid /usr/local/nginx/logs/nginx.pid;
worker_rlimit_nofile 51200; //最大能打开多赔少日志
events
{
use epoll;
worker_connections 6000; //最大连接数
}
http
{
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 3526;
server_names_hash_max_size 4096;
log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]'
' $host "$request_uri" $status'
' "$http_referer" "$http_user_agent"';
sendfile on;
tcp_nopush on;
keepalive_timeout 30;
client_header_timeout 3m;
client_body_timeout 3m;
send_timeout 3m;
connection_pool_size 256;
client_header_buffer_size 1k;
large_client_header_buffers 8 4k;
request_pool_size 4k;
output_buffers 4 32k;
postpone_output 1460;
client_max_body_size 10m;
client_body_buffer_size 256k;
client_body_temp_path /usr/local/nginx/client_body_temp;
proxy_temp_path /usr/local/nginx/proxy_temp;
fastcgi_temp_path /usr/local/nginx/fastcgi_temp;
fastcgi_intercept_errors on;
tcp_nodelay on;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 8k;
gzip_comp_level 5;
gzip_http_version 1.1;
gzip_types text/plain application/x-javascript text/css text/htm
application/xml;
server
{
listen 80; //监听端口,server配置
server_name localhost;
index index.html index.htm index.php;
root /usr/local/nginx/html;
location ~ \.php$
{
include fastcgi_params;
fastcgi_pass unix:/tmp/php-fcgi.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
}
}
}
7,检查语法,启动nginx
[root@localhost conf]# /usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
一般主进程是root
[root@localhost conf]# /etc/init.d/nginx start
[root@localhost conf]# ps aux |grep nginx
8,测试一下能否支持php文件
[root@localhost conf]# vim /usr/local/nginx/html/1.php
<?php
echo "this is nginx test";
扩展
Nginx为什么比Apache Httpd高效:原理篇 http://www.toxingwang.com/linux-unix/linux-basic/1712.html
https://coding.net/u/aminglinux/p/nginx/git/blob/master/4z/IO.md?public=true
https://www.zhihu.com/question/64727674
apache和nginx工作原理比较 http://www.server110.com/nginx/201402/6543.html
概念了解:CGI,FastCGI,PHP-CGI与PHP-FPM https://www.awaimai.com/371.html