lnmp
LNMP
环境说明
主机名 | IP地址 | 服务 | 系统 |
---|---|---|---|
RS0 | 192.168.29.141 | mysql | centos8 |
RS1 | 192.168.29.138 | nginx | centos8 |
RS2 | 192.168.29.143 | php | centos8 |
1.mysql
[root@RS0 ~]# setenforce 0
[root@RS0 ~]# sed -ri 's/^(SELINUX=).*/\1disabled/g' /etc/selinux/config
[root@RS0 ~]# systemctl disable --now firewalld.service
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@RS0 ~]# wget https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz
--2022-10-11 21:46:34-- https://downloads.mysql.com/archives/get/p/23/file/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz
Resolving downloads.mysql.com (downloads.mysql.com)... 23.64.178.143, 2600:140b:2:99c::2e31, 2600:140b:2:99d::2e31
Connecting to downloads.mysql.com (downloads.mysql.com)|23.64.178.143|:443... connected.
HTTP request sent, awaiting response... 302 Moved Temporarily
Location: https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz [following]
--2022-10-11 21:46:35-- https://cdn.mysql.com/archives/mysql-5.7/mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz
Resolving cdn.mysql.com (cdn.mysql.com)... 23.3.85.25
Connecting to cdn.mysql.com (cdn.mysql.com)|23.3.85.25|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 674830866 (644M) [application/x-tar-gz]
Saving to: 'mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz'
mysql-5.7.38-linux-g 100%[====================>] 643.57M 3.70MB/s in 2m 3s
2022-10-11 21:48:39 (5.22 MB/s) - 'mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz' saved [674830866/674830866]
[root@RS0 ~]# ls
anaconda-ks.cfg mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz
[root@RS0 ~]# tar -xf mysql-5.7.38-linux-glibc2.12-x86_64.tar.gz -C /usr/local/[root@RS0 ~]# mv /usr/local/mysql-5.7.38-linux-glibc2.12-x86_64/ /usr/local//mysql
[root@RS0 ~]# useradd -rMs /sbin/nologin mysql
[root@RS0 ~]# chown -R mysql.mysql /usr/local/mysql/
[root@RS0 ~]# echo 'export PATH=$PATH:/usr/local/mysql/bin' > /etc/profile.d/mysql.sh
[root@RS0 ~]# source /etc/profile.d/mysql.sh
[root@RS0 ~]# mkdir /opt/mysqldata
[root@RS0 ~]# chown -R mysql.mysql /opt/mysqldata/
[root@RS0 ~]# ln -sv /usr/local/mysql/include /usr/include/mysql
'/usr/include/mysql' -> '/usr/local/mysql/include'
[root@RS0 ~]# echo "/usr/local/mysql/lib" > /etc/ld.so.conf.d/mysql.conf
[root@RS0 ~]# ldconfig
[root@RS0 ~]# echo "MANDATORY_MANPATH /usr/local/mysql/man" >> /etc/man_db.conf
[root@RS0 ~]# mysqld --initialize --user mysql --datadir /opt/mysqldata
2022-10-11T13:57:06.085626Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2022-10-11T13:57:07.044895Z 0 [Warning] InnoDB: New log files created, LSN=45790
2022-10-11T13:57:07.202006Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2022-10-11T13:57:07.234913Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 97ea1330-496c-11ed-94d1-000c29b9bdf9.
2022-10-11T13:57:07.236224Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2022-10-11T13:57:07.553243Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2022-10-11T13:57:07.553288Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2022-10-11T13:57:07.553828Z 0 [Warning] CA certificate ca.pem is self signed.
2022-10-11T13:57:07.744863Z 1 [Note] A temporary password is generated for root@localhost: ,jaZVsR+j1N3
[root@RS0 ~]# vim /etc/my.cnf
[mysqld]
basedir = /usr/local/mysql
datadir = /opt/mysqldata
socket = /tmp/mysql.sock
port = 3306
pid-file = /opt/mysqldata/mysql.pid
user = mysql
skip-name-resolve
sql-mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
[root@RS0 ~]# dnf -y install ncurses-compat-libs
[root@RS0 ~]# vim /lib/systemd/system/mysqld.service
[Unit]
Description=mysql server daemon
After=network.target sshd-keygen.target
[Service]
Type=forking
ExecStart=/usr/local/mysql/support-files/mysql.server start
ExecStop=/usr/local/mysql/support-files/mysql.server stop
ExecReload=/bin/kill -HUP
[Install]
WantedBy=multi-user.target
[root@RS0 ~]# systemctl daemon-reload
[root@RS0 ~]# systemctl restart mysqld.service
[root@RS0 ~]# systemctl status mysqld.service
● mysqld.service - mysql server daemon
Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled; vendor prese>
Active: active (running) since Tue 2022-10-11 22:01:23 CST; 8s ago
Process: 55148 ExecStart=/usr/local/mysql/support-files/mysql.server start (cod>
Main PID: 55161 (mysqld_safe)
Tasks: 28 (limit: 24717)
Memory: 182.2M
CGroup: /system.slice/mysqld.service
├─55161 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/opt/mysqld>
└─55361 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datad>
Oct 11 22:01:22 RS0 systemd[1]: Starting mysql server daemon...
Oct 11 22:01:22 RS0 mysql.server[55148]: Starting MySQL.Logging to '/opt/mysqldat>
Oct 11 22:01:23 RS0 mysql.server[55148]: SUCCESS!
Oct 11 22:01:23 RS0 systemd[1]: Started mysql server daemon.
[root@RS0 ~]# ss -antl
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 [::]:22 [::]:*
LISTEN 0 80 *:3306 *:*
[root@RS0 ~]# vim /etc/my.cnf
skip-grant-tables
[root@RS0 ~]# systemctl restart mysqld.service
[root@RS0 ~]# mysql -e " update mysql.user set authentication_string=password('123456') where user = 'root' and host = 'localhost'; "
[root@RS0 ~]# vim /etc/my.cnf
skip-grant-tables //再删除这添加的一行
[root@RS0 ~]# mysql -uroot -p123456
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.38
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
2. nginx
[root@RS1 ~]# setenforce 0
[root@RS1 ~]# sed -ri 's/^(SELINUX=).*/\1disabled/g' /etc/selinux/config
[root@RS1 ~]# systemctl disable --now firewalld.service
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@RS1 ~]# useradd -rMs /sbin/nologin nginx
[root@RS1 ~]# dnf -y install pcre-devel openssl openssl-devel gd-devel gcc gcc-c++ make wget vim
[root@RS1 ~]# wget http://nginx.org/download/nginx-1.20.2.tar.gz
--2022-10-11 22:19:06-- http://nginx.org/download/nginx-1.20.2.tar.gz
Resolving nginx.org (nginx.org)... 3.125.197.172, 52.58.199.22, 2a05:d014:edb:5702::6, ...
Connecting to nginx.org (nginx.org)|3.125.197.172|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1062124 (1.0M) [application/octet-stream]
Saving to: 'nginx-1.20.2.tar.gz'
nginx-1.20.2.tar.gz 100%[====================>] 1.01M 552KB/s in 1.9s
2022-10-11 22:19:09 (552 KB/s) - 'nginx-1.20.2.tar.gz' saved [1062124/1062124]
[root@RS1 ~]# tar -xf nginx-1.20.2.tar.gz
[root@RS1 ~]# cd nginx-1.20.2/
[root@RS1 nginx-1.20.2]# ./configure \
> --prefix=/usr/local/nginx \
> --user=nginx \
> --group=nginx \
> --with-debug \
> --with-http_ssl_module \
> --with-http_realip_module \
> --with-http_image_filter_module \
> --with-http_gunzip_module \
> --with-http_gzip_static_module \
> --with-http_stub_status_module
......
[root@RS1 nginx-1.20.2]# make -j $(grep 'processor' /proc/cpuinfo | wc -l) && make install
......
[root@RS1 nginx-1.20.2]# cd /usr/local/nginx/
[root@RS1 nginx]# ls
conf html logs sbin
[root@RS1 nginx]# cd
[root@RS1 ~]# echo "export PATH=$PATH:/usr/local/nginx/sbin" > /etc/profile.d/nginx.sh
[root@RS1 ~]# source /etc/profile.d/nginx.sh
[root@RS1 ~]# nginx
[root@RS1 ~]# ss -antl
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@RS1 ~]# nginx -s stop
[root@RS1 ~]# ss -anlt
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 [::]:22 [::]:*
[root@RS1 ~]# cat > /usr/lib/systemd/system/nginx.service << EOF
> [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
> EOF
[root@RS1 ~]# systemctl daemon-reload
[root@RS1 ~]# systemctl enable --now nginx.service
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service.
[root@RS1 ~]# ss -anlt
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@RS1 ~]#
3. php
[root@RS2 ~]# sed -ri 's/^(SELINUX=).*/\1disabled/g' /etc/selinux/config
[root@RS2 ~]# systemctl disable --now firewalld.service
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@RS2 ~]# cd /etc/yum.repos.d/
[root@RS2 yum.repos.d]# ls
CentOS-Base.repo CentOS-Stream-HighAvailability.repo
CentOS-Stream-AppStream.repo CentOS-Stream-Media.repo
CentOS-Stream-BaseOS.repo CentOS-Stream-PowerTools.repo
CentOS-Stream-Debuginfo.repo CentOS-Stream-RealTime.repo
CentOS-Stream-Extras.repo cobbler-config.repo
[root@RS2 yum.repos.d]# rm -rf *
[root@RS2 yum.repos.d]# ls
[root@RS2 yum.repos.d]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 2495 100 2495 0 0 4882 0 --:--:-- --:--:-- --:--:-- 4873
[root@RS2 yum.repos.d]# ls
CentOS-Base.repo
[root@RS2 yum.repos.d]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@RS2 yum.repos.d]# dnf -y install epel-release
[root@RS2 yum.repos.d]#dnf -y install libxml2 libxml2-devel openssl openssl-devel bzip2 bzip2-devel libcurl libcurl-devel libicu-devel libjpeg libjpeg-devel libpng libpng-devel openldap-devel pcre-devel freetype freetype-devel gmp gmp-devel libmcrypt libmcrypt-devel readline readline-devel libxslt libxslt-devel mhash mhash-devel php-mysqlnd libsqlite3x-devel libzip-devel wget gcc gcc-c++ make
[root@RS2 yum.repos.d]#dnf -y install http://mirror.centos.org/centos/8-stream/PowerTools/x86_64/os/Packages/oniguruma-devel-6.8.2-2.el8.x86_64.rpm
[root@RS2 yum.repos.d]# cd
[root@RS2 ~]# wget https://www.php.net/distributions/php-8.1.11.tar.gz
--2022-10-11 10:38:01-- https://www.php.net/distributions/php-8.1.11.tar.gz
Resolving www.php.net (www.php.net)... 185.85.0.29, 2a02:cb40:200::1ad
Connecting to www.php.net (www.php.net)|185.85.0.29|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 19725720 (19M) [application/octet-stream]
Saving to: 'php-8.1.11.tar.gz'
php-8.1.11.tar.gz 100%[====================>] 18.81M 32.2KB/s in 5m 42s
2022-10-11 10:43:44 (56.3 KB/s) - 'php-8.1.11.tar.gz' saved [19725720/19725720]
[root@RS2 ~]# tar -xf php-8.1.11.tar.gz -C /usr/local/src/
[root@RS2 ~]# cd /usr/local/src/php-8.1.11/
[root@RS2 php-8.1.11]# ./configure --prefix=/usr/local/php \
> --with-config-file-path=/etc \
> --enable-fpm \
> --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-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@RS2 php-8.1.11]#make -j $(grep 'processor' /proc/cpuinfo | wc -l) && make install
[root@RS2 php-8.1.11]# cd /usr/local/php/
[root@RS2 php]# ls
bin etc include lib php sbin var
[root@RS2 php]# cp etc/php-fpm.conf.default etc/php-fpm.conf
[root@RS2 php]# cp etc/php-fpm.d/www.conf.default etc/php-fpm.d/www.conf
[root@RS2 php]# ln -s /usr/local/php /usr/include/php
[root@RS2 php]# echo "/usr/local/php/lib" > /etc/ld.so.conf.d/php.conf
[root@RS2 php]# ldconfig
[root@RS2 php]# cat > /usr/lib/systemd/system/php.service << EOF
> [Unit]
> Description=php server daemon
> After=network.target
>
> [Service]
> Type=forking
> ExecStart=/usr/local/php/sbin/php-fpm
> ExecStop=ps -ef |grep php |grep -v grep|awk '{print$2}'|xargs kill
> ExecReload=/bin/kill -HUP $MAINPID
>
> [Install]
> WantedBy=multi-user.target
> EOF
[root@RS2 php]# systemctl daemon-reload
[root@RS2 php]# systemctl enable --now php.service
Created symlink /etc/systemd/system/multi-user.target.wants/php.service → /usr/lib/systemd/system/php.service.
[root@RS2 php]# ss -anlt
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@RS2 php]# mkdir -p /usr/local/nginx/html
[root@RS2 php]# cat > /usr/local/nginx/html/index.php << EOF
> <?php
> phpinfo();
> ?>
> EOF
[root@RS2 php]# vi /usr/local/php/etc/php-fpm.d/www.conf
listen =192.168.29.143:9000
listen.allowed_clients = 192.168.29.138
[root@RS2 ~]# systemctl restart php.service
[root@RS1 ~]# cat > /usr/local/nginx/html/index.php << EOF
> <?php
> phpinfo();
> ?>
> EOF
[root@RS1 ~]# systemctl restart nginx.service
[root@RS1 ~]# vim /usr/local/nginx/conf/nginx.conf
location / {
root html;
index index.html index.htm index.php;
......
location ~ \.php$ {
root html;
fastcgi_pass 192.168.29.143:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME
$document_root$fastcgi_script_name;
include fastcgi_params;
}
[root@RS1 ~]# systemctl reload nginx.service
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 提示词工程——AI应用必不可少的技术
· 地球OL攻略 —— 某应届生求职总结
· 字符编码:从基础到乱码解决
· SpringCloud带你走进微服务的世界