VMware的CentOS部署环境
1. 配置CentOS 7的防火墙
- CentOS 7 默认使用的防火墙是firewall,开启TCP端口80:
[root@localhost ~]# firewall-cmd --zone=public --add-port=80/tcp --permanent
- 重新启动防火墙让更改立刻生效:
[root@localhost ~]# firewall-cmd --reload
- 检查端口是否开放:
[root@localhost ~]# firewall-cmd --list-all
- 查看firewall服务状态:
[root@localhost ~]# firewall-cmd --state
补充:
systemctl --failed
:检查加载失败的服务systemctl status network
:查看网络服务状态systemctl stop firewalld.service
: 关闭firewalld防火墙systemctl disable firewalld.service
: 禁止firewalld开机启动systemctl start firewalld.service
: 开启firewalld防火墙systemctl restart firewalld.service
: 重启firewalld防火墙
2.使用links来浏览网站###
- 安装links工具:
yum install links
安装过程中,遇到选项,一路y
即可。
如:links localhost 或者 links www.baidu.com
3.安装Apache HTTP服务器###
- 安装 Apache HTTP
# yum install httpd
-
允许HTTP服务通过防火墙
# firewall-cmd --add-service=http
-
永久添加HTTP服务配置
# firewall-cmd --add-service=http --permanent
-
重新加载防火墙
# firewall-cmd --reload
-
重启Apache HTTP服务器
# systemctl restart httpd.service
将Apache服务添加到系统,随系统自动启动
# systemctl start httpd.service
# systemctl enable httpd.service
-
通过links 命令验证Apache HTTP 服务器
# links 127.0.0.1
Ctrl+z
退出界面
4.安装mysql###
[root@localhost ~]# yum install mysql-server
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* hase: mirrors.sina.cn
* extras: mirrors.sina.cn
* updates: mirrors.sina.cn
No package mysql-server available.
Error: Nothing to do
经查CentOS 7 版本将MySQL数据库软件从默认的程序列表中移除,用mariadb代替了。
MariaDB 是 MySQL 的一个分支。RHEL 以及它的衍生版已经从 MySQL 迁移到 MariaDB。这是一个主流的数据库管理系统。在最小化安装的 CentOS 上安装 MariaDB,如下所示:
[root@localhost ~]# yum install mariadb-server mariadb
mariadb数据库的相关命令是:
systemctl start mariadb
#启动MariaDB
systemctl stop mariadb
#停止MariaDB
systemctl restart mariadb
#重启MariaDB
systemctl enable mariadb
#设置开机启动
所以先启动数据库
[root@localhost ~]# systemctl start mariadb
然后就可以正常使用mysql了
[root@localhost ~]# mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.41-MariaDB MariaDB Server
Copyright (c) 2000, 2014, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
+--------------------+
4 rows in set (0.00 sec)
MariaDB [(none)]>
-
下载mysql进行安装
wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
rpm -ivh mysql-community-release-el7-5.noarch.rpm
yum install mysql-community-server
安装成功后重启mysql服务。
# service mysqld restart
初次安装mysql,root账户没有密码。
[root@yl-web yl]# mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.6.37 MySQL Community Server (GPL)
Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
+--------------------+
3 rows in set (0.01 sec)
mysql>
设置密码
mysql> set password for 'root'@'localhost' =password('password');
Query OK, 0 rows affected (0.00 sec)
mysql>
不需要重启数据库即可生效。
查看mysql字符集配置:
mysql>show variables like 'character%'
mysql配置文件为/etc/my.cnf
最后加上编码配置
[mysqld]
character_set_server = utf8
字符编码必须和/usr/share/mysql/charsets/Index.xml
中保持一致。
把在所有数据库的所有表的所有权限赋值给位于所有IP地址的root用户。
mysql> grant all privileges on *.* to root@'%'identified by 'password';
如果不是root用户,则要先新建用户
mysql>create user 'username'@'%' identified by 'password';
查看安装的软件:
[root@localhost ~]# yum list installed | grep mysql
[root@localhost ~]# rpm -qa | grep -i mysql