LNMP架構介紹
- 和LAMP不一樣的是,提供web服務的是Nginx
- 而且php是做爲一個獨立服務存在的,這個服務叫作php-fpm
- Nginx直接處理靜態請求,動態請求會轉發給php-fpm
MySQL從新安裝
- MySQL是經過免編譯二進制安裝包進行安裝的,須要刪除對應的目錄後進行重裝,重裝以前要先中止服務
[root@test-a ~]# ps -ef | grep mysql
root 1449 1 0 14:35 ? 00:00:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/data/mysql --pid-file=/usr/local/mysql/mysqld.pid
mysql 1930 1449 0 14:35 ? 00:00:02 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/data/mysql --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/db.err --pid-file=/usr/local/mysql/mysqld.pid --socket=/usr/local/mysql/mysql.sock --port=3306
root 2496 2430 0 15:09 pts/0 00:00:00 grep --color=auto mysql
[root@test-a ~]# service mysqld stop
Shutting down MySQL.. SUCCESS!
[root@test-a ~]# rm -rf /usr/local/mysql # 刪除MySQL安裝目錄
[root@test-a ~]# rm -rf /etc/init.d/mysqld # 刪除MySQL服務腳本
[root@test-a ~]# rm /data/mysql/* -rf # 清空MySQL數據
[root@test-a ~]# cd /usr/local/src/
[root@test-a src]# tar -zxvf mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz
[root@test-a src]# mv mysql-5.7.23-linux-glibc2.12-x86_64 /usr/local/mysql
[root@test-a src]# ls /usr/local/mysql
bin COPYING docs include lib man README share support-files
[root@test-a src]# cd /usr/local/mysql
[root@test-a mysql]# id mysql # 須要mysql用戶,查看是否存在
uid=1007(mysql) gid=1008(mysql) groups=1008(mysql)
[root@test-a mysql]# ./bin/mysqld --initialize --user=mysql --datadir=/data/mysql #初始化,生成MySQL啓動須要的一些目錄和文件
2018-11-25T07:27:03.963759Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-11-25T07:27:03.986922Z 0 [ERROR] Could not open file '/usr/local/mysql/db.err' for error logging: Permission denied
2018-11-25T07:27:03.986975Z 0 [ERROR] Aborting
[root@test-a mysql]# touch /usr/local/mysql/db.err
[root@test-a mysql]# chown mysql:mysql db.err
[root@test-a mysql]# ./bin/mysqld --initialize --user=mysql --datadir=/data/mysql # 此次生成的臨時密碼在db.err文件中
[root@test-a mysql]# cp support-files/mysql.server /etc/init.d/mysqld # 拷貝啓動腳本
[root@test-a mysql]# vim /etc/init.d/mysqld # 編輯啓動腳本,設置basedir和datadir
basedir=/usr/local/mysql
datadir=/data/mysql
# 啓動
[root@test-a mysql]# /etc/init.d/mysqld start
Starting MySQL...... ERROR! The server quit without updating PID file (/usr/local/mysql/mysqld.pid).
[root@test-a mysql]# chown mysql:mysql -R .
[root@test-a mysql]#
[root@test-a mysql]# /etc/init.d/mysqld start
Starting MySQL.. SUCCESS!
#設置開機啓動
[root@test-a mysql]# chkconfig --add mysqld
[root@test-a mysql]# chkconfig mysqld on
PHP安裝
[root@test-a mysql]# cd /usr/local/src/php-5.6.32/
[root@test-a php-5.6.32]# make clean # 刪除以前編譯過的文件
find . -name \*.gcno -o -name \*.gcda | xargs rm -f
find . -name \*.lo -o -name \*.o | xargs rm -f
find . -name \*.la -o -name \*.a | xargs rm -f
find . -name \*.so | xargs rm -f
find . -name .libs -a -type d|xargs rm -rf
rm -f libphp5.la sapi/cli/php sapi/cgi/php-cgi libphp5.la modules/* libs/*
[root@test-a php-5.6.32]# ./configure --prefix=/usr/local/php-fpm --with-config-file-path=/usr/local/php-fpm/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-pdo-mysql=/usr/local/mysql --with-mysql-sock=/tmp/mysql.sock --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --with-pear --with-curl --with-openssl
...
checking whether to enable ctype functions... yes
checking for cURL support... yes
checking for cURL in default path... not found
configure: error: Please reinstall the libcurl distribution -
easy.h should be in <curl-dir>/include/curl/
# 報錯,安裝curl
[root@test-a php-5.6.32]# yum install -y libcurl-devel
# 再次初始化
[root@test-a php-5.6.32]# ./configure --prefix=/usr/local/php-fpm --with-config-file-path=/usr/local/php-fpm/etc --enable-fpm --with-fpm-user=php-fpm --with-fpm-group=php-fpm --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-pdo-mysql=/usr/local/mysql --with-mysql-sock=/tmp/mysql.sock --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-ftp --enable-mbstring --enable-exif --with-pear --with-curl --with-openssl
...
Thank you for using PHP.
config.status: creating php5.spec
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating sapi/fpm/php-fpm.conf
config.status: creating sapi/fpm/init.d.php-fpm
config.status: creating sapi/fpm/php-fpm.service
config.status: creating sapi/fpm/php-fpm.8
config.status: creating sapi/fpm/status.html
config.status: creating sapi/cgi/php-cgi.1
config.status: creating ext/phar/phar.1
config.status: creating ext/phar/phar.phar.1
config.status: creating main/php_config.h
config.status: executing default commands
# 編譯安裝
[root@test-a php-5.6.32]# make && make install
...
[PEAR] XML_Util - installed: 1.4.2
[PEAR] PEAR - installed: 1.10.5
Wrote PEAR system config file at: /usr/local/php-fpm/etc/pear.conf
You may want to add: /usr/local/php-fpm/lib/php to your php.ini include_path
/usr/local/src/php-5.6.32/build/shtool install -c ext/phar/phar.phar /usr/local/php-fpm/bin
ln -s -f phar.phar /usr/local/php-fpm/bin/phar
Installing PDO headers: /usr/local/php-fpm/include/php/ext/pdo/
[root@test-a php-5.6.32]# ls /usr/local/php-fpm/
bin etc include lib php sbin var
[root@test-a php-5.6.32]# ls /usr/local/php
bin etc include lib php
# php-fpm的選項和php差很少,有-i,-m等,多了-t來檢查配置語法
[root@test-a php-5.6.32]# /usr/local/php-fpm/sbin/php-fpm -t
[25-Nov-2018 16:45:09] ERROR: failed to open configuration file '/usr/local/php-fpm/etc/php-fpm.conf': No such file or directory (2)
[25-Nov-2018 16:45:09] ERROR: failed to load configuration file '/usr/local/php-fpm/etc/php-fpm.conf'
[25-Nov-2018 16:45:09] ERROR: FPM initialization failed
[root@test-a php-5.6.32]# cd /usr/local/php-fpm/etc/
[root@test-a etc]# cp /usr/local/src/php-5.6.32/php.ini-production ./php.ini # 拷貝配置文件php.ini
[root@test-a etc]# vim php-fpm.conf # 建立php-fpm.conf配置文件,添加以下內容
[global] # 全局配置
pid = /usr/local/php-fpm/var/run/php-fpm.pid
error_log = /usr/local/php-fpm/var/log/php-fpm.log
[www] #模塊名
listen = /tmp/php-fcgi.sock #socket監聽
# listen = 127.0.0.1:9000 # tcp監聽
listen.mode = 666 # /tmp/php-fcgi.sock文件權限
user = php-fpm
group = php-fpm
pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500
rlimit_files = 1024
# 拷貝啓動腳本
[root@test-a etc]# cp /usr/local/src/php-5.6.32/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
[root@test-a etc]# chmod 755 /etc/init.d/php-fpm
[root@test-a etc]# chkconfig --add php-fpm
[root@test-a etc]# chkconfig php-fpm on
[root@test-a etc]# useradd -s /sbin/nologin php-fpm # 建立不能登陸的php-fpm用戶
root@test-a etc]# service php-fpm start
Starting php-fpm done
[root@test-a etc]# ps -aux|grep php-fpm
root 54315 1.0 0.4 124564 4880 ? Ss 17:06 0:00 php-fpm: master process (/usr/local/php-fpm/etc/php-fpm.conf)
php-fpm 54316 0.0 0.4 124564 4644 ? S 17:06 0:00 php-fpm: pool www
php-fpm 54317 0.0 0.4 124564 4644 ? S 17:06 0:00 php-fpm: pool www
php-fpm 54318 0.0 0.4 124564 4644 ? S 17:06 0:00 php-fpm: pool www
php-fpm 54319 0.0 0.4 124564 4644 ? S 17:06 0:00 php-fpm: pool www
php-fpm 54320 0.0 0.4 124564 4648 ? S 17:06 0:00 php-fpm: pool www
php-fpm 54321 0.0 0.4 124564 4652 ? S 17:06 0:00 php-fpm: pool www
php-fpm 54322 0.0 0.4 124564 4652 ? S 17:06 0:00 php-fpm: pool www
php-fpm 54323 0.0 0.4 124564 4652 ? S 17:06 0:00 php-fpm: pool www
php-fpm 54324 0.0 0.4 124564 4652 ? S 17:06 0:00 php-fpm: pool www
php-fpm 54325 0.0 0.4 124564 4652 ? S 17:06 0:00 php-fpm: pool www
php-fpm 54326 0.0 0.4 124564 4652 ? S 17:06 0:00 php-fpm: pool www
php-fpm 54327 0.0 0.4 124564 4652 ? S 17:06 0:00 php-fpm: pool www
php-fpm 54328 0.0 0.4 124564 4652 ? S 17:06 0:00 php-fpm: pool www
php-fpm 54329 0.0 0.4 124564 4652 ? S 17:06 0:00 php-fpm: pool www
php-fpm 54330 0.0 0.4 124564 4652 ? S 17:06 0:00 php-fpm: pool www
php-fpm 54331 0.0 0.4 124564 4652 ? S 17:06 0:00 php-fpm: pool www
php-fpm 54332 0.0 0.4 124564 4652 ? S 17:06 0:00 php-fpm: pool www
php-fpm 54333 0.0 0.4 124564 4652 ? S 17:06 0:00 php-fpm: pool www
php-fpm 54334 0.0 0.4 124564 4652 ? S 17:06 0:00 php-fpm: pool www
php-fpm 54335 0.0 0.4 124564 4652 ? S 17:06 0:00 php-fpm: pool www
Nginx 介紹
- Nginx官網 nginx.org
- Nginx應用場景:web服務、反向代理、負載均衡
- Nginx著名分支,淘寶基於Nginx開發的Tengine,使用上和Nginx一致,服務名,配置文件名都同樣,和Nginx的最大區別在於Tenging增長了一些定製化模塊,在安全限速方面表現突出,另外它支持對js,css合併
- Nginx核心+lua相關的組件和模塊組成了一個支持lua的高性能web容器openresty,參考 http://jinnianshilongnian.iteye.com/blog/2280928