操作系统:centos 7.5
做事器IP:192.168.10.5
运行用户:root
连接工具:xshell工具
web环境:Linux+apache+php+mariadb(LAMP架构)
大型动态运用系统平台紧张是针对付大流量、高并发网站建立的底层系统架构。大型网站的运行须要一个可靠、安全、可扩展、易掩护的运用系统平台做为支撑,以担保网站运用的平稳运行。这些东西都须要依赖web做事器来支撑,里面运用到的技能有单节点web做事器系统、负载均衡系统、数据集群系统、缓存系统、分布式存储系统、分布式做事器管理系统、代码发布系统等,现在企业一样平常都盛行利用自动化系统支配,可以把web业务全部跑在docker容器中,简化了运维配置流程,下面我们大略的先容下web做事器单节点的支配及利用。
本文属于原创,比较适宜企业运用,详细详细的先容可以参考《Linux就该这么学》里边教程的第20章,里面详细的先容了LNMP架构,而我这里是先容LAMP架构,LAMP、LNMP在企业都运用比较广泛,一样平常大型企业网站都会在Linux做事器上面跑,节约资源、提高web做事器性能及安全性。
单节点web做事器
通过系统自带的yum源安装,也可以通过本地镜像配置本地yum源,还可以通过rpm包或者tar.gz源码包编译后再安装;通过yum安装是比较方便的,安装过程会自动把依赖包自动安装上去;通过rpm包安装过程中须要根据提示探求依赖包,这种安装办法比较麻烦;下面我们来通过yum源安装办法来演示给大家看。
apache是一款开源的web做事器,它可以运行在险些所有广泛利用的打算机平台上,由于其跨平台和安全性被广泛利用,是最盛行的Web做事器端软件之最,apache在企业运用也是比较广泛的。特殊是结合Linux操作系统发挥最优的性能。
1、install apache
# yum install httpd.x86_64 httpd-devel.x86_64 -y //安装apache
# rpm -qa httpd //查看apache是否安装成功
# 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/
apache默认web路径:/var/www/html ,默认里面是空目录
PHP 是一种创建动态交互性站点的强有力的做事器端脚本措辞;PHP 是开源的,并且利用非常广泛;同时,对付像微软 asp、asp.net做事器脚本措辞竞争者来说,PHP 无疑是另一种高效率的选项,PHP有点:开源性、处理快、易上手、跨平台,效率高、适用于大型网站架构,一样平常PHP都是结合Linux apache nginx mysql;iis+php极少,配置繁芜、性能差。下面就大略先容下php的安装及配置。
2、install 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
# rpm -qa php //查看安装的PHP模块
# php -v //查看php版本
# ll /etc/php.ini //php默认配置文件,配置文件里面详细参数这里就不一一先容了。
MySQL最初也是开源的,后来被Oracle公司收购后5.5后的版本开始收费了,后来又有了MariaDB数据库,MariaDB数据库管理系统是MySQL的一个分支,紧张由开源社区在掩护,采取GPL授权容许 MariaDB的目的是完备兼容MySQL,包括API和命令行,使之能轻松成为MySQL的代替品,MariaDB开源、跨平台、性能强、易扩展、运用广。
3、install mariadb
# yum install mariadb.x86_64 mariadb-server.x86_64 mariadb-devel.x86_64 -y
# rpm -qa mariadb //查看mariadb是否安装成功
# 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 //连接数据库
4、test web service,apache + php +mariadb安装启动做事后就开始测试。
4.1、通过浏览器访问web做事器涌现如下解密解释apache安装成功。
http://192.168.10.5
4.2、测试apache+php
# vim /var/www/html/index.php
<?php
phpinfo();
?>
http://192.168.10.5/index.php
4.3、测试apache+php+mariadb
# vim /var/www/html/mysqld.php
<?php
$servername = \"大众localhost\"大众;
$username = \"大众root\"大众;
$password = \公众password\公众;
// 创建连接
$conn = new mysqli($servername, $username, $password);
// 检测连接
if ($conn->connect_error) {
die(\"大众连接失落败: \"大众 . $conn->connect_error);
}
echo \公众连接成功\"大众;
?>
http://192.168.10.5/mysqld.php