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
来源:oschina
链接:https://my.oschina.net/u/996931/blog/2960660