LNMP的部署

一、

LNMP代表的就是:Linux系统下Nginx+MySQL+PHP这种网站服务器架构。

Linux是一类Unix计算机操作系统的统称,是目前最流行的免费操作系统。代表版本有:debian、centos、ubuntu、fedora、gentoo等。

Nginx是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器。

Mysql是一个小型关系型数据库管理系统。

PHP是一种在服务器端执行的嵌入HTML文档的脚本语言。

这四种软件均为免费开源软件,组合到一起,成为一个免费、高效、扩展性强的网站服务系统。
 

二、安装

1.安装nginx

在这个链接里nginx的安装

2.安装mysql

在这个链接里mysql的安装

3.安装php

yum -y install php
yum -y install php-fpm
yum -y install php-devel

三、部署

1.启动nginx服务

1.ln -s /usr/local/nginx/sbin/nginx /sbin/  先创一个软连接到系统sbin里
2.nginx

2.启动mysql和php服务

systemctl restart mysql
systemctl restart php-fpm

3.修改nginx配置

vim /usr/local/nginx/conf/nginx.conf

65         location ~ \.php$ {
 66             root           html;
 67             fastcgi_pass   127.0.0.1:9000;
 68             fastcgi_index  index.php;
 69         #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;    //把这一行注释
 70             include        fastcgi.conf;                                      //把后缀改为.conf
 71         }

4.修改完nginx.conf,需要让nginx重新读取配置文件(重启服务)

 [root@localhost html]# nginx -s stop

 [root@localhost html]# nginx

5.把项目写在nginx文件里html里

 vi  /usr/local/nginx/html/mysql.php ##这里项目名就叫mysql.php

这边没有项目直接就随便写了点

6.再重新运行nginx

 [root@localhost html]# nginx -s stop

 [root@localhost html]# nginx

7.文件里的数据就能看到了

 注意如果数据没出来可能是防火墙的原因

Centos7如果是以上情况请看防火墙配置
centos7默认使用firewall
1.查看防火墙是否开启:systemctl status firewalld

2.开启防火墙:systemctl start firewalld.service

   如果出现Failed to start firewalld.service: Unit is masked的错误,说明firewalld服务被锁定了
可执行:systemctl unmask firewalld解除锁定

3.查看防火墙监听的端口号:firewall-cmd --list-ports

4.防火墙开启80端口访问:firewall-cmd --zone=public --add-port=80/tcp --permanent

5.重启防火墙:firewall-cmd --reload

防火墙相关命令:
    开启开机启动:systemctl enable firewalld.service
    关闭开机自启动:systemctl disable firewalld.service
    查看防火墙状态:firewall-cmd --state

    停止firewall:systemctl stop firewalld 
    禁用firewall:systemctl mask firewalld
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Ansible角色是Ansible中的一种组织方式,它是一组任务、变量、文件和模板的集合,用于实现某个特定功能。在这个问题中,我们可以使用Ansible角色来部署LNMPLinuxNginx、MySQL和PHP)堆栈。 以下是一个简单的LNMP Ansible角色部署示例: 1. 创建一个名为“lnmp”的Ansible角色目录: ``` mkdir roles/lnmp ``` 2. 在lnmp目录中创建一个tasks目录: ``` mkdir roles/lnmp/tasks ``` 3. 在tasks目录中创建一个main.yml文件,其中包含以下任务: ``` - name: Install Nginx yum: name: nginx state: present - name: Start Nginx service service: name: nginx state: started - name: Install MySQL yum: name: mysql-server state: present - name: Start MySQL service service: name: mysqld state: started - name: Install PHP yum: name: php state: present - name: Install PHP-FPM yum: name: php-fpm state: present - name: Start PHP-FPM service service: name: php-fpm state: started ``` 这些任务将安装和启动Nginx、MySQL和PHP-FPM服务。 4. 在lnmp目录中创建一个vars目录: ``` mkdir roles/lnmp/vars ``` 5. 在vars目录中创建一个main.yml文件,其中包含以下变量: ``` --- nginx_conf_file: /etc/nginx/nginx.conf mysql_root_password: mysecretpassword php_conf_dir: /etc/php.d/ ``` 这些变量将用于配置Nginx、MySQL和PHP的设置。 6. 在lnmp目录中创建一个templates目录: ``` mkdir roles/lnmp/templates ``` 7. 在templates目录中创建一个nginx.conf.j2模板文件: ``` worker_processes 1; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; server { listen 80; server_name localhost; location / { root /var/www/html; index index.php index.html index.htm; } location ~ \.php$ { root /var/www/html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } } ``` 这个模板将用于生成Nginx的配置文件。 8. 在tasks目录中创建一个configure.yml文件,其中包括以下任务: ``` - name: Copy Nginx configuration file template: src: nginx.conf.j2 dest: "{{ nginx_conf_file }}" mode: '0644' - name: Set MySQL root password mysql_user: name: root password: "{{ mysql_root_password }}" login_unix_socket: /var/lib/mysql/mysql.sock - name: Copy PHP configuration file copy: src: php.ini dest: "{{ php_conf_dir }}" mode: '0644' ``` 这些任务将生成Nginx配置文件、设置MySQL root密码和复制PHP配置文件。 9. 在lnmp目录中创建一个files目录: ``` mkdir roles/lnmp/files ``` 10. 在files目录中创建php.ini文件: ``` memory_limit = 128M upload_max_filesize = 64M post_max_size = 64M ``` 这个文件将被复制到PHP配置目录中。 11. 在lnmp目录中创建一个meta目录: ``` mkdir roles/lnmp/meta ``` 12. 在meta目录中创建一个main.yml文件,其中包含以下元数据: ``` --- dependencies: - { role: geerlingguy.repo-epel } - { role: geerlingguy.mysql } ``` 这些元数据将指定依赖项,以便安装EPEL存储库和MySQL角色。 13. 在playbook中使用lnmp角色: ``` - hosts: webserver become: true roles: - lnmp ``` 这个playbook将在webserver主机上使用lnmp角色。 这就是一个简单的LNMP Ansible角色部署示例。当然,还有很多其他的配置选项和任务可以添加到这个角色中,以满足不同的需求。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值