LNMP架构 安装MySQL 、php、nginx

LNMP框架 -mysql安装

一、yum源安装相关工具

  1. #cd /usr/local/src

//软件包都放在这里方便管理

  1. [root@localhost src]#yum install -y lrzsz

//确定安装yum

二、上传并解压Mysql

  1. [root@localhost ~]# tar -zxvf mysql-5.6.47-linux-glibc2.12-x86_64.tar.gz
  2. [root@localhost ~]#mv mysql-5.6.47-linux-glibc2.12-x86_64.tar.gz /usr/local/src/

//把mysql放到根目录下面

  1. [root@localhost ~]# mv nginx-1.17.8.tar.gz /usr/local/src
    //把nginx放到根目录下面
  2.  [root@localhost ~]#mv php-5.6.30.tar.gz /usr/local/src
    //把php放到根目录下面

三、安装与配置

  1. [root@localhost ~]#cd /usr/local/src
  2. //进入根目录下面
    [root@localhost src]# mkdir -p /data/mysql

//创建datadir,数据库文件会放到这里面 

  1.  [root@localhost src]# useradd -s /sbin/nologin mysql
  2.  [root@localhost src]# chown -R mysql:mysql /data/mysql       // 更改权限,不更改后续操作就会出问题
  3.  [root@localhost src]# mv mysql-5.6.47-linux-glibc2.12-x86_64 /usr/local/mysql

// 挪动位置

  1. [root@localhost src]# yum install -y autoconf
  2. //安装依赖工具
    [root@localhost mysql]#  ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql

//--user表示定义数据库的以哪个用户的身份运

//--datadir表示定义数据库的安装目录

  1. [root@localhost mysql]# cp support-files/my-default.cnf /etc/my.cnf
    cp: overwrite ‘/etc/my.cnf’? y

  2. [root@localhost mysql]#cp  support-files/mysql.server  /etc/init.d/mysql

//复制启动脚本文件

9. [root@localhost mysql]#chmod  755  /etc/init.d/mysql

//修改启动脚本文件的属性

10.[root@localhost mysql]#vim /etc/init.d/mysql

//修改启动脚本

dasedir=/usr/local/mysql

datadir=/data/mysql

11.[root@localhost ~]# vim /etc/my.cnf

log_bin=crlinux1

# These are commonly set, remove the # and set as required.
basedir = /usr/local/mysql/
datadir = /data/mysql/
port = 3306
server_id = 21
socket = /tmp/mysql.sock

  1. [root@localhost mysql]#chkconfig --add mysql

//把mysql服务加到系统服务列表中

  1.  [root@localhost mysql]#chkconfig mysql on

//开机启动

13.[root@localhost mysql]# service mysql start

//启动MySQL

LNMP框架 -PHP安装

一、   下载与解压

  1. #cd /usr/local/src  

//软件包都放在这里方便管理

  1. #tar -zxvf php-5.6.30.tar.gz//解压

二、   安装与配置

安装依赖插件

  1. # yum install -y libxml2-devel
  2. # yum install -y openssl openssl-devel
  3. # yum install -y bzip2 bzip2-devel
  4. # yum install -y libpng libpng-devel
  5. # yum install -y freetype freetype-devel
  6. # yum install -y epel-release
  7. # yum install -y libmcrypt-devel
  8. #yum -y install libjpeg-devel
  9. #yum install -y libcurl-devel
  10. #yum install -y gcc//有可能会报错 安装gcc
  11. #useradd -s /sbin/nologin php-fpm

配置安装

  1. [root@localhost ~]# cd /usr/local/src/php-5.6.30
  2. [root@localhost php-5.6.30]# ./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-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 --disable-ipv6 --with-pear --with-curl --with-openssl
  3. #make j4 && make install (安装时间会很久,4通道稍快一点)

编辑配置文件

  1. [root@localhost php-5.6.30]# cp php.ini-production /usr/local/php-fpm/etc/php.ini
  2. [root@server php-5.6.39]# vim /usr/local/php-fpm/etc/php-fpm.conf
  3. [global]
  4. pid = /usr/local/php-fpm/var/run/php-fpm.pid
  5. error_log = /usr/local/php-fpm/var/log/php-fpm.log
  6. [www]
  7. listen = /tmp/php-fcgi.sock
  8. listen.mode = 666
  9. user = php-fpm
  10. group = php-fpm
  11. pm = dynamic
  12. pm.max_children = 50
  13. pm.start_servers = 20
  14. pm.min_spare_servers = 5
  15. pm.max_spare_servers = 35
  16. pm.max_requests = 500
  17. rlimit_files = 1024
  18. [root@localhost etc]# /usr/local/php-fpm/sbin/php-fpm -t
  19. [06-Sep-2021 17:43:00] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful(代表成功)
  20. [root@localhost etc]# cd /usr/local/src/php-5.6.30
  21. [root@localhost php-5.6.30]# cp /usr/local/src/php-5.6.30/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
  22. [root@localhost php-5.6.30]#  chmod 755 /etc/init.d/php-fpm

启动php

  1. [root@localhost php-5.6.30]# service php-fpm start
  2. Starting php-fpm  done
  3. [root@localhost php-5.6.30]# chkconfig php-fpm on

测试是否安装成功

  1. [root@localhost php-5.6.30]# ps aux |grep php-fpm
  2. root     111527  0.0  0.1 128200  5052 ?        Ss   18:13   0:00 php-fpm: master process (/usr/local/php-fpm/etc/php-fpm.conf)
  3. php-fpm  111528  0.0  0.1 128200  4788 ?        S    18:13   0:00 php-fpm: pool www
  4. php-fpm  111529  0.0  0.1 128200  4788 ?        S    18:13   0:00 php-fpm: pool www
  5. php-fpm  111530  0.0  0.1 128200  4788 ?        S    18:13   0:00 php-fpm: pool www
  6. php-fpm  111531  0.0  0.1 128200  4788 ?        S    18:13   0:00 php-fpm: pool www
  7. php-fpm  111532  0.0  0.1 128200  4796 ?        S    18:13   0:00 php-fpm: pool www
  8. php-fpm  111533  0.0  0.1 128200  4796 ?        S    18:13   0:00 php-fpm: pool www
  9. php-fpm  111534  0.0  0.1 128200  4796 ?        S    18:13   0:00 php-fpm: pool www
  10. php-fpm  111535  0.0  0.1 128200  4796 ?        S    18:13   0:00 php-fpm: pool www
  11. php-fpm  111536  0.0  0.1 128200  4796 ?        S    18:13   0:00 php-fpm: pool www
  12. php-fpm  111537  0.0  0.1 128200  4796 ?        S    18:13   0:00 php-fpm: pool www
  13. php-fpm  111538  0.0  0.1 128200  4796 ?        S    18:13   0:00 php-fpm: pool www
  14. php-fpm  111539  0.0  0.1 128200  4796 ?        S    18:13   0:00 php-fpm: pool www
  15. php-fpm  111540  0.0  0.1 128200  4796 ?        S    18:13   0:00 php-fpm: pool www
  16. php-fpm  111541  0.0  0.1 128200  4796 ?        S    18:13   0:00 php-fpm: pool www
  17. php-fpm  111542  0.0  0.1 128200  4796 ?        S    18:13   0:00 php-fpm: pool www
  18. php-fpm  111543  0.0  0.1 128200  4796 ?        S    18:13   0:00 php-fpm: pool www
  19. php-fpm  111544  0.0  0.1 128200  4796 ?        S    18:13   0:00 php-fpm: pool www
  20. php-fpm  111545  0.0  0.1 128200  4796 ?        S    18:13   0:00 php-fpm: pool www
  21. php-fpm  111546  0.0  0.1 128200  4796 ?        S    18:13   0:00 php-fpm: pool www
  22. php-fpm  111547  0.0  0.1 128200  4796 ?        S    18:13   0:00 php-fpm: pool www
  23. root     111570  0.0  0.0 112812   976 pts/0    S+   18:17   0:00 grep --color=auto php-fpm

LNMP框架 -Nginx安装

上传并解压Nginx

  1. [root@localhost src]# tar -zxvf nginx-1.17.8.tar.gz
  2. [root@localhost src]# cd nginx-1.17.8

安装配置

配置

  1. [root@localhost nginx-1.17.8]# ./configure --prefix=/usr/local/nginx

编译

  1. [root@localhost nginx-1.17.8]# make -j4 && make install

修改配置文件

[root@localhost nginx-1.17.8]# vi /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

添加权限增加开机项

  1. [root@localhost nginx-1.17.8]# chmod 755 /etc/init.d/nginx
  2. [root@localhost nginx-1.17.8]# chkconfig  --add nginx
  3. [root@localhost nginx-1.17.8]# chkconfig nginx on
  4. [root@localhost nginx-1.17.8]# > /usr/local/nginx/conf/nginx.conf

修改配置文件

1.        [root@server nginx-1.17.8]#  > /usr/local/nginx/conf/nginx.conf
2.        [root@server nginx-1.17.8]# vim /usr/local/nginx/conf/nginx.conf    //修改配置文件
3.        user nobody nobody;
4.        worker_processes 2;
5.        error_log /usr/local/nginx/logs/nginx_error.log crit;
6.        pid /usr/local/nginx/logs/nginx.pid;
7.        worker_rlimit_nofile 51200;
8.        events
9.        {
10.     use epoll;
11.     worker_connections 6000;
12.     }
13.     http
14.     {
15.     include mime.types;
16.     default_type application/octet-stream;
17.     server_names_hash_bucket_size 3526;
18.     server_names_hash_max_size 4096;
19.     log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]'
20.     ' $host "$request_uri" $status'
21.     ' "$http_referer" "$http_user_agent"';
22.     sendfile on;
23.     tcp_nopush on;
24.     keepalive_timeout 30;
25.     client_header_timeout 3m;
26.     client_body_timeout 3m;
27.     send_timeout 3m;
28.     connection_pool_size 256;
29.     client_header_buffer_size 1k;
30.     large_client_header_buffers 8 4k;
31.     request_pool_size 4k;
32.     output_buffers 4 32k;
33.     postpone_output 1460;
34.     client_max_body_size 10m;
35.     client_body_buffer_size 256k;
36.     client_body_temp_path /usr/local/nginx/client_body_temp;
37.     proxy_temp_path /usr/local/nginx/proxy_temp;
38.     fastcgi_temp_path /usr/local/nginx/fastcgi_temp;
39.     fastcgi_intercept_errors on;
40.     tcp_nodelay on;
41.     gzip on;
42.     gzip_min_length 1k;
43.     gzip_buffers 4 8k;
44.     gzip_comp_level 5;
45.     gzip_http_version 1.1;
46.     gzip_types text/plain application/x-javascript text/css text/htm
47.     application/xml;
48.     server
49.     {
50.     listen 80;
51.     server_name localhost;
52.     index index.html index.htm index.php;
53.     root /usr/local/nginx/html;
54.     location ~ \.php$
55.     {
56.     include fastcgi_params;
57.     fastcgi_pass unix:/tmp/php-fcgi.sock;
58.     fastcgi_index index.php;
59.     fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
60.     }
61.     }
62.     }

检测是否成功

  1. [root@localhost nginx-1.17.8]# /usr/local/nginx/sbin/nginx -t
  2. nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
  3. nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

启动 Nginx

  1. [root@localhost nginx-1.17.8]# service nginx start
  2. Starting nginx (via systemctl):                            [  OK  ]
  3. [root@localhost nginx-1.17.8]# ps aux |grep nginx

测试是否正确解析

[root@localhost nginx-1.17.8]#vi /usr/local/nginx/html/2.php

<?php

echo "test php scripts";

?>

[root@localhost nginx-1.17.8]#curl localhost/2.php

test php scripts      //证明解析成功

 

posted @ 2021-09-06 17:30  发进  阅读(75)  评论(0)    收藏  举报