Distributed LNMP [centos7 + nginx1.24 + php8 + mysql8]
- Distributed source code deployment LNMP architecture
-
-
- Deploy MYSQL8
-
- yum deploy cmake3
- Source code deployment cmake3
- Upgrade GCC to higher version
- Start deploying mysql
- Deploy NGINX
- Deploy PHP
- Upload wordpress package
- Install wordpress
- Try uploading a theme
-
Distributed source code deployment LNMP architecture
192.168.100.62 Mysql
192.168.100.101 Nginx
192.168.100.102 PHP
Download the mysql nginx php source code package separately
mysql8: https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.35.tar.gz
php8: https://www.php.net/distributions/php-8.2.12.tar.gz
nginx: http://nginx.org/download/nginx-1.24.0.tar.gz
Deploy MYSQL8
1. MYSQL8 database source code compilation and installation requires cmake version greater than 3.5. +, cmake3 can be deployed using yum or binary package
2. Upgrade GCC to a higher version
yum deploys cmake3
#View the current cmake version [root@localhost ~]# cmake --version -bash: cmake: command not found #Install epel-release extension source [root@localhost ~]# yum install epel-release -y #Install cmake3 [root@localhost ~]# yum install cmake3 -y #Soft link the new version cmake3 to cmake; [root@localhost ~]# ln -s /usr/bin/cmake3 /usr/bin/cmake
Source code deployment cmake3
#cmake3 source code download [root@localhost ~]# wget -O /usr/src/cmake-3.7.2.tar.gz https://cmake.org/files/v3.7/cmake-3.7.2.tar.gz [root@localhost ~]# cd /usr/src/ [root@localhost src]# ls cmake-3.7.2.tar.gz debug kernels #decompression [root@localhost src]# tar -xf cmake-3.7.2.tar.gz #Compile and install [root@localhost src]# cd cmake-3.7.2 [root@localhost cmake-3.7.2]# ls Auxiliary cmake_uninstall.cmake.in DartConfig.cmake Source bootstrap CompileFlags.cmake doxygen.config Templates CMakeCPack.cmake configure Help Tests CMakeCPackOptions.cmake.in CONTRIBUTING.rst Licenses Utilities CMakeGraphVizOptions.cmake Copyright.txt Modules CMakeLists.txt CTestConfig.cmake Packaging CMakeLogo.gif CTestCustom.cmake.in README.rst [root@localhost cmake-3.7.2]# ./bootstrap & amp; & amp; make & amp; & amp; make install [root@localhost cmake-3.7.2]# rm -rf /usr/bin/cmake [root@localhost cmake-3.7.2]# ln -s /usr/local/bin/cmake /usr/bin/ [root@localhost cmake-3.7.2]# cmake --version cmake version 3.7.2 CMake suite maintained and supported by Kitware (kitware.com/cmake).
Upgrade GCC to a higher version
#Upgrade [root@localhost cmake-3.7.2]# yum -y install centos-release-scl #Install dependency packages and library files [root@localhost cmake-3.7.2]# yum -y install ncurses-devel make perl gcc autoconf automake zlib libxml2 libxml2-devel libgcrypt libtool bison devtoolset-10-gcc devtoolset-10-gcc-c + + devtoolset-10-binutils openssl openssl-devel #Enable new version of Gcc [root@localhost cmake-3.7.2]# scl enable devtoolset-10 bash [root@localhost cmake-3.7.2]# gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/opt/rh/devtoolset-10/root/usr/libexec/gcc/x86_64-redhat-linux/10/lto-wrapper Target: x86_64-redhat-linux Configured with: ../configure --enable-bootstrap --enable-languages=c,c++ ,fortran,lto --prefix=/opt/rh/devtoolset-10/root/usr --mandir=/opt/ rh/devtoolset-10/root/usr/share/man --infodir=/opt/rh/devtoolset-10/root/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique -object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --with-default-libstdcxx-abi=gcc4-compatible --enable- plugin --enable-initfini-array --with-isl=/builddir/build/BUILD/gcc-10.2.1-20210130/obj-x86_64-redhat-linux/isl-install --disable-libmpx --enable-gnu -indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux Thread model: posix Supported LTO compression algorithms: zlib gcc version 10.2.1 20210130 (Red Hat 10.2.1-11) (GCC)
Start deploying mysql
#Download mysql wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.35.tar.gz #Unzip mysql [root@localhost src]# tar -xf mysql-8.0.35.tar.gz [root@localhost src]# cd mysql-8.0.35 [root@localhost mysql-8.0.35]# ls client Doxyfile.in libmysql plugin storage cmake doxygen_resources libservices README strings CMakeLists.txt extra LICENSE router support-files components include man run_doxygen.cmake testclients config.h.cmake INSTALL mysql-test scripts unittest configure.cmake libbinlogevents MYSQL_VERSION share utilities Docs libbinlogstandalone mysys sql vio Doxyfile-ignored libchangestreams packaging sql-common #Precompile (there is a problem here) [root@localhost mysql-8.0.35]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql/ \ > -DMYSQL_UNIX_ADDR=/tmp/mysql.sock \ > -DMYSQL_DATADIR=/data/mysql/ \ > -DSYSCONFDIR=/etc \ > -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/ \ > -DFORCE_INSOURCE_BUILD=1 -- Running cmake version 3.7.2 -- This is .el7. as found from 'rpm -qf /' -- Looking for a devtoolset compiler CMake Warning at CMakeLists.txt:394 (MESSAGE): Could not find devtoolset compiler/linker in /opt/rh/devtoolset-11 CMake Warning at CMakeLists.txt:396 (MESSAGE): You need to install the required packages: yum install devtoolset-11-gcc devtoolset-11-gcc-c + + devtoolset-11-binutils CMake Error at CMakeLists.txt:398 (MESSAGE): Or you can set CMAKE_C_COMPILER and CMAKE_CXX_COMPILER explicitly. -- Configuring incomplete, errors occurred! #Install according to the prompts [root@localhost mysql-8.0.35]# yum install devtoolset-11-gcc devtoolset-11-gcc-c + + devtoolset-11-binutils -y #Download boost in advance before this [root@localhost mysql-8.0.35]# wget -O /usr/local/boost/boost_1_77_0.tar.bz2 https://boostorg.jfrog.io/artifactory/main/release/1.77.0/source/boost_1_77_0. tar.bz2 #Reprecompile [root@localhost mysql-8.0.35]# cmake . -DCMAKE_INSTALL_PREFIX=/usr/local/mysql/ \ > -DMYSQL_UNIX_ADDR=/tmp/mysql.sock \ > -DMYSQL_DATADIR=/data/mysql/ \ > -DSYSCONFDIR=/etc \ > -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 \ > -DDOWNLOAD_BOOST=1 \ > -DWITH_BOOST=/usr/local/boost \ > -DFORCE_INSOURCE_BUILD=1 #compile [root@localhost mysql-8.0.35]# make -j8 #Install [root@localhost mysql-8.0.35]# make -j8 install #Create data directory [root@localhost mysql-8.0.35]# mkdir -p /data/mysql #Create database user [root@localhost mysql-8.0.35]# useradd -s /sbin/nologin mysql -M #Initialize database [root@localhost mysql-8.0.35]# /usr/local/mysql/bin/mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql/ --datadir=/data/mysql / 2023-11-01T08:08:30.898167Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it ' is deprecated and will be removed in a future release. 2023-11-01T08:08:30.898241Z 0 [System] [MY-013169] [Server] /usr/local/mysql/bin/mysqld (mysqld 8.0.35) initializing of server in progress as process 65352 2023-11-01T08:08:30.899148Z 0 [Warning] [MY-013242] [Server] --character-set-server: 'utf8' is currently an alias for the character set UTF8MB3, but will be an alias for UTF8MB4 in a future release. Please consider using UTF8MB4 in order to be unambiguous. 2023-11-01T08:08:30.899154Z 0 [Warning] [MY-013244] [Server] --collation-server: 'utf8mb3_general_ci' is a collation of the deprecated character set UTF8MB3. Please consider using UTF8MB4 with an appropriate collation instead. 2023-11-01T08:08:30.905460Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started. 2023-11-01T08:08:31.097087Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended. 2023-11-01T08:08:31.812079Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option. #Set MYSQL as system service [root@localhost mysql-8.0.35]#ln -s /usr/local/mysql/bin/* /usr/bin/ [root@localhost mysql-8.0.35]# \cp support-files/mysql.server /etc/init.d/mysqld [root@localhost mysql-8.0.35]# chmod + x /etc/init.d/mysqld #Create my.cnf file [root@localhost mysql-8.0.35]# vim /etc/my.cnf [mysqld] basedir=/usr/local/mysql/ datadir=/data/mysql/ port=3306 pid-file=/data/mysql/mysql.pid socket=/tmp/mysql.sock [mysqld_safe] log-error=/data/mysql/mysql.log #Start mysql [root@localhost mysql]# /etc/init.d/mysqld start Starting MySQL. SUCCESS! #View process [root@localhost mysql]# netstat -nltp |grep 3306 tcp6 0 0 :::33060 :::* LISTEN 65958/mysqld tcp6 0 0 :::3306 :::* LISTEN 65958/mysqld [root@localhost mysql]# ps -ef |grep mysql root 65791 1 0 16:18 pts/0 00:00:00 /bin/sh /usr/local/mysql//bin/mysqld_safe --datadir=/data/mysql/ --pid-file=/data/mysql/ mysql.pid mysql 65958 65791 1 16:18 pts/0 00:00:00 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql/ --datadir=/data/mysql --plugin-dir= /usr/localmysql//lib/plugin --user=mysql --log-error=/data/mysql/mysql.log --pid-file=/data/mysql/mysql.pid --socket=/data/mysql /mysql.sock --port=3306 root 66009 27676 0 16:19 pts/0 00:00:00 grep --color=auto mysql #Loginmysql [root@localhost ~]# mysql Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.0.35 Source distribution Copyright (c) 2000, 2023, 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> #Change password 123456 mysql> alter user user() identified by "123456"; Query OK, 0 rows affected (0.01 sec) #Create wordpress database mysql> create database wordpress charset utf8; Query OK, 1 row affected, 1 warning (0.00 sec) #Create user webwz mysql> create user webwz@'%' identified by '123456'; Query OK, 0 rows affected (0.01 sec) #Authorize webwz permissions mysql> grant all on wordpress.* to webwz@'%'; Query OK, 0 rows affected (0.00 sec) mysql> flush privileges; Query OK, 0 rows affected (0.00 sec) At this point the database is basically done.
Deploy NGINX
#Source code download [root@localhost ~]# wget -O /usr/src/nginx-1.24.0.tar.gz https://nginx.org/download/nginx-1.24.0.tar.gz [root@localhost ~]# cd /usr/src/ [root@localhost src]# ls debug kernels nginx-1.24.0.tar.gz #decompression [root@localhost src]# tar -xf nginx-1.24.0.tar.gz [root@localhost src]# cd nginx-1.24.0 #Install dependent libraries [root@localhost nginx-1.24.0]# yum install pcre pcre-devel zlib zlib-devel -y #Precompiled [root@localhost nginx-1.24.0]# ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module #Compile & amp; & amp;Install [root@localhost nginx-1.24.0]# make & amp; & amp; make install #Create nginx user [root@localhost nginx-1.24.0]# useradd -s /sbin/nologin nginx #Modify the user in the configuration file to nginx [root@localhost nginx-1.24.0]# vim /usr/local/nginx/conf/nginx.conf #linknginx [root@localhost nginx-1.24.0]# ln -s /usr/local/nginx/sbin/nginx /usr/bin/nginx #start up [root@localhost nginx-1.24.0]# nginx #Check if the process is up [root@localhost nginx-1.24.0]# ps -ef |grep nginx root 14114 1 0 02:02 ? 00:00:00 nginx: master process nginx nginx 14115 14114 0 02:02 ? 00:00:00 nginx: worker process root 14117 1311 0 02:02 pts/0 00:00:00 grep --color=auto nginx #nginx configuration file modification, integrate php location ~ \.php$ { root /usr/local/nginx/html; fastcgi_pass 192.168.100.102:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } -------------------------------------------------- ---------------------------------- If you need to do PHP load balancing, please refer to the following Added in http module upstream php-wordpress { server 192.168.100.102:9000; server 192.168.100.104:9000; } Added in server module location ~ \.php$ { root /usr/local/nginx/html; fastcgi_pass php-wordpress; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } ##Finally copy the wordpress source file to the php server [root@localhost html]# scp -r * 192.168.100.102:/usr/local/nginx/html #Be sure to pay attention to the permissions, otherwise the installation will not be possible. [root@localhost html]# chown -R nginx. /usr/local/nginx/html
Deploy PHP
#Download source code [root@localhost src]# wget https://www.php.net/distributions/php-8.2.12.tar.gz --no-check-certificate [root@localhost src]# ls debug kernels php-8.2.12.tar.gz [root@localhost src]# tar -xf php-8.2.12.tar.gz [root@localhost src]# cd php-8.2.12 [root@localhost php-8.2.12]# ls appveyor configure EXTENSIONS php.ini-development sapi UPGRADING build configure.ac LICENSE php.ini-production scripts UPGRADING.INTERNALS buildconf CONTRIBUTING.md main README.md tests win32 buildconf.bat docs NEWS README.REDIST.BINS travis Zend CODING_STANDARDS.md ext pear run-tests.php TSRM #Install dependencies [root@localhost php-8.2.12]# yum -y install gd curl curl-devel libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel openssl openssl-devel sqlite-devel -y #Precompiled [root@localhost php-8.2.12]# ./configure --prefix=/usr/local/php \ > --enable-fpm \ > --with-fpm-user=nginx \ > --with-fpm-group=nginx \ > --enable-debug \ > --with-gd \ > --with-jpeg-dir \ > --with-png-dir \ > --with-freetype-dir \ > --enable-mbstring \ > --with-curl \ > --with-mysqli=mysqlnd \ > --with-mysql-sock=/data/mysql/mysql.sock \ > --with-pdo-mysql=mysqlnd \ > --with-config-file-path=/usr/local/php/etc \ > --with-zip \ > --with-zlib \ > --with-zlib-dir \ > --with-openssl If it prompts that the openssl version is low, please update the openssl version. Refer below #1. Download wget https://www.openssl.org/source/old/1.1.1/openssl-1.1.1.tar.gz #2. Unzip and switch directories tar -zxvf openssl-1.1.1.tar.gz cd openssl-1.1.1 #3. Set the Openssl installation, the (--prefix) parameter is the directory to be installed, that is, the installed files will appear in this directory. ./config --prefix=/usr/local/openssl #4. Execute the command ./config-t #5. Execute make, make install, compile Openssl make & make install # If there is no GCC compiler in CentOS7, execute the command yum -y install gcc to install GCC. #6. Switch openssl version mv /usr/bin/openssl /usr/bin/openssl.bak mv /usr/include/openssl /usr/include/openssl.bak ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl ln -s /usr/local/openssl/include/openssl /usr/include/openssl echo "/usr/local/openssl/lib" >> /etc/ld.so.conf ldconfig -v ln -s /usr/local/openssl/lib/libssl.so.1.1 /usr/lib64/libssl.so.1.1 ln -s /usr/local/openssl/lib/libcrypto.so.1.1 /usr/lib64/libcrypto.so.1.1 #Note: Soft links cannot be deleted directly #If you need to use a new version for development, you need to replace the original soft link pointer, that is, replace the original dynamic library and upgrade the version. #Replace the corresponding dynamic libraries that exist in /lib(lib64) and /usr/lib(lib64) and /usr/local/lib(lib64): ln -sf /usr/local/openssl/lib/libssl.so.1.1 /usr/lib64/libssl.so ln -sf /usr/local/openssl/lib/libcrypto.so.1.1 /usr/lib64/libcrypto.so ##There are many problems with source code installation of php and some software versions need to be updated. #onigurumaproblem handling wget https://github.com/kkos/oniguruma/archive/v6.9.4.tar.gz -O oniguruma-6.9.4.tar.gz [root@localhost oniguruma-6.9.4]# yum -y install autoconf automake libtool [root@localhost oniguruma-6.9.4]# ./autogen.sh [root@localhost oniguruma-6.9.4]# ./configure --prefix=/usr --libdir=/lib64 [root@localhost oniguruma-6.9.4]# make & amp; & amp; make install
After the problem is solved, re-precompile [root@localhost php-8.2.12]# ./configure --prefix=/usr/local/php \ > --enable-fpm \ > --with-fpm-user=nginx \ > --with-fpm-group=nginx \ > --enable-debug \ > --with-gd \ > --with-jpeg-dir \ > --with-png-dir \ > --with-freetype-dir \ > --enable-mbstring \ > --with-curl \ > --with-mysqli=mysqlnd \ > --with-mysql-sock=/data/mysql/mysql.sock \ > --with-pdo-mysql=mysqlnd \ > --with-config-file-path=/usr/local/php/etc \ > --with-zip \ > --with-zlib \ > --with-zlib-dir \ > --with-openssl ... +------------------------------------------------- ------------------ + | License: | | This software is subject to the PHP License, available in this | | distribution in the file LICENSE. By continuing this installation | | process, you are bound by the terms of this license agreement. | | If you do not agree with the terms of this license, you must abort | | the installation process at this point. | +------------------------------------------------- ------------------ + Thank you for using PHP. #Compile and install [root@localhost php-8.2.12]# make & amp; & amp; make install #Create configuration file [root@localhost php-8.2.12]# cp php.ini-development /usr/local/php/etc/php.ini [root@localhost php-8.2.12]# cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf [root@localhost php-8.2.12]# cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.conf #Create startup script [root@localhost php-8.2.12]# cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm [root@localhost php-8.2.12]# chmod + x /etc/init.d/php-fpm #Start php [root@localhost php-8.2.12]# /etc/init.d/php-fpm start Starting php-fpm [01-Nov-2023 04:48:31] ERROR: [pool www] cannot get uid for user 'nginx' [01-Nov-2023 04:48:31] ERROR: FPM initialization failed failed #Create nginx user (nginx was written when compiling above) [root@localhost php-8.2.12]# useradd -s /sbin/nologin nginx -M [root@localhost php-8.2.12]# /etc/init.d/php-fpm start Starting php-fpm done #View port process [root@localhost php-8.2.12]# ps -ef |grep php root 59916 1 0 04:50 ? 00:00:00 php-fpm: master process (/usr/local/php/etc/php-fpm.conf) nginx 59917 59916 0 04:50 ? 00:00:00 php-fpm: pool www nginx 59918 59916 0 04:50 ? 00:00:00 php-fpm: pool www root 59920 1313 0 04:50 pts/0 00:00:00 grep --color=auto php [root@localhost php-8.2.12]# netstat -nltp |grep 9000 tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 59916/php-fpm: mast ### Modify php configuration file [root@localhost php-8.2.12]# vim /usr/local/php/etc/php-fpm.d/www.conf listen = 0.0.0.0:9000 listen.allowed_clients = 127.0.0.01,192.168.100.101
Upload wordpress package
[root@localhost ~]# cd /usr/local/nginx/html/ [root@localhost html]# wget https://cn.wordpress.org/latest-zh_CN.tar.gz [root@localhost html]# tar -xf latest-zh_CN.tar.gz [root@localhost html]# mv wordpress/* .
Install wordpress
Upload a theme to try