LNMP部署
环境
系统 | ip | 部署服务 |
---|
centos8-stream | 192.168.245.128 | nginx | centos8-stream | 192.168.245.131 | php | centos8-stream | 192.168.245.129 | mysql |
lnmp由linux,nginx,mysql,php构成
作为 Web 服务器:相比 Apache,Nginx 使用更少的资源,支持更多的并发连接,体现更高的效率。
作为负载均衡服务器:Nginx 既可以在内部直接支持Rails和PHP,也可以支持作为 HTTP代理服务器对外进行服务。Nginx 用C编写,不论是系统资源开销还是CPU使用效率都比Perlbal要好的多。
作为邮件代理服务器:Nginx同时也是一个非常优秀的邮件代理服务器(最早开发这个产品的目的之一也是作为邮件代理服务器),Last/fm 描述了成功并且美妙的使用经验。
Nginx 安装非常的简单,配置文件非常简洁(还能够支持perl语法)。Nginx支持平滑加载新的配置,还能够在不间断服务的情况下进行软件版本的升级。具体的优点或者配置文件详解可以看之前的nginx基础
[root@localhost nginx-1.20.2]
[root@localhost nginx-1.20.2]
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost nginx-1.20.2]
部署nginx:
[root@localhost ~]
[root@localhost ~]
[root@localhost ~]
[root@localhost ~]
[root@localhost ~]
[root@localhost src]
/usr/src
[root@localhost src]
[root@localhost src]
[root@localhost src]
[root@localhost nginx-1.20.2]
[root@localhost nginx-1.20.2]
[root@localhost nginx-1.20.2]
[root@localhost nginx-1.20.2]
[root@localhost nginx-1.20.2]
/usr/local/nginx/sbin/nginx
[root@localhost nginx-1.20.2]
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@localhost nginx-1.20.2]
nginx version: nginx/1.20.2
[root@localhost nginx-1.20.2]
[root@localhost nginx-1.20.2]
[root@localhost nginx-1.20.2]
[Unit]
Description=nginx server daemon
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx
ExecStop=/usr/local/nginx/sbin/nginx -s stop
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
[root@localhost nginx-1.20.2]
[root@localhost nginx-1.20.2]
[root@localhost nginx-1.20.2]
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:80 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
[root@localhost nginx-1.20.2]
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
body {
width: 35em;
margin: 0 auto;
font-family: Tahoma, Verdana, Arial, sans-serif;
}
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>
<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>
<p><em>Thank you for using nginx.</em></p>
</body>
</html>
部署php
[root@localhost ~]
anaconda-ks.cfg php-8.1.11.tar.gz to.sh
[root@localhost ~]
[root@localhost ~]
[root@localhost ~]
[root@localhost php-8.1.11]
[root@localhost php-8.1.11]
[root@localhost ~]
[root@localhost ~]
./configure --prefix=/usr/local/php8 \
--with-config-file-path=/etc \
--enable-fpm \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-soap \
--with-openssl \
--enable-bcmath \
--with-iconv \
--with-bz2 \
--enable-calendar \
--with-curl \
--enable-exif \
--enable-ftp \
--enable-gd \
--with-jpeg \
--with-zlib-dir \
--with-freetype \
--with-gettext \
--enable-json \
--enable-mbstring \
--enable-pdo \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-readline \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--with-zip \
--enable-mysqlnd-compression-support \
--with-pear \
--enable-pcntl \
--enable-posix
[root@localhost php-8.1.11]
[root@localhost php-8.1.11]
make: *** No rule to make target 'installecho'. Stop.
[root@localhost php-8.1.11]
[root@localhost php-8.1.11]
/usr/local/php8/bin/php
[root@localhost php-8.1.11]
PHP 8.1.11 (cli) (built: Oct 11 2022 15:56:45) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.11, Copyright (c) Zend Technologies
[root@localhost php-8.1.11]
cp: overwrite '/etc/php.ini'? y
[root@localhost php-8.1.11]
[root@localhost sapi]
apache2handler cgi cli embed fpm fuzzer litespeed phpdbg
[root@localhost sapi]
[root@localhost fpm]
init.d.php-fpm: POSIX shell script, ASCII text executable
[root@localhost /]
[root@localhost /]
[root@localhost etc]
[root@localhost php-fpm.d]
Starting php-fpm done
[root@localhost php-fpm.d]
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 127.0.0.1:9000 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
[root@localhost php-fpm.d]
[root@localhost fpm]
[root@localhost fpm]
[root@localhost fpm]
[root@localhost php8]
[root@localhost etc]
[root@localhost etc]
[root@localhost php-fpm.d]
/启动php-fpm并设为开机自启
[root@localhost php-fpm.d]
Starting php-fpm done
[root@localhost php-fpm.d]
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 128 127.0.0.1:9000 0.0.0.0:*
LISTEN 0 128 [::]:22 [::]:*
[root@localhost php-fpm.d]
listen = 127.0.0.1:9000
;listen.allowed_clients = 192.168.245.128
[root@localhost ~]
[root@localhost ~]
[root@localhost ~]
[root@localhost ~]
[root@localhost ~]
[root@localhost html]
[root@localhost html]
<?php
phpinfo();
?>
[root@localhost php-fpm.d]
部署mysql
[root@master ~]
网页访问上地址下载
?
[root@master ~]
[root@master ~]
[root@master local]
apache apr bin games include lib64 mysql-5.7.38-linux-glibc2.12-x86_64 share
apache2.4 apr-util etc httpd lib libexec sbin src
[root@master local]
[root@master local]
[root@master local]
apache apr bin games include lib64 mysql share
apache2.4 apr-util etc httpd lib libexec sbin src
[root@master local]
[root@master local]
drwxr-xr-x. 9 mysql mysql 129 Aug 2 21:03 /usr/local/mysql
[root@master local]
?
[root@master ~]
LICENSE README bin docs include lib man share support-files
[root@master ~]
[root@master ~]
[root@master ~]
/usr/local/mysql/bin:/usr/local/httpd/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
[root@master ~]
?
[root@master ~]
[root@master ~]
[root@master ~]
total 468
drwxr-xr-x. 2 mysql mysql 6 Aug 2 21:06 data
-rw-r--r--. 1 root root 478044 Aug 2 10:55 tang.sql
[root@master ~]
?
?
[root@master ~]
------------------
root@localhost: s!a<7i5!DoLa
[root@master ~]
[root@master ~]
s!a<7i5!DoLa
[root@master ~]
?
[root@master ~]
'/usr/local/include/mysql' -> '/usr/local/mysql/include/'
[root@master ~]
[root@master ~]
[root@master ~]
?
[root@master ~]
> [mysqld]
> basedir = /usr/local/mysql
> datadir = /opt/data
> socket = /tmp/mysql.sock
> port = 3306
> pid-file = /opt/data/mysql.pid
> user = mysql
> skip-name-resolve
> EOF
[root@master ~]
?
[root@master ~]
[root@master ~]
[root@master ~]
[root@master ~]
?
[root@master ~]
Starting MySQL.Logging to '/opt/data/master.err'.
SUCCESS!
[root@master ~]
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 [::]:22 [::]:*
[root@master ~]
?
[root@master ~]
?
mysql> set password = password('1');
Query OK, 0 rows affected, 1 warning (0.00 sec)
?
mysql>
————————————————
修改nginx配置文件
[root@localhost ~]
[root@localhost nginx]
client_body_temp conf fastcgi_temp html logs proxy_temp sbin scgi_temp uwsgi_temp
[root@localhost nginx]
[root@localhost conf]
location / {
root html;
index index.php index.html index.htm;
}
location ~ \.php$ {
root html;
fastcgi_pass 192.168.245.131:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi_params;
}
[root@localhost conf]
[root@localhost nginx]
[root@localhost html]
[root@localhost html]
<?php phpinfo(); ?>
|