300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > 源码编译安装部署LNMP架构(Nginx MYSQL PHP+论坛)

源码编译安装部署LNMP架构(Nginx MYSQL PHP+论坛)

时间:2022-01-19 11:51:42

相关推荐

源码编译安装部署LNMP架构(Nginx MYSQL PHP+论坛)

目录

1.LNMP概述1.1 LNMP所需要的安装包 2.Nginx安装3. MYSQL安装4. PHP安装4.1 数据库安装 5. 论坛安装6. 小结

1.LNMP概述

LNMP:Linux系统下Nginx+MySQL+PHP这种网站服务器架构。Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器。

1.1 LNMP所需要的安装包

mysql-boost-5.7.20.tar.gz

nginx-1.15.9.tar.gz

php-7.1.10.tar.bz2

Discuz_X3.4_SC_UTF8.zip

2.Nginx安装

[root@client ~]# systemctl stop firewalld[root@client ~]# setenforce 0[root@client ~]# ping PING www. (180.101.49.12) 56(84) bytes of data.64 bytes from 180.101.49.12 (180.101.49.12): icmp_seq=1 ttl=128 time=3.79 ms#先关闭一下防火墙,确定网络可以与外界互通[root@client ~]# yum -y install gcc gcc-c++ pcre-devel zlib-devel make# yum 安装依赖包[root@client ~]# useradd -M -s /sbin/nologin nginx#为nginx建立一个单独的管理用户nginx[root@client ~]# cd /opt[root@client opt]# rz -Erz waiting to receive.[root@client opt]# unzip LNMP-C7-6.22.zip #进行解压压缩包[root@client opt]# lsDiscuz_X3.4_SC_UTF8.zip mysql-boost-5.7.20.tar.gz php-7.1.10.tar.bz2LNMP-C7-6.22.zip nginx-1.15.9.tar.gz rh[root@client opt]# tar zxvf nginx-1.15.9.tar.gz [root@client opt]# cd nginx-1.15.9/#一下进入源码编译[root@client nginx-1.15.9]# ./configure \> --prefix=/usr/local/nginx \> --user=nginx \> --group=nginx \> --with-http_stub_status_module[root@client nginx-1.15.9]# make && make install[root@client nginx-1.15.9]# ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/#设置软连接,方便调用[root@client nginx-1.15.9]# nginx -tnginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is oknginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful[root@client nginx-1.15.9]# vim /lib/systemd/system/nginx.service#制作systemctl管理文件,修改权限,用systemctl启动nginx[Unit]Description=nginxAfter=network.target[Service]Type=forkingPIDFile =/usr/local/nginx/logs/nginx.pidExecStart=/usr/local/nginx/sbin/nginxExecReload=/usr/bin/kill -S HUP $MAINPIDExecStop=/usr/bin/kill -S QUIT $MAINPIDPrivateTmp=true[Install]WantedBy=multi-user.target[root@client nginx-1.15.9]# chmod 754 /lib/systemd/system/nginx.service[root@client nginx-1.15.9]# systemctl stop nginx[root@client nginx-1.15.9]# systemctl start nginx[root@client nginx-1.15.9]# systemctl status nginx● nginx.service - nginxLoaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)Active: active (running) since 三 -06-23 00:47:41 CST; 5s ago#可以看到服务状态是开启的状态[root@client nginx-1.15.9]# ss -antp | grep 80LISTEN0128*:80 *:* users:(("nginx",pid=14910,fd=6),("nginx",pid=14909,fd=6))

3. MYSQL安装

#安装依赖包[root@client ~]# yum -y install \> ncurses \> ncurses-devel \> bison \> cmake[root@client ~]# useradd -s /sbin/nologin mysql#为mysql创建一个管理用户mysql[root@client ~]# cd /opt[root@client ~]# tar xzvf mysql-boost-5.7.20.tar.gz [root@client opt]# lsDiscuz_X3.4_SC_UTF8.zip mysql-boost-5.7.20.tar.gz php-7.1.10.tar.bz2LNMP-C7-6.22.zip nginx-1.15.9rhmysql-5.7.20 nginx-1.15.9.tar.gz[root@client opt]# cd mysql-5.7.20/#开始进行编译[root@client mysql-5.7.20]# cmake \> -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \> -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock \> -DSYSCONFDIR=/etc \> -DSYSTEMD_PID_DIR=/usr/local/mysql \> -DDEFAULT_CHARSET=utf8 \> -DDEFAULT_COLLATION=utf8_general_ci \> -DWITH_INNOBASE_STORAGE_ENGINE=1 \> -DWITH_ARCHIVE_STORAGE_ENGINE=1 \> -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \> -DWITH_PERFSCHEMA_STORAGE_ENGINE=1 \> -DMYSQL_DATADIR=/usr/local/mysql/data \> -DWITH_BOOST=boost \> -DWITH_SYSTEMD=1[root@client mysql-5.7.20]# make && make install[root@server mysql-5.7.20]# chown -R mysql.mysql /usr/local/mysql/#修改mysql属主和属组为mysql,否则影响启动[root@client ~]# chown mysql.mysql /etc/f#修改文件,mysql 可以通过sql_mode 来控制mysql 数据库的行为[root@client ~]# vim /etc/f[client]port = 3306default-character-set=utf8socket = /usr/local/mysql/mysql.sock[mysql]port = 3306default-character-set=utf8socket = /usr/local/mysql/mysql.sock[mysqld]user = mysqlbasedir = /usr/local/mysqldatadir = /usr/local/mysql/dataport = 3306character_set_server=utf8pid-file = /usr/local/mysql/mysqld.pidsocket = /usr/local/mysql/mysql.sockserver-id = 1sql_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[root@client ~]# #优化设置,添加进系统变量[root@client ~]# echo 'PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH' >> /etc/profile[root@client ~]# echo 'export PATH' >> /etc/profile[root@client ~]# source /etc/profile#初始化数据库[root@client ~]# cd /usr/local/mysql/bin/[root@client bin]# bin/mysqld \> --initialize-insecure \> --user=mysql \> --basedir=/usr/local/mysql \> --datadir=/usr/local/mysql/data-06-23T00:44:25.044025Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).-06-23T00:44:25.393629Z 0 [Warning] InnoDB: New log files created, LSN=45790-06-23T00:44:25.445677Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.#用systemctl启动mysql[root@client mysql]# cp usr/lib/systemd/system/mysqld.service /lib/systemd/system[root@client mysql]# systemctl start mysqld.service[root@client mysql]# netstat -antp | grep 3306tcp6 00 :::3306 :::*LISTEN103161/mysqld #为mysql创建管理账户root,密码为abc123 [root@client mysql]# mysqladmin -u root -p passwordEnter password: New password: Confirm new password: Warning: Since password will be sent to server in plain text, use ssl connection to ensure password safety.[root@client mysql]# mysql -u root -pEnter password: Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 4Server version: 5.7.20 Source distributionCopyright (c) 2000, , Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> exitBye

4. PHP安装

#安装依赖包[root@client ~]# yum -y install \libjpeg \libjpeg-devel \libpng libpng-devel \freetype freetype-devel \libxml2 \libxml2-devel \zlib zlib-devel \curl curl-devel \openssl openssl-devel[root@client ~]# cd /opt[root@client opt]# tar xjvf php-7.1.10.tar.bz2 [root@client opt]# cd php-7.1.10/#开始编译[root@client 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[root@client php-7.1.10]# make && make install#拷贝默认配置文件并修改配置[root@client php-7.1.10]# cp php.ini-development /usr/local/php/lib/php.ini[root@client php-7.1.10]# vim /usr/local/php/lib/php.ini 939 date.timezone = Asia/Shanghai1170 mysqli.default_socket = /usr/local/mysql/mysql.sock[root@client php-7.1.10]# /usr/local/php/bin/php -m#查看加载的模块#php-fpm有一个默认配置文件在/usr/local/php/etc/php-fpm.conf.default,需要把名字改成php-fpm.conf才能被识别[root@client php-7.1.10]# cd /usr/local/php/etc/[root@client etc]# lspear.conf php-fpm.conf.default php-fpm.d[root@client etc]# cp php-fpm.conf.default php-fpm.conf[root@client etc]# cd /usr/local/php/etc/php-fpm.d/[root@client php-fpm.d]# cp www.conf.default www.conf[root@client php-fpm.d]# cd /usr/local/php/etc/[root@client etc]# [root@client etc]# vim php-fpm.conf17 pid = run/php-fpm.pid[root@client etc]# /usr/local/php/sbin/php-fpm -c /usr/local/php/lib/php.ini [root@client etc]# netstat -anpt | grep 9000tcp 00 127.0.0.1:90000.0.0.0:*LISTEN111557/php-fpm:#把php的命令制作软链接到系统环境变量/usr/local/bin/下便于使用管理[root@client etc]# ln -s /usr/local/php/bin/* /usr/local/bin/[root@client etc]# ps aux | grep -c "php-fpm"4[root@client etc]# vim /usr/local/nginx/conf/nginx.conf65 location ~ \.php$ {66 root html;67 fastcgi_pass 127.0.0.1:9000;68 fastcgi_index index.php;69 fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;70 include fastcgi_params;71 }#修改nginx主页为php格式[root@client etc]# vim /usr/local/nginx/html/index.php<?phpphpinfo ();?>

4.1 数据库安装

[root@client etc]# mysql -u root -pEnter password: Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 5Server version: 5.7.20 Source distributionCopyright (c) 2000, , Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> CREATE DATABASE bbs;Query OK, 1 row affected (0.02 sec)mysql> GRANT all ON bbs.* To 'bbsuser'@'%' IDENTIFIED BY 'admin123';Query OK, 0 rows affected, 1 warning (0.03 sec)mysql> GRANT all ON bbs.* To 'bbsuser'@'localhost' IDENTIFIED BY 'admin123';Query OK, 0 rows affected, 1 warning (0.00 sec)mysql> flush privileges;Query OK, 0 rows affected (0.00 sec)mysql> show databases;+--------------------+| Database |+--------------------+| information_schema || bbs|| mysql || performance_schema || sys|+--------------------+5 rows in set (0.00 sec)mysql> exitBye[root@client etc]# vim /usr/local/nginx/html/index.php<?php<?php$link=mysqli_connect('192.168.152.129','bbsuser','admin123');if($link) echo "<h1>Success!!</h1>";else echo "Fail!!"?>

5. 论坛安装

[root@client etc]# cd /opt[root@client opt]# unzip Discuz_X3.4_SC_UTF8.zip -d /tmp/[root@client opt]# cd /tmp/[root@client tmp]# ls[root@client tmp]# cd dir_SC_UTF8/[root@client dir_SC_UTF8]# lsreadme upload utility[root@client dir_SC_UTF8]# cp -r upload/ /usr/local/nginx/html/bbs/[root@client dir_SC_UTF8]# ls /usr/local/nginx/html/50x.html bbs index.html index.php[root@client dir_SC_UTF8]# [root@client dir_SC_UTF8]# [root@client dir_SC_UTF8]# cd /usr/local/nginx/html/bbs/[root@client bbs]# chown -R root:nginx ./config/[root@client bbs]# chown -R root:nginx ./data/[root@client bbs]# chown -R root:nginx ./uc_client/[root@client bbs]# chown -R root:nginx ./uc_server/[root@client bbs]# chmod -R 777 ./config/[root@client bbs]# chmod -R 777 ./data/[root@client bbs]# chmod -R 777 ./uc_client/[root@client bbs]# chmod -R 777 ./uc_server/

6. 小结

介绍了nginx和apache的区别,以及详细的源码部署LNMP架构的方法,以及其中易错知识点

需要性能的 web 服务,用 nginx ,如果不需要性能只求稳定,更考虑 apache ,更为通用的方案是,前端 nginx 抗并发,后端 apache 集群,配合起来会更好。

apache因为把php模块集于一身成为一个整体,任何请求访问(静态,动态)都是apache(httpd)自己搞定的, 而nginx仅仅是一个传递的角色。它可以处理静态(图片,js,css等),但php相关的就得由后面的php-fpm来处理。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。