Chinaunix首页 | 论坛 | 博客
  • 博客访问: 95673
  • 博文数量: 47
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 350
  • 用 户 组: 普通用户
  • 注册时间: 2018-03-07 16:33
文章分类

全部博文(47)

文章存档

2019年(19)

2018年(28)

我的朋友

分类: LINUX

2019-02-03 12:31:52

LAMP架构部署和动态网站环境的配置

实验环境:

操作系统:centos 7.5

服务器IP192.168.10.5

运行用户:root

连接工具:xshell工具

web环境:Linux+apache+php+mariadbLAMP架构)

 

大型动态应用系统平台主要是针对于大流量、高并发网站建立的底层系统架构。大型网站的运行需要一个可靠、安全、可扩展、易维护的应用系统平台做为支撑,以保证网站应用的平稳运行。这些东西都需要依靠web服务器来支撑,里面应用到的技术有单节点web服务器系统、负载均衡系统、数据集群系统、缓存系统、分布式存储系统、分布式服务器管理系统、代码发布系统等,现在企业一般都流行使用自动化系统部署,可以把web业务全部跑在docker容器中,简化了运维配置流程,下面我们简单的介绍下web服务器单节点的部署及使用。

 

本文属于原创,比较适合企业应用,具体详细的介绍可以参考里边教程的第20章,里面详细的介绍了LNMP架构,而我这里是介绍LAMP架构,LAMPLNMP在企业都应用比较广泛,一般大型企业网站都会在Linux服务器上面跑,节约资源、提高web服务器性能及安全性。

 

单节点web服务器

通过系统自带的yum源安装,也可以通过本地镜像配置本地yum源,还可以通过rpm包或者tar.gz源码包编译后再安装;通过yum安装是比较方便的,安装过程会自动把依赖包自动安装上去;通过rpm包安装过程中需要根据提示寻找依赖包,这种安装方式比较麻烦;下面我们来通过yum源安装方式来演示给大家看。

 

apache是一款开源的web服务器,它可以运行在几乎所有广泛使用的计算机平台上,由于其跨平台和安全性被广泛使用,是最流行的Web服务器端软件之最,apache在企业应用也是比较广泛的。特别是结合Linux操作系统发挥最优的性能。

 

1install apache

# yum install httpd.x86_64 httpd-devel.x86_64 -y  //安装apache

clipboard.png

# rpm -qa httpd   //查看apache是否安装成功

clipboard.png

# httpd -v    //查看apache版本

Server version: Apache/2.4.6 (CentOS)

Server built:   Jun 27 2018 13:48:59

# systemctl start httpd.service    //启动apache服务

# systemctl status httpd.service   //查看apache服务状态

# systemctl stop httpd.service    //停止apache服务

# systemctl enable httpd.service   //设置开机自动启动apache服务

apache默认配置文件路径:/etc/httpd/

clipboard.png

apache默认web路径:/var/www/html ,默认里面是空目录

clipboard.png

 

PHP 是一种创建动态交互性站点的强有力的服务器端脚本语言;PHP 是开源的,并且使用非常广泛;同时,对于像微软 aspasp.net服务器脚本语言竞争者来说,PHP 无疑是另一种高效率的选项,PHP有点:开源性、处理快、易上手、跨平台,效率高、适用于大型网站架构,一般PHP都是结合 apache nginx mysqliis+php极少,配置复杂、性能差。下面就简单介绍下php的安装及配置。

 

2install php

# yum install php php-common php-fpm php-gd php-soap php-json php-ldap php-mbstring php-mysqlnd php-mysqld php-xml php-xmlrpc php-opcache php-simplexml php-bcmath -y

clipboard.png

# rpm -qa php*  //查看安装的PHP模块

clipboard.png

# php -v   //查看php版本

clipboard.png

# ll /etc/php.ini    //php默认配置文件,配置文件里面详细参数这里就不一一介绍了。

clipboard.png

MySQL最初也是开源的,后来被Oracle公司收购后5.5后的版本开始收费了,后来又有了MariaDB数据库,MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可 MariaDB的目的是完全兼容MySQL,包括API和命令行,使之能轻松成为MySQL的代替品,MariaDB开源、跨平台、性能强、易扩展、应用广。

 

3install mariadb

# yum install mariadb.x86_64 mariadb-server.x86_64 mariadb-devel.x86_64 -y

clipboard.png

# rpm -qa mariadb  //查看mariadb是否安装成功

clipboard.png

# systemctl start mariadb.service   //启动数据库服务

# systemctl stop mariadb.service   //停止数据库服务

# systemctl status mariadb.service   //查看数据库服务状态

# systemctl enable mariadb.service  //设置开机自动启动数据库服务

mariadb安装后启动服务,数据库root用户是没有密码的,需要进行初始化并设置密码,配置如下:

 

# mysql_secure_installation

 

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB

      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

 

In order to log into MariaDB to secure it, we'll need the current

password for the root user.  If you've just installed MariaDB, and

you haven't set the root password yet, the password will be blank,

so you should just press enter here.

 

Enter current password for root (enter for none):   //直接回车

OK, successfully used password, moving on...

 

Setting the root password ensures that nobody can log into the MariaDB

root user without the proper authorisation.

 

Set root password? [Y/n] y   //y设置root用户密码

New password:      //输入密码

Re-enter new password:    //确定密码

Password updated successfully!

Reloading privilege tables..

 ... Success!

 

By default, a MariaDB installation has an anonymous user, allowing anyone

to log into MariaDB 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? [Y/n] y    //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? [Y/n] y   //y禁止root远程登录

 ... Success!

 

By default, MariaDB 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? [Y/n] n  //n不删除test数据库,根据自己需求定。

 ... skipping.

 

Reloading the privilege tables will ensure that all changes made so far

will take effect immediately.

 

Reload privilege tables now? [Y/n] y   //刷新数据表

 ... Success!

 

Cleaning up...

 

All done!  If you've completed all of the above steps, your MariaDB

installation should now be secure.

 

Thanks for using MariaDB!

 

# mysql -h 127.0.0.1 -u root -p   //连接数据库

clipboard.png

 

4test web serviceapache + php +mariadb安装启动服务后就开始测试。

4.1、通过浏览器访问web服务器出现如下解密说明apache安装成功。

clipboard.png

 

4.2、测试apache+php

# vim /var/www/html/index.php

        phpinfo();

?>

 

clipboard.png

 

4.3、测试apache+php+mariadb

# vim /var/www/html/mysqld.php

 

$servername = "localhost";

$username = "root";

$password = "password";

// 创建连接

$conn = new mysqli($servername, $username, $password);

// 检测连接

if ($conn->connect_error) {

die("连接失败: " . $conn->connect_error);

}

echo "连接成功";

?>

 

clipboard.png

阅读(1210) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~