【Linux云计算架构:第二阶段-Linux必会的20多种服务】第10章——-Mysql初步认实和搭建LAMP环境部署Ucenter和Ucenter-home网站

学习一个服务的过程:

1、 此服务器的概述:名字,功能,特点,端口号 
2、 安装 
3、 配置文件的位置 
4、 服务启动关闭脚本,查看端口 
5、 此服务的使用方法 
6、 修改配置文件 
7、 排错(从下到上,从内到外) 

本节所讲内容:
• Mysql服务器常见概念
• Mysql服务器安装及相关配置文件
• 实战:安装mysql数据库并去除安全隐患
• 实战:搭建LAMP环境部署Ucenter和Ucenter-home网站

服务端:xuegod68.cn   IP:10.10.10..68

MySQL服务概述:

MySQL是一个关系型数据库管理系统,由瑞典MySQL AB公司开发,目前属于Oracle公司。
MySQL是最流行的关系型数据库管理系统,在WEB应用方面MySQL是最好的RDBMS(Relational Database Management System:关系数据库管理系统)应用软件之一。

MySQL是一种关联数据库管理系统,关联数据库将数据保存在丌同的表中,而不是将所有数据放在一个大仓库内,这样就增加了速度并提高了灵活性。

MySQL所使用的SQL语言是用于访问数据库最常用标准化语言。MySQL软件采用了双授权政策,它分为社区版和商业版,由于其体积小、速度快、总体拥有成本低,尤其是开放源码这一特点,一般中小型网站的开发都选择MySQL作为网站数据库。由于其社区版的性能卓越,搭配PHP和Apache可组成良好的开发环境。

双授权政策:开放源代码版本和商业版本。
例如:很多公司出售应用软件,例如Microsoft、Apple和Oracle;
如Red Hat和IBM,则通过为其开放源代码软件提供销售支援、托管戒咨询等服务来进行赚钱。但鲜为人知的是,企业可以透过开放源代码发布仕们的软件,也可以同时销售该软件的商业版本。

LAMP架构:

Linux+Apache+Mysql+PHP

官方网站:
http://www.mysql.com/
http://dev.mysql.com/downloads/mysql/
CentOS 7.0中,已经使用MariaDB替代了MySQL数据库,原因你懂的,MYSQL被Oracle收购以后,前景堪忧,所以MYSQL兄弟MariaDB就出来了,继续开源事业。

以rpm包的方式安装LAMP。
一、安装需要的软件包

[root@xuegod68 ~]#yum -y install httpd mariadb-server mariadb php php-mysql

centos6.5执行以下

[root@xuegod68 ~]# yum install httpd mysql-server mysql php php-mysql -y 

httpd    # web服务器 
mariadb-server  #mysql数据库 
mariadb     # mysql服务器linux下客户端 
php    #php相关文件 
php-mysql  #???          #php程序连接mysql使用的模块

查看php-mysql包作用:

[root@xuegod68 Packages]# rpm -pqi php-mysql-5.4.16-42.el7.x86_64.rpm
Name        : php-mysql
Version     : 5.4.16
Release     : 42.el7
Architecture: x86_64
Install Date: (not installed)
Group       : Development/Languages
Size        : 237331
License     : PHP
Signature   : RSA/SHA256, 2016年11月21日 星期一 04时04分05秒, Key ID 24c6a8a7f4a80eb5
Source RPM  : php-5.4.16-42.el7.src.rpm
Build Date  : 2016年11月06日 星期日 08时38分25秒
Build Host  : worker1.bsys.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem <http://bugs.centos.org>
Vendor      : CentOS
URL         : http://www.php.net/
Summary : A module for PHP applications that use MySQL databases 百度翻译一下

查看某个命令由哪个包安装:

[root@xuegod68 ~]# rpm -qf `which mysql`

查看apache版本:

[root@xuegod68 ~]# httpd -v 

查看mysql数据版客户端版本:

[root@xuegod68 ~]# mysql –V

启动服务LAMP相关服务:

[root@xuegod68 ~]# systemctl start  httpd
[root@xuegod68 ~]# systemctl enable  httpd

[root@xuegod68 ~]# systemctl start  mariadb 
[root@xuegod68 ~]# systemctl enable  mariadb 
[root@xuegod68 ~]#systemctl status  mariadb

测试数据库连接:

连接mysql数据库,连接本机可以去掉-h 
#mysql 
或: 
# mysql -h IP -u USER -pPASS 

Mysql的超级管理员是root拥有最mysql数据库的最高权限。 
例: 
# mysql -u root –p123456 –h 10.10.10.68
mysql> exit;   #退出mysql

MySQL安全配置向导

安装完mysql-server 会提示可以运行mysql_secure_installation。运行mysql_secure_installation会执行几个设置:

  a)为root用户设置密码
  b)删除匿名账号
  c)取消root用户远程登录
  d)删除test库和对test库的访问权限
  e)刷新授权表使修改生效

通过这几项的设置能够提高mysql库的安全。建议生产环境中mysql安装这完成后一定要运行一次。

mysql_secure_installation,详细步骤请参看下面的命令:

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, 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 MySQL
root user without the proper authorisation.
Set root password? [Y/n] <– 是否设置root用户密码, 刚才我已设置密码,我们输n
... skipping
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL 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
… 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] <–是否禁止root远程登录,根据自己的需求选择Y/n并回车,建议禁止
… Success!
By default, MySQL 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] <– 是否删除test数据库,直接回车或Y
- Dropping test database…
… Success!
- Removing privileges on test database…
… Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] <– 是否重新加载权限表,直接回车
… Success!
Cleaning up…
All done! If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!

如果不做安全配置root密码 :

[root@xuegod64 ~]# mysqladmin -u root password "654321" 

测试:登录mysql

[root@xuegod68 kaixin]# mysql -u root -p 

或:

[root@xuegod68 kaixin]# mysql -u root -p123456

测试:

[root@xuegod68 ~]# mysql -u root -p123456 

mysql> show databases; #没有test数据库 #执行时,所有命令以;号结尾 
+--------------------+ 
| Database | 
+--------------------+ 
| information_schema | 
| mysql | 
| ucenter | 
+--------------------+ 
3 rows in set (0.00 sec) 
mysql> exit #退出命令可以加分号,也可以不加分号。

测试网站是否支持PHP :

[root@xuegod68  html]# cd /var/www/html/ 
[root@xuegod68  html]# vim index.php 
[root@xuegod68  html]# vim index.php 
<?php 
phpinfo(); 
?> 

测试:

[root@xuegod68 html]# systemctl restart httpd 重启web
http://10.10.10.68/index.php

在这里插入图片描述

搭建LAMP环境部署Ucenter和Ucenter-home网站,搭建一个类人人网的社交网站:www.renren.com
在这里插入图片描述

http://faq.comsenz.com/viewtopic/noviceguide/tab/prepare
UCenter 用户中心,实现用户的统一登录登出,积分的兑换,TAG的互通等,在安装UCenter Home、Discuz!、SupeSite、X-Space 等应用前必须先安装UCenter。本教程讲解的即是如何全新安装UCenter 1.5.0。

http://www.discuz.net
Discuz! 论坛:
百万站长的选择,定会给您带来非凡的论坛体验。Discuz! 7.0.0 的推出使Discuz! 的用户体验又上升到了一个新的高度。本教程讲解的即是如何全新安装Discuz! 7.0.0 FULL(集成了UCenter 安装的版本)。
UCenter Home 个人家园,给社区中的会员一个可以安家的地方,在这里会员可以交朋友,写记录,发日志,贴照片,玩游戏…使会员可以牢牢的黏在你的社区里。本教程讲解的即是如何全新安装UCenter Home 1.5。
SupeSite 社区门户,实现CMS 的功能,拥有强大的模型功能,对Discuz! 和UCenter Home 的完美聚合,是您将社区中所有信息进行整合展示的最佳平台。本教程讲解的即是如何全新安装SupeSite 7.0。
上传
在这里插入图片描述
到服务器上/root目录下:

[root@xuegod68 ~]# unzip -d ./ucenter UCenter_1.5.0_SC_UTF8.zip # 解压缩到./ucenter 
[root@xuegod68 ~]# cd ./ucenter 
[root@xuegod68 ucenter]# ls 
advanced readme upload utilities 
[root@xuegod68 ~]#mkdir /var/www/html/ucadmin   #创建目录
[root@xuegod68 ucenter]# mv upload/ /var/www/html/ucadmin 
[root@xuegod68 ucenter]# cd /var/www/html/ucadmin 
[root@xuegod68 ucadmin]# ls 
admin.php control images js plugin upgrade 
api crossdomain.xml index.php lib release view 
avatar.php data install model robots.txt 
# robots.txt 网站根目录下,robots.txt 文件作用。 

Robots协议(也称为爬虫协议、机器人协议等)全称是“网络爬虫排除标准”(Robots Exclusion Protocol),网站通过Robots协议告诉搜索引擎哪些页面可以抓取,哪些页面不能抓取。
robots.txt文件是一个文本文件,使用任何一个常见的文本编辑器,比如Windows系统自带的Notepad,就可以创建和编辑它[1] 。robots.txt是一个协议,而不是一个命令。robots.txt是搜索引擎中访问网站的时候要查看的第一个文件。robots.txt文件告诉蜘蛛程序在服务器上什么文件是可以被查看的。

但robots.txt不是命令,也不是防火墙,如同守门人无法阻止窃贼等恶意闯入者。

修改文件权限:

[root@xuegod68 ucadmin]# ls -ld data 
drwxrwxrwx 8 root root 4096 2009-01-22 data 
[root@xuegod68 html]# ps -aux | grep httpd 
Warning: bad syntax, perhaps a bogus '-'? See /usr/share/doc/procps-3.2.8/FAQ 
root 3736 0.0 0.7 260340 9040 ? Ss 20:06 0:00 /usr/sbin/httpd 
apache 3741 0.0 0.6 260492 7412 ? S 20:06 0:00 /usr/sbin/httpd 
apache 3742 0.0 0.5 260340 6296 ? S 20:06 0:00 /usr/sbin/httpd

[root@xuegod68 html]# id apache 
uid=48(apache) gid=48(apache) groups=48(apache) 
[root@xuegod68 ucadmin]# chown apache:apache data/ -R 

或:

[root@xuegod68 ucadmin]# chmod -R 777 data # 
# 为安全正确做法应该是chown –R apache:apache data。后面安装好后测试。

安装网站模版:
安装UCenter:
打开:http://10.10.10.68/ucadmin/install/
在这里插入图片描述

要安这个打开:

[root@xuegod68 ~]# vim /etc/php.ini #php运用程序的配置文件 
改:229 short_open_tag = Off
为:230 short_open_tag = On	# 开启PHP短标签功能:

决定是否允许使用,代码开始标志的缩写形式(<? 。。。?>)
PHP 代码开始标志的完整形式为:<?php。。。?>

重新加载配置文件:

[root@xuegod68 ~]# service httpd restart 
Stopping httpd: [ OK ] 
Starting httpd: [ OK ]

测试:http:// 10.10.10.68/ucadmin/install/
在这里插入图片描述

需要这个data目录可写:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

注:这个注册码很不清楚,多按F5刷新几次就可以了
要记录创始人用户名:UCenter Administrator 密码:123456
创建一个用户和密码。用于管理UCenter Home

创建一个用户和密码:
在这里插入图片描述

第二步: 安装UCenter_Home_

[root@xuegod68 ~]# unzip -d ./ucenter_home UCenter_Home_2.0_SC_UTF8.zip 
[root@xuegod68 ~]# cd ucenter_home 
[root@xuegod68 uchome]# ls 
2.0_changelog.txt readme.txt update upload 

[root@xuegod68 uchome]# mv upload/* /var/www/html/   #拷贝过去也行
[root@xuegod68 uchome]# cd /var/www/html/
[root@xuegod68 html]# ls 
admin cp.php index.php network.php userapp.php 
admincp.php crossdomain.xml install rss.php ver.php 
api data invite.php source xmlrpc.php 
app.php do.php js.php space.php 
attachment editor.php language template 
common.php help.php link.php theme 
config.new.php image magic.php uc_client 
[root@xuegod68 html]# cp config.new.php config.php 
[root@xuegod68 html]# chown apache:apache config.php 
[root@xuegod68 html]# chown apache:apache  attachment/  data/  uc_client/ -R

然后打开连接 安装http://10.10.10.68/install

填写相关连接:
UCenter 的URL:http:// 10.10.10.68/ucadmin
UCenter创始人密码:123456
在这里插入图片描述
在这里插入图片描述

配置httpd虚拟主机:

vim /etc/httpd/conf.d/vhost.conf 添加两个基于域名的虚拟主机。 

第一个:

<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /var/www/html/ucadmin
ServerName admin.xuegod68.cn
</VirtualHost>

第二个:

<VirtualHost *:80>
ServerAdmin webmaster@dummy-host.example.com
DocumentRoot /var/www/html/
ServerName www.xuegod68.cn
</VirtualHost>

修改windows主机的host文件 指向域名

# localhost name resolution is handled within DNS itself.
#	127.0.0.1       localhost
#	::1             localhost
10.10.10.68	www.xuegod68.cn
10.10.10.68	admin.xuegod68.cn
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值