当前位置:网站首页>Explanation of LNMP architecture source code compilation and installation with pictures and texts (with forum experiment)

Explanation of LNMP architecture source code compilation and installation with pictures and texts (with forum experiment)

2022-06-11 19:41:00 [email protected]

1 install Nginx service

1. Turn off firewall , take Nginx Required packages to /opt Under the table of contents

systemctl stop firewalld  # Turn off firewall 
systemctl disable firewalld  # Turn off the firewall and turn it on 
setenforce 0   # Turn off system security 

cd /opt    # Switch to /opt Catalog 
nginx-1.12.0.tar.gz

 Insert picture description here

2. Install dependency packages

yum -y install pcre-devel zlib-devel gcc gcc-c++ make   # Install the required development kit ,  To provide the corresponding libraries and header files, as well as the compilation environment and compiler 

 Insert picture description here

3. Create a running user 、 Group
(Nginx The service program defaults to nobody Identity running , It is recommended to create a special user account for it , In order to more accurately control its access rights )

useradd -M -s /sbin/nologin nginx   # Create program users , So as to control access accurately 
#Nginx The service program runs as an anonymous user by default 

 Insert picture description here

4. Compilation and installation Nginx

cd /opt
tar zxvf nginx-1.12.0.tar.gz -C /opt/

cd nginx-1.12.0/
./configure \   # Use configure
--prefix=/usr/local/nginx \				    # Appoint nginx Installation path for 
--user=nginx \								# Specify user name 
--group=nginx \								# Specify the group name 
--with-http_stub_status_module				# Enable  http_stub_status_module  Module to support State Statistics 

make && make install  # Compile and install 

 Insert picture description here
5. Optimize the path

ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/		# Let the system recognize nginx Operation command of 

6. add to Nginx system service

vim /lib/systemd/system/nginx.service
[Unit]
Description=nginx
After=network.target
[Service]
Type=forking        # Background run type 
PIDFile=/usr/local/nginx/logs/nginx.pid     #PID file location 
ExecStart=/usr/local/nginx/sbin/nginx   # Start the service 
ExecrReload=/bin/kill -s HUP $MAINPID    # according to PID Overload configuration 
ExecrStop=/bin/kill -s QUIT $MAINPID    # according to PID Terminate the process 
PrivateTmp=true
[Install]
WantedBy=multi-user.target   # Start level 

chmod 754 /lib/systemd/system/nginx.service
systemctl start nginx.service
systemctl enable nginx.service

 Insert picture description here

2 install MySQL service

1. Will install mysql The required software package is transferred to /opt Under the table of contents

mysql-boost-5.7.20.tar.gz

 Insert picture description here

2、 install Mysql Environment dependent packages

yum -y install \
ncurses \
ncurses-devel \
bison \
cmake

 Insert picture description here
3. Create a running user

useradd -M -s /sbin/nologin  mysql

 Insert picture description here
4. Compilation and installation

cd /opt
tar zxvf mysql-boost-5.7.20.tar.gz

cd /opt/mysql-5.7.20/
cmake \
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql \		# Appoint mysql Installation path for 
-DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \ # Appoint mysql The process listens to socket files ( Database connection file ) Storage path for 
-DSYSCONFDIR=/etc \                             # Specify the storage path of the configuration file 
-DSYSTEMD_PID_DIR=/usr/local/mysql \            # Specifies the storage path of the process file 
-DDEFAULT_CHARSET=utf8  \                       # Specifies the default character set encoding , Such as  utf8
-DDEFAULT_COLLATION=utf8_general_ci \			# Specifies the character set collation rules to be used by default 
-DWITH_EXTRA_CHARSETS=all \						# Specify support for other character set encoding 
-DWITH_INNOBASE_STORAGE_ENGINE=1 \              # install INNOBASE Storage engine 
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \               # install ARCHIVE Storage engine  
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \             # install BLACKHOLE Storage engine  
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \            # install FEDERATED Storage engine  
-DMYSQL_DATADIR=/usr/local/mysql/data \         # Specify the storage path of the database file 
-DWITH_BOOST=/usr/local/boost \          # Appoint boost The path of , If you use mysql-boost Integration package installation is -DWITH_BOOST=boost
-DWITH_SYSTEMD=1               # Generation facilitates systemctl Administrative document 

make && make install

 Insert picture description here
 Insert picture description here
 Insert picture description here
5. modify mysql The configuration file

vim /etc/my.cnf
[client]
port = 3306
socket=/usr/local/mysql/mysql.sock

[mysqld]
user = mysql
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
port = 3306
character-set-server=utf8
pid-file = /usr/local/mysql/mysqld.pid
socket=/usr/local/mysql/mysql.sock
bind-address = 0.0.0.0
skip-name-resolve
max_connections=2048
default-storage-engine=INNODB
max_allowed_packet=16M
server-id = 1

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_AUTO_VALUE_ON_ZERO,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,PIPES_AS_CONCAT,ANSI_QUOTES

 Insert picture description here

6. change mysql The primary group of the installation directory and configuration files

chown -R mysql:mysql /usr/local/mysql/
chown mysql:mysql /etc/my.cnf

 Insert picture description here

7. Set the path environment variable

echo 'export PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile	
source /etc/profile

 Insert picture description here

8. Initialize database

cd /usr/local/mysql/bin/
./mysqld \
--initialize-insecure \				# Generate initialization password is empty 
--user=mysql \                      # Generate initialization password is empty 
--basedir=/usr/local/mysql \        # Specify the installation directory of the database 
--datadir=/usr/local/mysql/data		# Specify the storage path of the database file 

 Insert picture description here

9. add to mysqld system service

cp /usr/local/mysql/usr/lib/systemd/system/mysqld.service /usr/lib/systemd/system/		# be used for systemctl Service management 
systemctl daemon-reload         # Refresh recognition  
systemctl start mysqld.service  # Opening service 
systemctl enable mysqld         # Boot up 
netstat -anpt | grep 3306       # Check the port 

 Insert picture description here
10. modify mysql Login password for

mysqladmin -u root -p password "abc123" 	# to root Set the password to abc123, The prompt is the original password ( It's empty )

 Insert picture description here
11. Authorize remote login

mysql -u root -p
grant all privileges on *.* to 'root'@'%' identified by 'abc123';
# grant root Users can log in remotely at all terminals , The password used is abc123, And all databases and all tables have operation permissions 
% Represents a wildcard arbitrary value 
show databases;			# View the existing database 

 Insert picture description here

3 Installation configuration PHP Analyze the environment

1. Will install PHP The required software package is transferred to /opt Under the table of contents

php-7.1.10.tar.bz2

 Insert picture description here
2. Install environment dependency package

yum -y install \
gd \
libjpeg libjpeg-devel \
libpng libpng-devel \
freetype freetype-devel \
libxml2 libxml2-devel \
zlib zlib-devel \
curl curl-devel \
openssl openssl-devel

 Insert picture description here
3. Compilation and installation

cd /opt
tar jxvf php-7.1.10.tar.bz2

cd php-7.1.10
./configure \
--prefix=/usr/local/php \
--with-mysql-sock=/usr/local/mysql/mysql.sock \
--with-mysqli \
--with-zlib \
--with-curl \
--with-gd \
--with-jpeg-dir \
--with-png-dir \
--with-freetype-dir \
--with-openssl \
--enable-fpm \
--enable-mbstring \
--enable-xml \
--enable-session \
--enable-ftp \
--enable-pdo \
--enable-tokenizer \
--enable-zip

make && make install

 Insert picture description here
 Insert picture description here
4. Path optimization

ln -s /usr/local/php/bin/* /usr/local/bin/
ln -s /usr/local/php/sbin/* /usr/local/sbin/

 Insert picture description here

5. adjustment PHP The configuration file
php There are three profiles :
php.ini Master profile
php-fpm.conf Process service profile
www.conf Extended profile

Adjust the main profile

cp /opt/php-7.1.10/php.ini-development /usr/local/php7/php.ini	
# Use... In the test environment php.ini-development file , And in the production environment php.ini-production file 
vim /usr/local/php7/php.ini
--1170 That's ok -- modify 
mysqli.default_socket = /usr/local/mysql/mysql.sock
--939 That's ok -- uncomment , modify 
date.timezone = Asia/Shanghai

php -m 					# Verify the installed module 

 Insert picture description here
 Insert picture description here
Adjust the process service profile

cd /usr/local/php/etc/
cp  php-fpm.conf.default php-fpm.conf
vim php-fpm.conf
--17 That's ok -- Get rid of ";" notes 
pid = run/php-fpm.pid

 Insert picture description here
Adjust the extended profile

cd /usr/local/php/etc/php-fpm.d/
cp www.conf.default www.conf

 Insert picture description here
6. start-up php-fpm

/usr/local/php/sbin/php-fpm -c /usr/local/php/lib/php.ini
netstat -anpt | grep 9000

 Insert picture description here
PHP-FPM(FastCGI Process Manager:FastCGI Process Manager ) It's a PHPFastCGI Manager , because Nginx The server can't handle dynamic pages , Need by Nginx Give the dynamic request to php-fpm Process

cd /opt/php-7.1.10/sapi/fpm
cp php-fpm.service /usr/lib/systemd/system/php-fpm.service
systemctl restart php-fpm.service

 Insert picture description here
7. To configure Nginx Support PHP analysis

vim /usr/local/nginx/conf/nginx.conf
--65 That's ok -- uncomment , modify 
location ~ \.php$ {
    
	root           html;
	fastcgi_pass   127.0.0.1:9000;
	fastcgi_index  index.php;
	fastcgi_param  SCRIPT_FILENAME  /usr/local/nginx/html$fastcgi_script_name;	# take  /scripts  It is amended as follows nginx Working directory of 
   #fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; #$document_root  On behalf of the current request root The value specified in the instruction 
	include        fastcgi_params;
}

systemctl restart nginx.service

 Insert picture description here
8. verification PHP Test page

vim /usr/local/nginx/html/index.php
<?php
phpinfo();
?>

 Browser access 
http://192.168.16.16/index.php

 Insert picture description here
 Insert picture description here
9. Verify that the database is working properly

mysql -u root -p
CREATE DATABASE bbs;   # establish bbs library 
show databases;     # View Library 
GRANT all ON bbs.* TO 'bbsuser'@'%' IDENTIFIED BY 'admin123';
to Create user later ,% All users 
GRANT all ON bbs.* TO 'bbsuser'@'localhost' IDENTIFIED BY 'admin123';
flush privileges;

vim /usr/local/nginx/html/index.php      		# Replace the content of the original test page 
<?php
$link=mysqli_connect('192.168.16.16','bbsuser','admin123');
if($link) echo "<h1>Success!!</h1>";
else echo "Fail!!";
?>

 Browser access 
http://192.168.16.16/index.php

 Insert picture description here
 Insert picture description here
 Insert picture description here

4 Deploy Discuz! Community BBS Web application

cd /opt
unzip Discuz_X3.4_SC_UTF8.zip  -d /opt/dis
cd /opt/dis/dir_SC_UTF8/
cp -r upload/ /usr/local/nginx/html/bbs/     # Upload site update package 

 Insert picture description here
 Insert picture description here
Adjust the permissions of forum Directory

ps aux							# The user name of the forum process is daemon
cd /usr/local/nginx/html/bbs/
chown -R daemon ./config
chown -R daemon ./data
chown -R daemon ./uc_client
chown -R daemon ./uc_server/data
 or 
chmod -R 777 ./config/
chmod -R 777 ./data/
chmod -R 777 ./uc_client/
chmod -R 777 ./uc_server/

 Insert picture description here

Forum page access

http://192.168.16.16/bbs/install/index.php

 database server :localhost     ### It's built locally localhost, How not to fill in on this machine IP Address and port number 
 Database name :bbs
 Database user name :bbsuser
 Database password :admin123
 Administrator account :admin
 Administrator password :admin123

 Visit the forum page :
http://192.168.16.16/bbs/index.php
http://192.168.16.16/bbs/admin.php

 Insert picture description here
 Insert picture description here
 Insert picture description here
 Insert picture description here
installation is complete
 Insert picture description here
 Insert picture description here
 Insert picture description here

5 fpm Parameter optimization

Nginx Of PHP If the implementation of parsing function is entrusted to FPM To deal with the , In order to improve the PHP Processing speed of , But for FPM Module to adjust the parameters , According to the memory and service load of the server , adjustment FPM Module parameters

vim /usr/local/php/etc/php-fpm.conf 
pid = run/php-fpm.pid
 
vim /usr/local/php/etc/php-fpm.d/www.conf
--96 That's ok --
pm = dynamic				#fpm Process startup mode , Dynamic 
--107 That's ok --
pm.max_children=20			#fpm The maximum number of processes started by a process 
--112 That's ok --
pm.start_servers = 5		# The number of processes started by default when starting in dynamic mode , Between the smallest and the largest 
--117 That's ok --
pm.min_spare_servers = 2	# Minimum number of idle processes in dynamic mode 
--122 That's ok --
pm.max_spare_servers = 8	# The maximum number of idle processes in dynamic mode 
 
-----------------------------------------------------------------------------
kill -USR2 `cat /usr/local/php/var/run/php-fpm.pid`			# restart php-fpm
 perhaps systemctl start php-fpm.service
netstat -anpt | grep 9000
ps -elf | grep php-fpm

 Insert picture description here
 Insert picture description here

原网站

版权声明
本文为[[email protected]]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/162/202206111936500062.html