LNMP部署

你的名字 2022-11-25 00:39 360阅读 0赞

LNMP部署

    • 1.准备环境
    • 2.安装nginx
    • 3.安装mysql
    • 4.安装php
    • 5.ngnix虚拟主机配置

   














主机 IP
zyy180 192.168.30.150/24

1.准备环境

  1. #准备工作#
  2. 安装yum
  3. [root@zyy180 ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
  4. [root@zyy180 ~]# sed -i 's/\$releasever/7/g' /etc/yum.repos.d/CentOS-Base.repo
  5. sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
  6. [root@zyy180 ~]#yum -y install wget
  7. [root@zyy180 ~]#wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
  8. 安装所需软件
  9. yum -y install vim gd-devel pcre-devel openssl openssl-devel gcc gcc-c++ bzip2
  10. 安装所需工具包
  11. [root@zyy ~]# yum groups mark install 'Development Tools'

   

2.安装nginx

  1. 1.创建nginx用户
  2. [root@zyy180 ~]#useradd -r -M -s /sbin/nologin nginx
  3. 2.创建日志文件并更改属主
  4. [root@zyy180 ~]# cd /usr/src/
  5. [root@zyy180 ~]# mkdir -p /var/log/nginx
  6. [root@zyy180 src]# chown -R nginx.nginx /var/log/nginx
  7. 3.解压
  8. [root@zyy180 src]# tar xf nginx-1.18.0.tar.gz -C /usr/local/
  9. 4.编译安装
  10. [root@zyy180 ~]# cd /usr/local/nginx-1.18.0/
  11. [root@zyy180 nginx-1.18.0]# ./configure \
  12. --prefix=/usr/local/nginx \
  13. --user=nginx \
  14. --group=nginx \
  15. --with-debug \
  16. --with-http_ssl_module \
  17. --with-http_realip_module \
  18. --with-http_image_filter_module \
  19. --with-http_gunzip_module \
  20. --with-http_gzip_static_module \
  21. --with-http_stub_status_module \
  22. --http-log-path=/var/log/nginx/access.log \
  23. --error-log-path=/var/log/nginx/error.log
  24. [root@zyy180 nginx-1.18.0]# make && make install
  25. 5.做环境变量
  26. [root@zyy180 ~]# echo 'export PATH=/usr/local/nginx/sbin:$PATH' > /etc/profile.d/nginx.sh
  27. [root@zyy180 local]# . /etc/profile.d/nginx.sh
  28. 6.启动服务
  29. [root@zyy180 ~]# nginx

   

3.安装mysql

  1. 安装mysql
  2. 安装依赖包
  3. [root@zyy180 ~]# yum -y install ncurses-devel openssl-devel openssl cmake mariadb-devel
  4. 1.创建用户
  5. [root@zyy180 ~]# useradd -r -M -s /sbin/no -u 306 mysql
  6. 2.解压
  7. 将二进制数据库拖进来
  8. [root@zyy180 ~]# tar xf mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz -C /usr/local/
  9. 3.做链接和改属主
  10. [root@zyy180 ~]# cd /usr/local/
  11. [root@zyy180 local]# ln -s mysql-5.7.30-linux-glibc2.12-x86_64/ mysql
  12. [root@zyy180 local]# chown -R mysql.mysql mysql*
  13. 4.做环境变量
  14. [root@zyy180 local]# echo 'export PATH=/usr/local/mysql/bin:$PATH' > /etc/profile.d/mysql.sh
  15. [root@zyy180 local]# source /etc/profile.d/mysql.sh
  16. [root@zyy180 local]# cd /usr/local/mysql
  17. [root@zyy180 mysql]# ln -s include /usr/include/mysql
  18. [root@zyy180 mysql]# vim /etc/man_db.conf
  19. MANDATORY_MANPATH /usr/local/mysql/man
  20. [root@zyy180 mysql]# vim /etc/ld.so.conf.d/mysql.conf
  21. /usr/local/mysql/lib
  22. [root@zyy180 mysql]# ldconfig
  23. 5.创建存放目录
  24. [root@zyy180 mysql]# mkdir /opt/data
  25. [root@zyy180 mysql]# chown -R mysql.mysql /opt/data/
  26. 6.初始化
  27. [root@zyy180 mysql]# mysqld --initialize-insecure --user=mysql --datadir=/opt/data
  28. 7.编译并安装
  29. [root@zyy180 mysql]# cat > /etc/my.cnf <<EOF
  30. [mysqld]
  31. basedir = /usr/local/mysql
  32. datadir = /opt/data
  33. socket = /tmp/mysql.sock
  34. port = 3306
  35. pid-file = /opt/data/mysql.pid
  36. user = mysql
  37. skip-name-resolve
  38. EOF
  39. 8.配置服务启动脚本
  40. [root@zyy180 mysql]# cd /usr/local/mysql/support-files
  41. [root@zyy180 support-files]# cp mysql.server /etc/init.d/mysqld
  42. [root@zyy180 support-files]# vim /etc/init.d/mysqld
  43. basedir=/usr/local/mysql
  44. datadir=/opt/data
  45. [root@zyy180 support-files]# service mysqld start
  46. 9.修改密码
  47. [root@zyy180 support-files]# mysql -uroot
  48. mysql> set password=password('1');
  49. [root@zyy180 ~]# ss -anlt
  50. State Recv-Q Send-Q Local Address:Port Peer Address:Port
  51. LISTEN 0 128 *:80 *:*
  52. LISTEN 0 128 *:22 *:*
  53. LISTEN 0 100 127.0.0.1:25 *:*
  54. LISTEN 0 128 :::22 :::*
  55. LISTEN 0 100 ::1:25 :::*
  56. LISTEN 0 80 :::3306 :::*

   

4.安装php

  1. C.安装php
  2. 下载php
  3. [root@zyy180 ~]# wget http://rpms.remirepo.net/enterprise/remi-release-7.rpm
  4. 解压
  5. [root@zyy180 ~]# tar xf php-7.4.7.tar.xz
  6. 启动php
  7. [root@zyy180 ~]# rpm -Uvh remi-release-7.rpm
  8. 下载缓存
  9. [root@zyy180 ~]# yum makecache --enablerepo=remi-php74
  10. 下载所需依赖包
  11. [root@zyy180 ~]# yum -y install libxml2 libxml2-devel \
  12. openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libicu-devel libjpeg \
  13. libjpeg-devel libpng libpng-devel openldap-devel pcre-devel \
  14. freetype freetype-devel gmp gmp-devel libmcrypt \
  15. libmcrypt-devel readline readline-devel libxslt libxslt-devel \
  16. mhash mhash-devel php74-php-mysqlnd
  17. 1.进到php
  18. [root@zyy180 php-7.4.7]# cd php-7.4.7
  19. 2.编译并安装
  20. [root@zyy180 ~]# yum -y install libsqlite3x-devel.x86_64 oniguruma-devel.x86_64
  21. ./configure --prefix=/usr/local/php7 \
  22. --with-config-file-path=/etc \
  23. --enable-fpm \
  24. --enable-inline-optimization \
  25. --disable-debug \
  26. --disable-rpath \
  27. --enable-shared \
  28. --enable-soap \
  29. --with-openssl \
  30. --enable-bcmath \
  31. --with-iconv \
  32. --with-bz2 \
  33. --enable-calendar \
  34. --with-curl \
  35. --enable-exif \
  36. --enable-ftp \
  37. --enable-gd \
  38. --with-jpeg \
  39. --with-png \
  40. --with-zlib \
  41. --with-freetype \
  42. --with-gettext \
  43. --enable-json \
  44. --enable-mbstring \
  45. --enable-pdo \
  46. --with-mysqli=mysqlnd \
  47. --with-pdo-mysql=mysqlnd \
  48. --with-readline \
  49. --enable-shmop \
  50. --enable-simplexml \
  51. --enable-sockets \
  52. --enable-zip \
  53. --enable-mysqlnd-compression-support \
  54. --with-pear \
  55. --enable-pcntl \
  56. --enable-posix
  57. 使用多核心编译
  58. [root@zyy180 php-7.4.7]# make -j $(cat /proc/cpuinfo |grep processor|wc -l)
  59. [root@zyy180 php-7.4.7]# make install
  60. 3.环境变量
  61. [root@zyy180 php-7.4.7]#echo 'export PATH=/usr/local/php7/bin:$PATH' > /etc/profile.d/php7.sh
  62. [[root@zyy180 php-7.4.7]#source /etc/profile.d/php7.sh
  63. 4.配置服务启动脚本
  64. php解压文件里
  65. [root@zyy180 php-7.4.7]# cp php.ini-production /etc/php.ini
  66. [root@zyy180 php-7.4.7]# cd sapi/fpm/
  67. [root@zyy180 fpm]# cp init.d.php-fpm /etc/init.d/php-fpm
  68. [root@zyy180 fpm]# chmod +x /etc/init.d/php-fpm
  69. 5.配置php-fpm
  70. [root@zyy180 etc]# cd /usr/local/php7/etc
  71. [root@zyy180 etc]# cp php-fpm.conf.default php-fpm.conf
  72. [root@zyy180 etc]# vim php-fpm.conf //优化
  73. pm.max_children = 50
  74. pm.start_servers = 5
  75. pm.min_spare_servers = 2
  76. pm.max_spare_servers = 8
  77. [root@zyy180 etc]# cd php-fpm.d/
  78. [root@zyy180 php-fpm.d]# cp www.conf.default www.conf
  79. [root@zyy180 php-fpm.d]# vim www.conf
  80. listen = 0.0.0.0:9000
  81. 6.启动服务
  82. [root@zyy180 ~]# service php-fpm start
  83. [root@zyy180 ~]# chkconfig --add php-fpm
  84. [root@zyy180 ~]# chkconfig --add mysqld

   

5.ngnix虚拟主机配置

  1. 1.进到nginx网站存放目录
  2. [root@zyy180 ~]# cd /usr/local/nginx/html/
  3. 2.写测试文件
  4. [root@zyy180 html]# vim index.php
  5. <?php
  6. phpinfo();
  7. ?>
  8. 3.修改配置文件
  9. [root@zyy180 ~]# vim /usr/local/nginx/conf/nginx.conf
  10. ##取消注释
  11. location ~ \.php$ {
  12. root html;
  13. fastcgi_pass 127.0.0.1:9000;
  14. fastcgi_index index.php;
  15. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  16. include fastcgi_params;
  17. }
  18. ##加上$document_root
  19. ##往上翻,加上index.php
  20. location / {
  21. root html;
  22. index index.php index.html index.htm;
  23. 4.重启nginx
  24. [root@zyy180 ~]# nginx -s stop
  25. [root@zyy180 ~]# nginx
  26. 重启mysql
  27. [root@zyy180 ~]# service mysqld restart
  28. Shutting down MySQL.. SUCCESS!
  29. Starting MySQL. SUCCESS!
  30. 重启php
  31. [root@zyy180 ~]# service php-fpm restart
  32. Gracefully shutting down php-fpm . done
  33. Starting php-fpm done
  34. 查看端口
  35. [root@zyy180 ~]# ss -anlt
  36. State Recv-Q Send-Q Local Address:Port Peer Address:Port
  37. LISTEN 0 128 *:80 *:*
  38. LISTEN 0 128 *:22 *:*
  39. LISTEN 0 100 127.0.0.1:25 *:*
  40. LISTEN 0 128 *:9000 *:*
  41. LISTEN 0 128 :::22 :::*
  42. LISTEN 0 100 ::1:25 :::*
  43. LISTEN 0 80 :::3306 :::*



http://192.168.30.150
在这里插入图片描述

在这里插入图片描述

发表评论

表情:
评论列表 (有 0 条评论,360人围观)

还没有评论,来说两句吧...

相关阅读