lnmp部署

2022/9/2 6:22:52

本文主要是介绍lnmp部署,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

一,安装nginx

1.安装nginx依赖库

 yum install lrzsz wget git make cmake gcc gcc-c++ pcre pcre-devel openssl openssl-devel ncurses-devel libaio bison git ncurses -y

二.安装nginx源码

2.1 创建nginx用户,用于运行nginx创建网站数据存放目录

# 创建Nginx运行用户[root@duduhome ~]# useradd -s /sbin/nologin -M www
# -s :指定bash目录,nologin表示该用户不能登录
# -M:不创建home目录
# 创建网站数据存放目录[root@duduhome ~]# mkdir -p /data/www/html && mkdir -p /data/www/error_page

2.2 下载nginx源码包

wget -c http://nginx.org/download/nginx-1.18.0.tar.gz && tar zxf nginx-1.18.0

2.3编译并安装nginx

预编译
./configure --user=www  --group=www  --prefix=/usr/local/nginx  --with-http_ssl_module  --with-http_stub_status_module  --with-pcre
没有报错后直接安装
make  && make install

2.4参数文件参数

user  www;
worker_processes  auto;

events {
    use epoll;
    worker_connections  65565;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  logs/access.log  main;

    # 响应头信息状态,更改响应头里面的Server字段用
    server_tokens off;

    # 加速访问,sedfile:直接内核处理,tcp_nopush:不阻塞
    sendfile        on;
    tcp_nopush     on;

    #keepalive_timeout  0;
    # 防爬虫,30秒内最多只能请求100次
    keepalive_timeout   30;
    keepalive_requests  100;

    # 开启压缩文件, 文件大于10K后就开始进行压缩,
    # 只对文件的类型是text/plain text/xml 的文件压缩
    gzip  on;
    gzip_min_length 10k;
    gzip_types  text/plain  text/xml;   # 压缩类型,公司里面开发会说明
    gzip_comp_level 5;                  # 压缩级别

    server {
      listen 443 ssl;

      # 填写绑定证书的域名
      server_name www.xxxxxx.com;
      # 网站主页路径。此路径仅供参考,具体请您按照实际目录操作。
      root /data/www/html;
      index index.html index.htm index.php;

      # 证书文件名称
      ssl_certificate  /data/www/html/src/ssl/1_www.xxxxx.com_bundle.crt;
      # 私钥文件名称
      ssl_certificate_key /data/www/html/src/ssl/2_www.xxxxx.com.key;
      ssl_session_timeout 5m;
      ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
      ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
      ssl_prefer_server_ciphers on;

      location / {
         index index.php index.html index.htm;
      }

      location ~ \.php$ {
         root           /data/www/html;
         fastcgi_pass   127.0.0.1:9000;
         fastcgi_index  index.php;
         fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
         include        fastcgi_params;
       }

       # deny access to .htaccess files, if Apache's document root
       # concurs with nginx's one
       location ~ /\.ht {
         deny  all;
       }
    }

    server {
        listen 80;
        #填写绑定证书的域名
        server_name www.xxxxxx.com;
        #把http的域名请求转成https
        return 301 https://$host$request_uri;
    }
}

三,搭建php-fpm

3.1.安装php-fpm

# CentOS 7 Yum里面没有php7.0以上的,所以要更新下repo源
[root@duduhome nginx-1.18.0]# rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm
[root@duduhome nginx-1.18.0]# rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm


# 安装 php-fpm 7.2版本
[root@duduhome nginx-1.18.0]# yum install php72w php72w-devel php72w-fpm php72w-mysql -y

3.2.配置pfp-fpm的配置文件

[root@duduhome nginx-1.18.0]# vim /etc/php-fpm.d/www.conf

/* 
把里面的 
    user = apache   group = apache
更改为
    user = www   group = www

因为我只有一台服务器,所以
    listen = 127.0.0.1:9000
我就不更改了,若要设置静态分离,这里就要设置为你的动态处理的服务器IP
*/

四,安装mysql数数据库

4.1 获取方式:

# 下载mysql:
[root@duduhome opt]# wget http://mirrors.163.com/mysql/Downloads/MySQL-5.7/mysql-5.7.28.tar.gz
# 下载boost:
[root@duduhome opt]# wget http://nchc.dl.sourceforge.net/project/boost/boost/1.59.0/boost_1_59_0.tar.gztar xf boost_1_59_0.tar.gz

# 下载二进制包(免安装,解压直接使用):
wget -c  https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.28-linux-glibc2.12-x86_64.tar

4.2,安装mysql 5.7数据库

# 安装mysql依赖包
[root@duduhome ~]# yum install lrzsz wget git make cmake gcc gcc-c++ pcre pcre-devel openssl openssl-devel ncurses-devel libaio bison git ncurses numactl numactl-devel -y

# 解压源码包
[root@duduhome ~]# tar zxf mysql-5.7.28.tar.gz   && cd mysql-5.7.28
[root@duduhome ~]# tar zxf boost_1_59_0.tar.gz && mv boost_1_59_0 boost

# 预编译
[root@duduhome mysql-5.7.28]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock -DMYSQL_DATADIR=/data/mysql -DSYSCONFDIR=/usr/local/mysql -DMYSQL_USER=mysql -DMYSQL_TCP_PORT=3306 -DWITH_XTRADB_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_READLINE=1 -DENABLED_LOCAL_INFILE=1 -DWITH_EXTRA_CHARSETS=1 -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DWITH_BIG_TABLES=1 -DWITH_DEBUG=0 -DWITH_BOOST=../boost
# 安装:
[root@duduhome mysql-5.7.28]# make && make install

4.3,修改配置文件

[root@duduhome opt]# vim /etc/my.cnf

[mysqld]
server-id=1
log-bin=mysql-bin
basedir=/usr/local/mysql
datadir=/data/mysql
port=3306
socket=/data/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd
[mysqld_safe]
log-error=/data/mysql/logs/mysql.log
pid-file=/data/mysql/mysql.pid

#
# include all files from the config directory
#!includedir /etc/my.cnf.d

4.5,创建数据库数据目录和所需文件(以配置文件里面的参数为主)

# 数据库数据存放目录:
[root@duduhome ~]# mkdir /data/mysql/

# 日志文件:
[root@duduhome ~]# mkdir /dat+a/mysql/logs
[root@duduhome ~]# touch /data/mysql/logs/mysql.log

# 给所有mysql目录权限:
[root@duduhome ~]# chown mysql. -R /data/mysql

# 给日志文件写、执行权限:
[root@duduhome ~]# chmod 755 /data/mysql/logs/mysql.log

PS:在启动的时候,若有报错,请按错误提示来处理,但是按这个来,一般不会有问题

4.6 初始化数据库

# 无临时密码(--initialize-insecure)
[root@duduhome ~]# /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --datadir=/data/mysql/3306 --basedir=/usr/local/mysql


#有临时密码(--initialize)
[root@duduhome ~]# /usr/local/mysql/bin/mysqld --initialize --user=mysql --datadir=/data/mysql/3306 --basedir=/usr/local/mysql




# 使用无临时密码初始化时,初始化完成就可以直接启动mysql,然后连接到数据库
# 而使用的是有临时密码的方式初始化时,在启动数据库后,要先密码下密码,然后才能连接到数据库

4.7 mysql数据库的重启命令

# 启动:
[root@duduhome opt]# /usr/local/mysql/support-files/mysql.server start

# 重启:
[root@duduhome opt]# /usr/local/mysql/support-files/mysql.server restart
[root@duduhome opt]# /usr/local/mysql/support-files/mysql.server reload

# 停止:
[root@duduhome opt]# /usr/local/mysql/support-files/mysql.server stop

# 运行状态:
[root@duduhome opt]# /usr/local/mysql/support-files/mysql.server status

# 查看帮助:
[root@duduhome opt]# /usr/local/mysql/support-files/mysql.server
[root@duduhome opt]# /usr/local/mysql/support-files/mysql.server --help
[root@duduhome opt]# /usr/local/mysql/support-files/mysql.server -h

五,网站wordpress网站环境

5.1获取wordpress源码

wget https://cn.wordpress.org/latest-zh_CN.tar.gz

5.2把wordpress网站代码拷贝到网站数据目录下

# 解压:
[root@duduhome ~]# tar zxf wordpress-5.4.1-zh_CN.tar.gz  && cd wordpress-5.4.1

# 拷贝网站代码到网站数据目录下:
[root@duduhome wordpress-5.4.1]# mv wordpress/*  /data/www/html/

5.3 给网站数据目录配置权限,让网站其正常运作

chown www. -R /data/www/html

5.4 创建数据库连接

5.4.1初始化无密码方式:

/usr/local/mysql/bin/mysql

5.4.2 初始化生成临时密码方式

# 先修改my.cnf配置文件,让其能空命令登录mysql,否则会报错:ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using # password: NO)

[root@www_1 ~]# vim /etc/my.cnf
# 在 [mysqld] 的最后一行加上一句:“skip-grant-tables”
# 然后保存,在重启下 mysql 即可正常连接到数据库

[root@www_1 ~]# /usr/local/mysql/support-files/mysql.server restart
[root@www_1 ~]# /usr/local/mysql/bin/mysql


# 修改密码:
mysql> update mysql.user set authentication_string=password("WS5mNoir69vEN!H6iw") where user="root";
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1

ysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql> 


# 测试下用密码是否可以登录上Mysql:
mysql> quit;
Bye
[root@www_1 ~]# /usr/local/mysql/bin/mysql -uroot -p
Enter password: 
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 5
Server version: 5.7.28

mysql> 
# 登录成功!!!
# 这个时候要修改新的密码,否则下次登录进Mysql后,在创建表之类的就会出现 “ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statemen”的错误

# 重新修改密码:
mysql> alter user 'root'@'localhost' identified by '&E83fcl1Al#NvnqF';
Query OK, 0 rows affected (0.00 sec)

mysql>

5,5 创建wordpress网站使用的数据库

# 创建数据库:
mysql> create database ddhome charset=utf8;
Query OK, 1 row affected (0.00 sec)

# 授权网站连接:
mysql> grant all on ddhome.* to "wordpress"@192.168.174.130 identified by "P&rQ4$scC#5Cujxr";
Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

mysql>

六,在前端上完成最后的wordress配置操作

 

 

 

 



这篇关于lnmp部署的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程