日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

LNMP架构的搭建

發布時間:2023/11/27 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 LNMP架构的搭建 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

LNMP 架構的搭建

基礎架構圖

環境:

server5: nginx? mysql?? php

//需要的安裝包 (藍色為解壓后的文件)

[root@test5 ~]# /etc/init.d/iptables stop??????? //關掉防火墻


MYSQL 源碼安裝

[root@test6 ~]#yum install -y gcc gcc-c++ make ncurses-devel bison
openssl-devel zlib-devel cmake?????????? //解決依賴性
[root@test6 ~]# ls
cmake-2.8.12.2-4.el6.x86_64.rpm mysql-boost-5.7.11.tar.gz
[root@test6 ~]# tar zxf mysql-boost-5.7.11.tar.gz
[root@test6 ~]# ls
cmake-2.8.12.2-4.el6.x86_64.rpm mysql-5.7.11 mysql-boost-5.7.11.tar.gz
[root@test6 ~]# yum install -y cmake-2.8.12.2-4.el6.x86_64.rpm
[root@test6 ~]# cd mysql-5.7.11/
[root@test6mysql-5.7.11]#cmake -DCMAKE_INSTALL_PREFIX=/usr/local/lnmp/mysql -DMYSQL_DATADIR=/usr/local/lnmp/mysql/data -DMYSQL_UNIX_ADDR=/usr/local/lnmp/mysql/data/mysql.sock-DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DDEFAULT_CHARSET=utf8
-DDEFAULT_COLLATION=utf8_general_ci -DEXTRA_CHARSETS=all -DWITH_BOOST=boost/boost_1_59_0/

注意:
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \??? #安裝目錄
-DMYSQL_DATADIR=/usr/local/mysql/data \??? #數據庫存放目錄
-DMYSQL_UNIX_ADDR=/usr/local/mysql/data/mysql.sock \ #Unix socket 文件路徑
-DWITH_MYISAM_STORAGE_ENGINE=1 \??? #安裝 myisam 存儲引擎
-DWITH_INNOBASE_STORAGE_ENGINE=1 \??? #安裝 innodb 存儲引擎
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \??? #安裝 archive 存儲引擎
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \??? #安裝 blackhole 存儲引擎
-DWITH_PARTITION_STORAGE_ENGINE=1 \??? #安裝數據庫分區
-DENABLED_LOCAL_INFILE=1 \??? #允許從本地導入數據
-DWITH_READLINE=1 \??? #快捷鍵功能
-DWITH_SSL=yes \??? #支持 SSL
-DDEFAULT_CHARSET=utf8 \??? #使用 utf8 字符
-DDEFAULT_COLLATION=utf8_general_ci \??? #校驗字符
-DEXTRA_CHARSETS=all \??? #安裝所有擴展字符集
-DMYSQL_TCP_PORT=3306 \??? #MySQL 監聽端口


編譯時可能會出現很多依賴性:
See also "/root/mysql-5.7.11/CMakeFiles/CMakeOutput.log".


[root@test6 ~]# yum install -y gcc gcc-c++
[root@test6 ~]# rm -rf CMakeCache.txt
[root@test6 ~]# yum install -y ncurses-devel
[root@test6 ~]# yum install -y bison???????

//每修改一次錯誤,就執行清緩存操作 rm -fr CMakeCache.txt 并再次編譯
//編譯三部曲 cmake / ./configure...../make/make install
[root@test6 ~]# make && make install
[root@test6 mysql-5.7.11]# cd /usr/local/lnmp/
[root@test6 lnmp]# ls
mysql
[root@test6 lnmp]#cd mysql


[root@test5 mysql]# cd support-files/
[root@test5 support-files]# pwd
/usr/local/lnmp/mysql/support-files
[root@test5 support-files]# cp my-default.cnf /etc/my.cnfcp: overwrite `/etc/my.cnf'? Y
[root@test5 support-files]# vim /etc/my.cnf

[root@test5 support-files]# file mysql.server
mysql.server: POSIX shell script text executable
[root@test5 support-files]# cp mysql.server /etc/init.d/mysqld
cp: overwrite `/etc/init.d/mysqld'? yes
[root@test5 support-files]# cd ..
[root@test5 mysql]# groupadd -g 27 mysql????? //創建組
[root@test5 mysql]# useradd -u 27 -g 27 -M -d /usr/local/lnmp/mysql/data -s????/sbin/nologin mysql???? //創建用戶
[root@test5 mysql]# cd
[root@test5 ~]# vim .bash_profile????????? //將路徑注明添加到環境變量

[root@test5 ~]# source .bash_profile?????????? //刷新環境變量
[root@test5 ~]# cd -
/usr/local/lnmp/mysql
[root@test5 mysql]# ls
bin
data include lib mysql-test share
COPYING docs keyring man README
support-files
[root@test5 mysql]# vim /etc/my.cnf

[root@test5 mysql]# mysqld --initialize --user=mysql???????????? //進行初始化

2018-10-10T05:37:45.328095Z 0 [ERROR] --initialize specified but the data
directory has files in it. Aborting.
2018-10-10T05:37:45.328132Z 0 [ERROR] Aborting
//出現這種問題,應將目錄切換到 mysql 下的 data 目錄,刪除 data 下的所有東西并重新初始化。若沒出現這種情況則步驟忽略。

[root@test5 mysql]# cd data/
[root@test5 data]# ls
auto.cnf? ibdata1?? ib_logfile1?? marry?? mysql.sock?? performance_schema test5.err?
ib_buffer_pool?? ib_logfile0?? ibtmp1?? mysql?? mysql.sock.lock?? sys? test5.pid

[root@test5 data]# rm -rf *

[root@test5 mysql]# cd ..
[root@test5 mysql]# mysqld --initialize --user=mysql???????? //再次初始化

2018-10-10T05:41:49.135259Z 0 [Warning] Gtid table is not ready to be used.
Table 'mysql.gtid_executed' cannot be opened.
2018-10-10T05:41:49.135787Z 1 [Note] A temporary password is generated for
root@localhost: e<hjlNprw7aj?????????? //localhost: 后面的為初始密碼用于后面的密碼初始化

[root@server5 mysql]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS!
[root@server5 mysql]# /etc/init.d/mysqld stop
Shutting down MySQL.. SUCCESS!
[root@server5 mysql]# chgrp root . -R??????????? //更改組及用戶
[root@test5 mysql]# ll

[root@server5 mysql]# chown mysql data/ -R????????? //初始化及登陸
[root@server5 mysql]# /etc/init.d/mysqld start

Starting MySQL. SUCCESS!

如果出現以下情況:

[root@test5 mysql]# /etc/init.d/mysqld start

Starting MySQL....
ERROR! The server quit without updating PID file (/usr/local/lnmp/mysql/data/test5.pid).
執行:

[root@test5 mysql]# chown -R mysql:mysql /var/data
[root@test5 mysql]# chown -R mysql:mysql /usr/local/lnmp/mysql/data
[root@test5 mysql]# chmod -R 755 /usr/local/lnmp/mysql/data
[root@test5 mysql]# /etc/init.d/mysqld restart????????? //重起服務,失敗

ERROR! MySQL server PID file could not be found!
Starting MySQL... ERROR! The server quit without updating PID file (/usr/local/lnmp/mysql/data/test5.pid).
//解決方法:用命令“ps -ef|grep mysqld”查看是否有 mysqld 進程,如果有使用“kill -9 進程號”殺掉,然后啟動 mysql
[root@test5 mysql]# ps -ef|grep mysqld????? //查看進程,殺掉 mysql 有關的進程

[root@test5 mysql]# /etc/init.d/mysqld start
Starting MySQL. SUCCESS!
[root@server5 mysql]# mysql_secure_installation??? //開啟服務,成功

Securing the MySQL server deployment.
Enter password for user root:????????????? //這里輸入初始密碼
The existing password for the user account root has expired. Please set a new
password.
New password:
Re-enter new password:????????? //輸入你想設置的數據庫密碼
VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?
Press y|Y for Yes, any other key for No:
Using existing password for root.
Change the password for root ? ((Press y|Y for Yes, any other key for No) :
... skipping.
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.
Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Success.
Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n
... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.Remove test database and access to it? (Press y|Y for Yes, any other key for
No) :
... skipping.
Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.
Reload privilege tables now? (Press y|Y for Yes, any other key for No) :
... skipping.
All done!

[root@server1 mysql]# mysql -p??????????? //登陸 mysql
[root@test5 mysql]# mysql -p

Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.

mysql> exit
Bye

?
PHP 源碼安裝

[root@test5 ~]# ls

cmake-2.8.12.2-4.el6.x86_64.rpm
libmcrypt-devel-2.5.8-9.el6.x86_64.rpm
php-5.6.35.tar.bz2
gd-devel-2.0.35-11.el6.x86_64.rpm
mysql-5.7.11
re2c-0.13.5-1.el6.x86_64.rpm
libmcrypt-2.5.8-9.el6.x86_64.rpm
mysql-boost-5.7.11.tar.gz

[root@test5 ~]# tar jxf php-5.6.35.tar.bz2
[root@test5 ~]# ls??? //下載依賴包
[root@test5 ~]# yum install -y libxml2-devel openssl-devel curl-devel? gd-devel-2.0.35-11.el6.x86_64.rpm? gmp-devellibmcrypt-2.5.8-9.el6.x86_64.rpm? libmcrypt-devel-2.5.8-9.el6.x86_64.rpm net-snmp-devel
[root@test5 ~]# rpm -ivh re2c-0.13.5-1.el6.x86_64.rpm

?

[root@test5 ~]# cd php-5.6.35
[root@test5~]./configure --prefix=/usr/local/lnmp/php --with-config-file-path=/usr/local/lnmp/php/etc --with-mysql=mysqlnd --enable-mysqlnd --with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-openssl --with-snmp --with-gd --with-zlib --with-curl --with-libxml-dir --with-png-dir --with-jpeg-dir --with-freetype-dir --with-pear --with-gettext --with-gmp --enable-inline-optimization --enable-soap --enable-ftp --enable-sockets --enable-mbstring --enable-fpm --with-fpm-user=nginx --with-fpm-group=nginx --with-mcrypt --with-mhash???? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //編譯第一步

遇到的問題及解決辦法
問題 1:
checking whether to enable JIS-mapped Japanese font support in GD... no
If configure fails try --with-vpx-dir=<DIR>
configure: error: jpeglib.h not found.

解決:
yum -y install libjpeg-devel
再次編譯
問題 2:
checking for jpeg_read_header in -ljpeg... yes
configure: error: png.h not found.解決:
yum install -y libpng-devel libpng
再次編譯
問題 3:
checking for png_write_image in -lpng... yes
If configure fails try --with-xpm-dir=<DIR>
configure: error: freetype-config not found.

解決:
[root@test5 php-5.6.35]# yum install -y freetype-devel


再次編譯


最后編譯成功
//可能遇到的其他問題:
問題 4:
No package xml2-config available.
Error: Nothing to do
解決:
[root@test5 php-5.6.35]# rpm -qa | grep libxml2
libxml2-python-2.7.6-14.el6.x86_64
libxml2-2.7.6-14.el6.x86_64
[root@test5 php-5.6.35]# yum install libxml2 libxml2-devel -y

問題 5:
configure: error: Please reinstall the libcurl distribution -
easy.h should be in <curl-dir>/include/curl/
解決:
[root@test5 php-5.6.35]# yum install curl curl-devel -y
問題 6:
configure: error: Could not find net-snmp-config binary. Please check your
net-snmp installation.
解決:
[root@test5 php-5.6.35]# yum -y install net-snmp-devel

[root@test5 php-5.6.35]# make && make install??????????? //編譯第二步和第三步

配置部分:

[root@test5 ~]# cd /usr/local/lnmp/php/
[root@test5 php]# ls
bin etc include lib php sbin var
[root@test5 php]# cd etc/
[root@test5 etc]# ls
pear.conf php-fpm.conf php-fpm.conf.default php.ini
[root@test5 etc]# cp php-fpm.conf.default php-fpm.conf
cp: overwrite `php-fpm.conf'? y
[root@test5 etc]# cd /root/php-5.6.35
[root@test5 etc]# cp php.ini-production /usr/local/lnmp/php/etc/php.ini
[root@test5 etc]# cd /usr/local/lnmp/php/etc/
[root@test5 etc]# ls
pear.conf php-fpm.conf php-fpm.conf.default php.ini
[root@test5 etc]# vim php.ini??????????????????????? //寫時間

[root@test5 etc]# vim php-fpm.conf?????????

???
??????????????????? //使第 25 行有效

[root@test5 etc]# useradd -M -d /usr/local/lnmp/nginx -s /sbin/nologin nginx???? //創建用戶
[root@test5 php-5.6.35]# cd /root/php-5.6.35/sapi/fpm/
[root@test5 fpm]# file init.d.php-fpm???????????????? //它是個腳本
init.d.php-fpm: POSIX shell script text executable
//[root@test5 fpm]# cp init.d.php-fpm /etc/init.d/php-fpm??????????????????? //將腳本文件傳到默認腳本路徑
[root@test5 fpm]# chmod +x /etc/init.d/php-fpm?????????????????? //給其可執行權限
[root@test5 fpm]# /etc/init.d/php-fpm start???????????????????? //執行文件
Starting php-fpm done


nginx 源碼安裝

需要的包
nginx-1.14.0.tar.gz
nginx-sticky-module-1.1.tar.gz

[root@test5 ~]# tar zxf nginx-sticky-module-1.1.tar.gz
[root@test5 ~]# tar zxf nginx-1.14.0.tar.gz
[root@test5 ~]# cd nginx-1.14.0
[root@test5 nginx-1.14.0]# ls
auto CHANGES CHANGES.ru conf configure contrib html LICENSE
man README src?

[root@test5 nginx-1.14.0]# vim src/core/nginx.h?????????????????????? //去掉 nginx 的版本號

[root@test5 nginx-1.14.0]# vim auto/cc/gcc???????????????????//注釋掉???

[root@test5 nginx-1.14.0]# yum install pcre-devel -y
[root@test5 nginx-1.14.0]# ./configure --prefix=/usr/local/lnmp/nginx --with-http_ssl_module --with-http_stub_status_module
--user=nginx --group=nginx --with-threads --with-file-aio????????????????????????????????? //同樣,根據報錯解決依賴性//編譯成功


//編譯成功

[root@test5 nginx-1.14.0]# make && make install
[root@test5 ~]# cd nginx-1.14.0
[root@test5 nginx-1.14.0]# cd /usr/local/lnmp/nginx/conf/
[root@test5 conf]# vim nginx.conf???????????????????????? //加入 index.php 會默認首先訪問 index.php

[root@test5 conf]# cd
[root@test5 ~]# vim .bash_profile

[root@test5 ~]# source .bash_profile //或者 ln -s /usr/local/lnmp/nginx/sbin/nginx /usr/local/sbin/????????? //做個軟連接
[root@test5 ~]# cd /usr/local/lnmp/nginx/html/
[root@test5 html]# vim index.php

[root@test5 html]# nginx -t ? ? ? ? ? ? //檢查 nginx 配置文件是否有錯誤
[root@test5 html]# nginx ? ? ? ? ? ? ?? //開啟 nginx 服務


在網頁進行訪問 172.25.1.5:

nginx 和 mysql 結合并安裝論壇

[root@test5 ~]# unzip Discuz_X3.2_SC_UTF8.zip -d /usr/local/lnmp/nginx/html
[root@test5 ~]# cd /usr/local/lnmp/nginx/html/
[root@test5 html]# ls
50x.html bbs index.html index.php readme utility
[root@test5 html]# mv upload bbs

網頁進行訪問 172.25.1.5/bbs:

[root@test5 bbs]# chmod 777 config/ data/ uc_server/ uc_client/ -R?????????? //修改權限

執行下一步

數據庫連接錯誤,執行:

[root@test5 bbs]# cd /usr/local/lnmp/php/etc/
[root@test5 etc]# vim php.ini
pdo_mysql.default_socket=/usr/local/lnmp/mysql/data/mysql.sock
mysql.default_socket =/usr/local/lnmp/mysql/data/mysql.sock
mysqli.default_socket =/usr/local/lnmp/mysql/data/mysql.sock

//分別是

[root@server5 etc]# /etc/init.d/php-fpm reload
[root@server5 etc]# cd /usr/local/lnmp/mysql/
[root@server5 mysql]# chmod 755 data/???

????????????????????

//下一步

登陸論壇:


登陸成功

上面提示刪除 index.php
故執行刪除操作:

[root@server5 mysql]# cd data
[root@server5 data]# cd /usr/local/lnmp/nginx/html/bbs/install/
[root@server5 install]# ls
data images include index.php
[root@server5 install]# rm -f index.php

最后,論壇發布成。

總結

以上是生活随笔為你收集整理的LNMP架构的搭建的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

歡迎分享!

轉載請說明來源于"生活随笔",并保留原作者的名字。

本文地址:LNMP架构的搭建