LNMP架构 安装MySQL 、php、nginx
LNMP框架 -mysql安装
一、yum源安装相关工具
- #cd /usr/local/src
//软件包都放在这里方便管理
- [root@localhost src]#yum install -y lrzsz
//确定安装yum
二、上传并解压Mysql
- [root@localhost ~]# tar -zxvf mysql-5.6.47-linux-glibc2.12-x86_64.tar.gz
- [root@localhost ~]#mv mysql-5.6.47-linux-glibc2.12-x86_64.tar.gz /usr/local/src/
//把mysql放到根目录下面
- [root@localhost ~]# mv nginx-1.17.8.tar.gz /usr/local/src
//把nginx放到根目录下面 - [root@localhost ~]#mv
php-5.6.30.tar.gz /usr/local/src
//把php放到根目录下面
三、安装与配置
- [root@localhost ~]#cd /usr/local/src
- //进入根目录下面
[root@localhost src]# mkdir -p /data/mysql
//创建datadir,数据库文件会放到这里面
- [root@localhost src]# useradd -s /sbin/nologin mysql
- [root@localhost src]# chown -R mysql:mysql /data/mysql // 更改权限,不更改后续操作就会出问题
- [root@localhost src]# mv mysql-5.6.47-linux-glibc2.12-x86_64 /usr/local/mysql
// 挪动位置
- [root@localhost src]# yum install -y autoconf
- //安装依赖工具
[root@localhost mysql]# ./scripts/mysql_install_db --user=mysql --datadir=/data/mysql
//--user表示定义数据库的以哪个用户的身份运
//--datadir表示定义数据库的安装目录
-
[root@localhost mysql]# cp support-files/my-default.cnf /etc/my.cnf
cp: overwrite ‘/etc/my.cnf’? y - [root@localhost mysql]#cp support-files/mysql.server /etc/init.d/mysql
//复制启动脚本文件
9. [root@localhost mysql]#chmod 755 /etc/init.d/mysql
//修改启动脚本文件的属性
10.[root@localhost mysql]#vim /etc/init.d/mysql
//修改启动脚本
dasedir=/usr/local/mysql
datadir=/data/mysql
11.[root@localhost ~]# vim /etc/my.cnf
log_bin=crlinux1
# These are commonly set, remove the # and set as required.
basedir = /usr/local/mysql/
datadir = /data/mysql/
port = 3306
server_id = 21
socket = /tmp/mysql.sock
- [root@localhost mysql]#chkconfig --add mysql
//把mysql服务加到系统服务列表中
- [root@localhost mysql]#chkconfig mysql on
//开机启动
13.[root@localhost mysql]# service mysql start
//启动MySQL
LNMP框架 -PHP安装
一、 下载与解压
- #cd /usr/local/src
//软件包都放在这里方便管理
- #tar -zxvf php-5.6.30.tar.gz//解压
二、 安装与配置
安装依赖插件
- # yum install -y libxml2-devel
- # yum install -y openssl openssl-devel
- # yum install -y bzip2 bzip2-devel
- # yum install -y libpng libpng-devel
- # yum install -y freetype freetype-devel
- # yum install -y epel-release
- # yum install -y libmcrypt-devel
- #yum -y install libjpeg-devel
- #yum install -y libcurl-devel
- #yum install -y gcc//有可能会报错 安装gcc
- #useradd -s /sbin/nologin php-fpm
配置安装
- [root@localhost ~]# cd /usr/local/src/php-5.6.30
- [root@localhost php-5.6.30]# ./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-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 --disable-ipv6 --with-pear --with-curl --with-openssl
- #make j4 && make install (安装时间会很久,4通道稍快一点)
编辑配置文件
- [root@localhost php-5.6.30]# cp php.ini-production /usr/local/php-fpm/etc/php.ini
- [root@server php-5.6.39]# vim /usr/local/php-fpm/etc/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
- listen.mode = 666
- 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@localhost etc]# /usr/local/php-fpm/sbin/php-fpm -t
- [06-Sep-2021 17:43:00] NOTICE: configuration file /usr/local/php-fpm/etc/php-fpm.conf test is successful(代表成功)
- [root@localhost etc]# cd /usr/local/src/php-5.6.30
- [root@localhost php-5.6.30]# cp /usr/local/src/php-5.6.30/sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
- [root@localhost php-5.6.30]# chmod 755 /etc/init.d/php-fpm
启动php
- [root@localhost php-5.6.30]# service php-fpm start
- Starting php-fpm done
- [root@localhost php-5.6.30]# chkconfig php-fpm on
测试是否安装成功
- [root@localhost php-5.6.30]# ps aux |grep php-fpm
- root 111527 0.0 0.1 128200 5052 ? Ss 18:13 0:00 php-fpm: master process (/usr/local/php-fpm/etc/php-fpm.conf)
- php-fpm 111528 0.0 0.1 128200 4788 ? S 18:13 0:00 php-fpm: pool www
- php-fpm 111529 0.0 0.1 128200 4788 ? S 18:13 0:00 php-fpm: pool www
- php-fpm 111530 0.0 0.1 128200 4788 ? S 18:13 0:00 php-fpm: pool www
- php-fpm 111531 0.0 0.1 128200 4788 ? S 18:13 0:00 php-fpm: pool www
- php-fpm 111532 0.0 0.1 128200 4796 ? S 18:13 0:00 php-fpm: pool www
- php-fpm 111533 0.0 0.1 128200 4796 ? S 18:13 0:00 php-fpm: pool www
- php-fpm 111534 0.0 0.1 128200 4796 ? S 18:13 0:00 php-fpm: pool www
- php-fpm 111535 0.0 0.1 128200 4796 ? S 18:13 0:00 php-fpm: pool www
- php-fpm 111536 0.0 0.1 128200 4796 ? S 18:13 0:00 php-fpm: pool www
- php-fpm 111537 0.0 0.1 128200 4796 ? S 18:13 0:00 php-fpm: pool www
- php-fpm 111538 0.0 0.1 128200 4796 ? S 18:13 0:00 php-fpm: pool www
- php-fpm 111539 0.0 0.1 128200 4796 ? S 18:13 0:00 php-fpm: pool www
- php-fpm 111540 0.0 0.1 128200 4796 ? S 18:13 0:00 php-fpm: pool www
- php-fpm 111541 0.0 0.1 128200 4796 ? S 18:13 0:00 php-fpm: pool www
- php-fpm 111542 0.0 0.1 128200 4796 ? S 18:13 0:00 php-fpm: pool www
- php-fpm 111543 0.0 0.1 128200 4796 ? S 18:13 0:00 php-fpm: pool www
- php-fpm 111544 0.0 0.1 128200 4796 ? S 18:13 0:00 php-fpm: pool www
- php-fpm 111545 0.0 0.1 128200 4796 ? S 18:13 0:00 php-fpm: pool www
- php-fpm 111546 0.0 0.1 128200 4796 ? S 18:13 0:00 php-fpm: pool www
- php-fpm 111547 0.0 0.1 128200 4796 ? S 18:13 0:00 php-fpm: pool www
- root 111570 0.0 0.0 112812 976 pts/0 S+ 18:17 0:00 grep --color=auto php-fpm
LNMP框架 -Nginx安装
上传并解压Nginx
- [root@localhost src]# tar -zxvf nginx-1.17.8.tar.gz
- [root@localhost src]# cd nginx-1.17.8
安装配置
配置
- [root@localhost nginx-1.17.8]# ./configure --prefix=/usr/local/nginx
编译
- [root@localhost nginx-1.17.8]# make -j4 && make install
修改配置文件
[root@localhost nginx-1.17.8]# vi /etc/init.d/nginx
#!/bin/bash
# chkconfig: - 30 21
# description: http service.
# Source Function Library
. /etc/init.d/functions
# Nginx Settings
NGINX_SBIN="/usr/local/nginx/sbin/nginx"
NGINX_CONF="/usr/local/nginx/conf/nginx.conf"
NGINX_PID="/usr/local/nginx/logs/nginx.pid"
RETVAL=0
prog="Nginx"
start()
{
echo -n $"Starting $prog: "
mkdir -p /dev/shm/nginx_temp
daemon $NGINX_SBIN -c $NGINX_CONF
RETVAL=$?
echo
return $RETVAL
}
stop()
{
echo -n $"Stopping $prog: "
killproc -p $NGINX_PID $NGINX_SBIN -TERM
rm -rf /dev/shm/nginx_temp
RETVAL=$?
echo
return $RETVAL
}
reload()
{
echo -n $"Reloading $prog: "
killproc -p $NGINX_PID $NGINX_SBIN -HUP
RETVAL=$?
echo
return $RETVAL
}
restart()
{
stop
start
}
configtest()
{
$NGINX_SBIN -c $NGINX_CONF -t
return 0
}
case "$1" in
start)
start
;;
stop)
stop
;;
reload)
reload
;;
restart)
restart
;;
configtest)
configtest
;;
*)
echo $"Usage: $0 {start|stop|reload|restart|configtest}"
RETVAL=1
esac
exit $RETVAL
添加权限增加开机项
- [root@localhost nginx-1.17.8]# chmod 755 /etc/init.d/nginx
- [root@localhost nginx-1.17.8]# chkconfig --add nginx
- [root@localhost nginx-1.17.8]# chkconfig nginx on
- [root@localhost nginx-1.17.8]# > /usr/local/nginx/conf/nginx.conf
修改配置文件
1. [root@server nginx-1.17.8]# > /usr/local/nginx/conf/nginx.conf
2. [root@server nginx-1.17.8]# vim /usr/local/nginx/conf/nginx.conf //修改配置文件
3. user nobody nobody;
4. worker_processes 2;
5. error_log /usr/local/nginx/logs/nginx_error.log crit;
6. pid /usr/local/nginx/logs/nginx.pid;
7. worker_rlimit_nofile 51200;
8. events
9. {
10. use epoll;
11. worker_connections 6000;
12. }
13. http
14. {
15. include mime.types;
16. default_type application/octet-stream;
17. server_names_hash_bucket_size 3526;
18. server_names_hash_max_size 4096;
19. log_format combined_realip '$remote_addr $http_x_forwarded_for [$time_local]'
20. ' $host "$request_uri" $status'
21. ' "$http_referer" "$http_user_agent"';
22. sendfile on;
23. tcp_nopush on;
24. keepalive_timeout 30;
25. client_header_timeout 3m;
26. client_body_timeout 3m;
27. send_timeout 3m;
28. connection_pool_size 256;
29. client_header_buffer_size 1k;
30. large_client_header_buffers 8 4k;
31. request_pool_size 4k;
32. output_buffers 4 32k;
33. postpone_output 1460;
34. client_max_body_size 10m;
35. client_body_buffer_size 256k;
36. client_body_temp_path /usr/local/nginx/client_body_temp;
37. proxy_temp_path /usr/local/nginx/proxy_temp;
38. fastcgi_temp_path /usr/local/nginx/fastcgi_temp;
39. fastcgi_intercept_errors on;
40. tcp_nodelay on;
41. gzip on;
42. gzip_min_length 1k;
43. gzip_buffers 4 8k;
44. gzip_comp_level 5;
45. gzip_http_version 1.1;
46. gzip_types text/plain application/x-javascript text/css text/htm
47. application/xml;
48. server
49. {
50. listen 80;
51. server_name localhost;
52. index index.html index.htm index.php;
53. root /usr/local/nginx/html;
54. location ~ \.php$
55. {
56. include fastcgi_params;
57. fastcgi_pass unix:/tmp/php-fcgi.sock;
58. fastcgi_index index.php;
59. fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name;
60. }
61. }
62. }
检测是否成功
- [root@localhost nginx-1.17.8]# /usr/local/nginx/sbin/nginx -t
- nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
- nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
启动 Nginx
- [root@localhost nginx-1.17.8]# service nginx start
- Starting nginx (via systemctl): [ OK ]
- [root@localhost nginx-1.17.8]# ps aux |grep nginx
测试是否正确解析
[root@localhost nginx-1.17.8]#vi /usr/local/nginx/html/2.php
<?php
echo "test php scripts";
?>
[root@localhost nginx-1.17.8]#curl localhost/2.php
test php scripts //证明解析成功

浙公网安备 33010602011771号