针对CentOS7两步安装启动Mysql和mariadb这两个问题,本篇文章进行了详细的解答,同时本文还将给你拓展4.56-MariaDB的密码重置4.57MariaDB慢查询日志4.58Tomcat
针对CentOS 7 两步安装启动 Mysql和mariadb这两个问题,本篇文章进行了详细的解答,同时本文还将给你拓展4.56-MariaDB 的密码重置 4.57 MariaDB 慢查询日志 4.58 Tomcat_JDK 部署 4.59 zrlog 安装 4.60 Nginx 代理 Tomcat、CentOS 7 x64下Apache+MySQL(Mariadb)+PHP56的安装教程详解、CentOS 7.0 使用 yum 安装 MariaDB 与 MariaDB 的简单配置、CentOS 7.4 上搭建 LAMP(CentOS 7.4、httpd-2.4.6、MariaDB 5.5.56、PHP 5.4.16)等相关知识,希望可以帮助到你。
本文目录一览:- CentOS 7 两步安装启动 Mysql(mariadb)
- 4.56-MariaDB 的密码重置 4.57 MariaDB 慢查询日志 4.58 Tomcat_JDK 部署 4.59 zrlog 安装 4.60 Nginx 代理 Tomcat
- CentOS 7 x64下Apache+MySQL(Mariadb)+PHP56的安装教程详解
- CentOS 7.0 使用 yum 安装 MariaDB 与 MariaDB 的简单配置
- CentOS 7.4 上搭建 LAMP(CentOS 7.4、httpd-2.4.6、MariaDB 5.5.56、PHP 5.4.16)
CentOS 7 两步安装启动 Mysql(mariadb)
注意:Mariadb=Mysql(Mariadb 是 Mysql 的分支)
可以使用以下命令搜索 Mariadb 安装包
yum list mariadb*
1. 安装数据库
yum install mariadb
2. 启动数据库
systemctl start mariadb
4.56-MariaDB 的密码重置 4.57 MariaDB 慢查询日志 4.58 Tomcat_JDK 部署 4.59 zrlog 安装 4.60 Nginx 代理 Tomcat
4.56-MariaDB 的密码重置
如果记得 root 的密码:
mysqladmin -uroot -paminglinux password "aming-linux"
如果不记得 root 密码:
1)编辑/etc/my.cnf
增加:skip-grant
重启服务
2)登录进MariaDB,执行
use mysql 切换到mysql库
desc user 查看user表的所有字段
update user set authentication_string=password("aming-linux") where user=''root'';
3)退出MariaDB,删除/etc/my.cnf里面的skip-grant, 重启服务
4)用新密码登录即可
常识:
mysql在5.7.36版本之后把密码字段存到了authentication_string字段里,在之前版本存在password字段里。
update user set password=password("aming-linux") where user=''root'';
4.57 MariaDB 慢查询日志
为什么要配置慢查询日志?
目的是为了帮助我们分析MariaDB的瓶颈点。
如何配置?
1)进入MariaDB里面执行:
show variables like ''slow%'';
show variables like ''datadir'';
show variables like ''long%'';
2)打开配置文件/etc/my.cnf,编辑,增加:
slow_query_log = ON
slow_query_log_file = /data/mysql/aminglinux01-slow.log
long_query_time = 2
3)重启服务
4)模拟慢查询
select sleep(5);
5)查看慢查询日志:
cat /data/mysql/aminglinux01-slow.log
扩展:
show processlist;
show full processlist;
mysql -uroot -pxxxx -e "show processlist"
4.58 Tomcat_JDK 部署
JAVA 应用要运行起来,需要一个 JVM(JAVA 虚拟机)
JVM --> JDK
Oracle 官方 JDK 下载地址: https://www.oracle.com/technetwork/java/javase/downloads/index.html
CentOS7 上 yum 安装 openjdk
yum install -y java-1.8.0-openjdk
Tomcat 官方网站:
http://tomcat.apache.org/
Tomcat 版本:
7.0 8.5 9.0
下载地址:
https://tomcat.apache.org/download-90.cgi
wget https://www-eu.apache.org/dist/tomcat/tomcat-9/v9.0.14/bin/apache-tomcat-9.0.14.tar.gz
安装 Tomcat
tar zxf apache-tomcat-9.0.14.tar.gz
mv apache-tomcat-9.0.14 /usr/local/tomcat
启动
/usr/local/tomcat/bin/startup.sh
查看端口
netstat -lntp |grep java
8080为WEB端口
8005 shutdown(管理端口)
8009 AJP端口(第三方的应用连接这个接口,和Tomcat结合起来)
查看进程
ps aux |grep java ; ps aux |grep tomcat
4.59 zrlog 安装
zrlog 是一款开源的 JAVA 应用,博客系统 官网: https://www.zrlog.com/
下载:
wget ''http://dl.zrlog.com/release/zrlog-2.1.0-3617b2e-release.war?attname=ROOT.war&ref=index''
mv zrlog-2.1.0-3617b2e-release.war\?attname\=ROOT.war\&ref\=index zrlog-2.1.0.war
安装:
mv zrlog-2.1.0.war /usr/local/tomcat/webapps/
cd !$
mv ROOT ROOT.bak
mv zrlog-2.1.0 ROOT
浏览器访问:
添加防火墙规则: firewall-cmd --add-port=8080/tcp --permanent
firewall-cmd --reload
http://ip:8080/ 开始安装
数据库操作:
mysql -uroot -paming-linux -e "create database zrlog"
mysql -uroot -paming-linux -e "grant all on zrlog.* to ''zrlog''@''127.0.0.1'' identified by ''zrlog-pass''"
4.60 Nginx 代理 Tomcat
为什么要为 Tomcat 配置反向代理?
1)如果同一台机器又有Nginx又有Tomcat,则会产生端口冲突。
2)我们需要把8080端口变成80端口
3)Nginx对于静态的请求速度上要优于Tomcat,Tomcat不擅长做高并发的静态文件请求处理
如何配置?
server {
server_name z.aminglinux.cc;
location /
{
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
代码后续慢慢补齐
4.56 MariaDB密码重置
如果不记得mysql的root密码
[root@test01 ~]# vi /etc/my.cnf
[mysqld]
datadir=/data/mysql
socket=/tmp/mysql.sock
skip-grant
[root@test01 ~]# /etc/init.d/mysqld restart 重启
Restarting mysqld (via systemctl): [ 确定 ]
[root@test01 ~]# mysql -uroot 此时就不需要再输入密码了
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 10.3.12-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type ''help;'' or ''\h'' for help. Type ''\c'' to clear the current input statement.
MariaDB [(none)]>
MariaDB [(none)]> use mysql 切换到mysql库下面去
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [mysql]> desc user; 看一下
+------------------------+-----------------------------------+------+-----+----------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------------------+-----------------------------------+------+-----+----------+-------+
| Host | char(60) | NO | PRI | | |
| User | char(80) | NO | PRI | | |
| Password | char(41) | NO | | | |
| Select_priv | enum(''N'',''Y'') | NO | | N | |
| Insert_priv | enum(''N'',''Y'') | NO | | N | |
| Update_priv | enum(''N'',''Y'') | NO | | N | |
| Delete_priv | enum(''N'',''Y'') | NO | | N | |
| Create_priv | enum(''N'',''Y'') | NO | | N | |
| Drop_priv | enum(''N'',''Y'') | NO | | N | |
| Reload_priv | enum(''N'',''Y'') | NO | | N | |
| Shutdown_priv | enum(''N'',''Y'') | NO | | N | |
| Process_priv | enum(''N'',''Y'') | NO | | N | |
| File_priv | enum(''N'',''Y'') | NO | | N | |
| Grant_priv | enum(''N'',''Y'') | NO | | N | |
| References_priv | enum(''N'',''Y'') | NO | | N | |
| Index_priv | enum(''N'',''Y'') | NO | | N | |
| Alter_priv | enum(''N'',''Y'') | NO | | N | |
| Show_db_priv | enum(''N'',''Y'') | NO | | N | |
| Super_priv | enum(''N'',''Y'') | NO | | N | |
| Create_tmp_table_priv | enum(''N'',''Y'') | NO | | N | |
| Lock_tables_priv | enum(''N'',''Y'') | NO | | N | |
| Execute_priv | enum(''N'',''Y'') | NO | | N | |
| Repl_slave_priv | enum(''N'',''Y'') | NO | | N | |
| Repl_client_priv | enum(''N'',''Y'') | NO | | N | |
| Create_view_priv | enum(''N'',''Y'') | NO | | N | |
| Show_view_priv | enum(''N'',''Y'') | NO | | N | |
| Create_routine_priv | enum(''N'',''Y'') | NO | | N | |
| Alter_routine_priv | enum(''N'',''Y'') | NO | | N | |
| Create_user_priv | enum(''N'',''Y'') | NO | | N | |
| Event_priv | enum(''N'',''Y'') | NO | | N | |
| Trigger_priv | enum(''N'',''Y'') | NO | | N | |
| Create_tablespace_priv | enum(''N'',''Y'') | NO | | N | |
| Delete_history_priv | enum(''N'',''Y'') | NO | | N | |
| ssl_type | enum('''',''ANY'',''X509'',''SPECIFIED'') | NO | | | |
| ssl_cipher | blob | NO | | NULL | |
| x509_issuer | blob | NO | | NULL | |
| x509_subject | blob | NO | | NULL | |
| max_questions | int(11) unsigned | NO | | 0 | |
| max_updates | int(11) unsigned | NO | | 0 | |
| max_connections | int(11) unsigned | NO | | 0 | |
| max_user_connections | int(11) | NO | | 0 | |
| plugin | char(64) | NO | | | |
| authentication_string | text | NO | | NULL | |
| password_expired | enum(''N'',''Y'') | NO | | N | |
| is_role | enum(''N'',''Y'') | NO | | N | |
| default_role | char(80) | NO | | | |
| max_statement_time | decimal(12,6) | NO | | 0.000000 | |
+------------------------+-----------------------------------+------+-----+----------+-------+
47 rows in set (0.022 sec)
新版本的MariaDB 密码文件是这个authentication_string
MariaDB [mysql]> update user set authentication_string=password("champin") where user=''root'';
Query OK, 4 rows affected (0.001 sec)
Rows matched: 4 Changed: 4 Warnings: 0
MariaDB [mysql]> Bye
[root@test01 ~]# vi /etc/my.cnf
删除
skip-grant
[root@test01 ~]# /etc/init.d/mysqld restart 重启
[root@test01 ~]# mysql -uroot -pchampin 重新登录
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 10.3.12-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type ''help;'' or ''\h'' for help. Type ''\c'' to clear the current input statement.
MariaDB [(none)]>
MariaDB [(none)]> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [mysql]> select user,host from user; 我们可以看一下有很多用户
+---------+-----------+
| user | host |
+---------+-----------+
| bbs | 127.0.0.1 |
| blogtop | 127.0.0.1 |
| root | 127.0.0.1 |
| root | ::1 |
| | localhost |
| root | localhost |
| | test01 |
| root | test01 |
+---------+-----------+
8 rows in set (0.000 sec)
4.57 MariaDB慢查询日志
MariaDB [(none)]> show variables like ''slow%''; 查看它的slow相关的
+---------------------+-----------------+
| Variable_name | Value |
+---------------------+-----------------+
| slow_launch_time | 2 |
| slow_query_log | OFF |
| slow_query_log_file | test01-slow.log |
+---------------------+-----------------+
3 rows in set (0.002 sec)
MariaDB [(none)]> show variables like ''datadir'';查看它的datadir
+---------------+--------------+
| Variable_name | Value |
+---------------+--------------+
| datadir | /data/mysql/ |
+---------------+--------------+
1 row in set (0.003 sec)
MariaDB [(none)]> show variables like ''long%''; 查看它的超时时间
+-----------------+-----------+
| Variable_name | Value |
+-----------------+-----------+
| long_query_time | 10.000000 |
+-----------------+-----------+
1 row in set (0.004 sec)
MariaDB [(none)]> Bye
[root@test01 ~]# vi /etc/my.cnf
增加如下
slow_query_log = ON
slow_query_log_file = /data/mysql/test01-slow.log
long_query_time = 2
[root@test01 ~]# /etc/init.d/mysqld restart
Restarting mysqld (via systemctl): [ 确定 ]
[root@test01 ~]# mysql -uroot -pchampin 进入MariaDB里面
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 10.3.12-MariaDB-log MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type ''help;'' or ''\h'' for help. Type ''\c'' to clear the current input statement.
MariaDB [(none)]> select sleep(5); 模拟慢查询
+----------+
| sleep(5) |
+----------+
| 0 |
+----------+
1 row in set (5.001 sec)
MariaDB [(none)]> Bye
[root@test01 ~]# cat /data/mysql/t
tc.log test/ test01.pid test01-slow.log
[root@test01 ~]# cat /data/mysql/test01-slow.log 查看慢查询日志
/usr/local/mysql/bin/mysqld, Version: 10.3.12-MariaDB-log (MariaDB Server). started with:
Tcp port: 0 Unix socket: /tmp/mysql.sock
Time Id Command Argument
# Time: 190311 23:12:52
# User@Host: root[root] @ localhost []
# Thread_id: 9 Schema: QC_hit: No
# Query_time: 5.000687 Lock_time: 0.000000 Rows_sent: 1 Rows_examined: 0
# Rows_affected: 0 Bytes_sent: 63
SET timestamp=1552317172;
select sleep(5);
扩展
[root@test01 ~]# mysql -uroot -pchampin
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 10.3.12-MariaDB-log MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type ''help;'' or ''\h'' for help. Type ''\c'' to clear the current input statement.
MariaDB [(none)]> show processlist; 查看所有的队列(跟查看所有的进程一个道理)
+----+-------------+-----------+------+---------+------+--------------------------+------------------+----------+
| Id | User | Host | db | Command | Time | State | Info | Progress |
+----+-------------+-----------+------+---------+------+--------------------------+------------------+----------+
| 1 | system user | | NULL | Daemon | NULL | InnoDB purge worker | NULL | 0.000 |
| 2 | system user | | NULL | Daemon | NULL | InnoDB purge coordinator | NULL | 0.000 |
| 3 | system user | | NULL | Daemon | NULL | InnoDB purge worker | NULL | 0.000 |
| 4 | system user | | NULL | Daemon | NULL | InnoDB purge worker | NULL | 0.000 |
| 5 | system user | | NULL | Daemon | NULL | InnoDB shutdown handler | NULL | 0.000 |
| 10 | root | localhost | NULL | Query | 0 | Init | show processlist | 0.000 |
+----+-------------+-----------+------+---------+------+--------------------------+------------------+----------+
6 rows in set (0.001 sec)
MariaDB [(none)]> show rull processlist; 显示完整的语句
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ''rull processlist'' at line 1
MariaDB [(none)]> show full processlist;
+----+-------------+-----------+------+---------+------+--------------------------+-----------------------+----------+
| Id | User | Host | db | Command | Time | State | Info | Progress |
+----+-------------+-----------+------+---------+------+--------------------------+-----------------------+----------+
| 1 | system user | | NULL | Daemon | NULL | InnoDB purge worker | NULL | 0.000 |
| 2 | system user | | NULL | Daemon | NULL | InnoDB purge coordinator | NULL | 0.000 |
| 3 | system user | | NULL | Daemon | NULL | InnoDB purge worker | NULL | 0.000 |
| 4 | system user | | NULL | Daemon | NULL | InnoDB purge worker | NULL | 0.000 |
| 5 | system user | | NULL | Daemon | NULL | InnoDB shutdown handler | NULL | 0.000 |
| 10 | root | localhost | NULL | Query | 0 | Init | show full processlist | 0.000 |
+----+-------------+-----------+------+---------+------+--------------------------+-----------------------+----------+
6 rows in set (0.000 sec)
4.58 Tomcat_JDK部署
[root@test01 ~]# yum install -y java-1.8.0-openj
[root@test01 ~]# cd /usr/local/src/
[root@test01 src]# wget http://mirror.bit.edu.cn/apache/tomcat/tomcat-9/v9.0.16/bin/apache-tomcat-9.0.16.tar.gz
[root@test01 src]# ls
apache-tomcat-9.0.16.tar.gz nginx-1.14.2
apache-tomcat-9.0.16.tar.gz.1 nginx-1.14.2.tar.gz
mariadb-10.3.12-linux-x86_64.tar.gz php-7.3.1
mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz php-7.3.1.tar.bz2
[root@test01 src]# tar zxf apache-tomcat-9.0.16.tar.gz
[root@test01 src]# ls
apache-tomcat-9.0.16 mariadb-10.3.12-linux-x86_64.tar.gz nginx-1.14.2.tar.gz
apache-tomcat-9.0.16.tar.gz mysql-5.7.23-linux-glibc2.12-x86_64.tar.gz php-7.3.1
apache-tomcat-9.0.16.tar.gz.1 nginx-1.14.2 php-7.3.1.tar.bz2
[root@test01 src]# mv apache-tomcat-9.0.16 /usr/local/tomcat
[root@test01 src]# /usr/local/tomcat/bin/startup.sh 启动Tomcat
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.
[root@test01 src]# ps aux |grep java 查看进程
root 7340 10.9 7.8 2289972 78204 pts/3 Sl 23:39 0:03 /usr/bin/java -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -Dignore.endorsed.dirs= -classpath /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/usr/local/tomcat -Dcatalina.home=/usr/local/tomcat -Djava.io.tmpdir=/usr/local/tomcat/temp org.apache.catalina.startup.Bootstrap start
root 7356 0.0 0.0 112728 976 pts/3 R+ 23:39 0:00 grep --color=auto java
[root@test01 src]# netstat -ltnp |grep java 查看监听端口,有3个端口
8080为WEB端口
8005 shutdown(管理端口)
8009 AJP端口(第三方的应用连接这个接口,和Tomcat结合起来)
tcp6 0 0 :::8080 :::* LISTEN 7340/java
tcp6 0 0 127.0.0.1:8005 :::* LISTEN 7340/java
tcp6 0 0 :::8009 :::* LISTEN 7340/java
4.59 安装zrlog
[root@test01 src]# cd
[root@test01 ~]# wget http://dl.zrlog.com/release/zrlog-2.1.0-3617b2e-release.war?attname=ROOT.war&ref=index
[root@test01 ~]# ls
11.txt 2.txt anaconda-ks.cfg startingup.sh
1.txt 3.txt DiscuzX zrlog-2.1.0-3617b2e-release.war?attname=ROOT.war
[root@test01 ~]# du -sh zrlog-2.1.0-3617b2e-release.war\?attname\=ROOT.war 也属于一种压缩包
不用管怎么解压,至于要放到某个目录下就可以,会自动解压
9.9M zrlog-2.1.0-3617b2e-release.war?attname=ROOT.war
[root@test01 ~]# mv zrlog-2.1.0.war /usr/local/tomcat/webapps/
[root@test01 ~]# cd !$
cd /usr/local/tomcat/webapps/
[root@test01 webapps]# ls
docs examples host-manager manager ROOT zrlog-2.1.0 zrlog-2.1.0.war
[root@test01 webapps]# mv zrlog-2.1.0 zrlog 改个名字,不需要带版本号了。因为等访问的时候要带目录
[root@test01 webapps]# ls
docs examples host-manager manager ROOT zrlog zrlog-2.1.0.war
用浏览器访问tomcat默认界面 192.168.28.107:8080 如果不能访问,检查是不是防火墙阻拦了8080
[root@test01 webapps]# iptables -nvL |grep 8080 检查有没有8080端口,结果没有
[root@test01 webapps]# firewall-cmd --add-port=8080/tcp --permanent 添加防火墙规则,8080端口
success
[root@test01 webapps]# firewall-cmd --reload 还要重载一下
success
然后再用浏览器访问tomcat默认界面 192.168.28.107:8080
要想访问zrlog,这样192.168.28.107:8080/zrlog
也就是说zrlog在/usr/local/tomcat/webapps这个目录 访问8080实际访问的是/usr/local/tomcat/webapps这个目录
下面这两步不太建议做。访问不了tomcat默认主页
[root@test01 webapps]# mv ROOT ROOT.bak
[root@test01 webapps]# mv zrlog ROOT
[root@test01 webapps]# mysql -uroot -pchampin -e "create database zrlog" 创建库
[root@test01 webapps]# mysql -uroot -pchampin -e "grant all on zrlog.* to ''zrlog''@''127.0.0.1''identified by ''champin''" 创建用户及密码
浏览器访问192.168.28.107:8080/zrlog
填入数据库,安装完成
4.60 Nginx代理Tomcat
[root@test01 webapps]# cd /etc/nginx/conf.d/
[root@test01 conf.d]# ls
2.conf bbs.champin.top.conf default.conf www.champin.top.conf
[root@test01 conf.d]# vi z.champinlinux.cc.conf
server {
server_name z.chamlinux.cc;
location /
{
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
[root@test01 conf.d]# nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@test01 conf.d]# nginx -s reload
还是因为是本机测试,要再windows绑定一个hosts 去ping一下 z.chamlinux.cc
然后在用浏览器访问z.chamlinux.cc去访问,可以去里面做一些细节的设置
CentOS 7 x64下Apache+MySQL(Mariadb)+PHP56的安装教程详解
每次搭建新服务器,都要来来回回把这些包再装一下,来来回回搞了不下20遍了吧,原来都是凭经验,配置过程中重复入坑是难免的,故写此文做个备忘。虽然有像xampp这样的集成包,但是在生产环境的Linux发行版上,还是通过包管理工具安装会放心。这次新买的服务器是CentOS 7(7.2)系统,相关配置也都以此版本为主,为方便操作,直接使用root
用户配置。
CentOS 7的源比较旧,自带的PHP是PHP 5.4,我们想要的是PHP 5.6,这就需要执行以下命令添加额外的remi源。
rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
准备工作完成后,执行以下命令:
#yum install httpd #yum install mariadb mariadb-server #yum install --enablerepo=remi --enablerepo=remi-PHP56 PHP PHP-devel PHP-mbstring PHP-mcrypt PHP-MysqLnd PHP-PHPunit-PHPUnit
apache,MysqL,PHP56就安装完了,从上面指令会发现没有MysqL和MysqL-server。这是由于MysqL存在版权问题,自CentOS 7已经被移除,取而代之的是mariadb和mariadb-server,它们被设计成与MysqL,MysqL-server完全兼容;而PHP除了自身外还安装了mbstring,mcrypt,MysqLnd等插件,这些在大部分项目中都是必要的,如果没有安装可能会出现打开网站一片空白,查看日志也没错误的情况。
现在我们看下apache的配置。apache安装完后就可以直接使用了,执行下命令先手动启动,并将它添加到开机启动。
#systemctl start httpd #手动启动 #systemctl enable httpd #添加开机启动
执行netstat -tln检查下80端口是否在监听,如果有在监听说明启动成功了。
然后打开apache的默认配置文件,位于/etc/httpd/conf/httpd.conf
,找到DocumentRoot
这一行,通常结果是
DocumentRoot "/var/www/html”`
,它表示网站根目录位于/var/www/html
。在该目录下执行echo "It Works!" > index.html
(如果已经有该文件就不用自己创建了)。然后执行如下命令测试网站是否能正常访问。
#curl http://127.0.0.1/ It Works! #输出该结果表示一切正常
当然,也可以直接在浏览器中访问测试。需要注意的是,如果你是从别的电脑访问,那么要先执行下iptables -F
清空下防火墙,否则访问不了。
然后我们看下PHP的配置。正常来讲,安装完PHP56之后,会在apache下生成相应的配置文件,确认下有生成以下文件:/etc/httpd/conf.modules.d/10-PHP.conf,/etc/httpd/modules/libPHP5.so,/etc/httpd/conf.d/PHP.conf
。
同样在网站根目录下执行以下命令创建PHP测试文件:
#echo "<?PHP PHPinfo; ?>" > info.PHP
访问下http://localhost/info.php,能显示PHP的配置信息即表示PHP安装成功,如果不行,执行apachectl restart
重启下Apache服务器试试,如果失败再从其他地方找原因。
最后看下MysqL的安装与配置。执行以下命令,先手动启动,然后添加到开机启动,接着启动MysqL服务器的初始配置。
#systemctl start mariadb #systemctl enable mariadb #MysqL_secure_installation #完成MysqL首次初始化
完成以后,执行
MysqL -uroot -p<
刚才设置的密码>登陆看看,如果成功说明MysqL配置OK。
至此服务器的配置就完成了。
额外的配置
现代的PHP开发,基本上都构建在composer之上,执行以下命令安装composer是必要的。
#yum install --enablerepo=remi --enablerepo=remi-PHP56 composer
PHPMyAdmin用来管理MysqL也很方便,在/var/www/html
下面,下载并解压就完成可以了。
wget https://files.PHPmyadmin.net/PHPMyAdmin/4.6.5.1/PHPMyAdmin-4.6.5.1-all-languages.zip mv PHPMyAdmin-4.6.5.1-all-languages PHPMyAdmin
建议PHPMyAdmin禁止root登陆,会比较安全,修改方法:进入PHPMyAdmin
目录,打开libraries/config.default.PHP
,找到以下这行,
cfg['Servers'][$i]['AllowRoot'] = true;
将true
改为false
即可。
以上所述是小编给大家介绍的CentOS 7 x64下Apache+MysqL(Mariadb)+PHP56的安装教程详解,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对编程小技巧网站的支持!
CentOS 7.0 使用 yum 安装 MariaDB 与 MariaDB 的简单配置
1、安装MariaDB
安装命令
yum -y install mariadb mariadb-server
安装完成MariaDB,首先启动MariaDB
systemctl start mariadb
设置开机启动
systemctl enable mariadb
接下来进行MariaDB的相关简单配置
MysqL_secure_installation
首先是设置密码,会提示先输入密码
Enter current password for root (enter for none):<–初次运行直接回车
设置密码
Set root password? [Y/n] <– 是否设置root用户密码,输入y并回车或直接回车
New password: <– 设置root用户的密码
Re-enter new password: <– 再输入一次你设置的密码
其他配置
Remove anonymous users? [Y/n] <– 是否删除匿名用户,回车
disallow root login remotely? [Y/n] <–是否禁止root远程登录,回车,
Remove test database and access to it? [Y/n] <– 是否删除test数据库,回车
Reload privilege tables Now? [Y/n] <– 是否重新加载权限表,回车
初始化MariaDB完成,接下来测试登录
MysqL -uroot -ppassword
完成。
2、配置MariaDB的字符集
文件/etc/my.cnf
vi /etc/my.cnf
在[MysqLd]标签下添加
init_connect='SET collation_connection = utf8_unicode_ci'
init_connect='SET NAMES utf8'
character-set-server=utf8
collation-server=utf8_unicode_ci
skip-character-set-client-handshake
文件/etc/my.cnf.d/client.cnf
vi /etc/my.cnf.d/client.cnf
在[client]中添加
default-character-set=utf8
文件/etc/my.cnf.d/MysqL-clients.cnf
vi /etc/my.cnf.d/MysqL-clients.cnf
在[MysqL]中添加
default-character-set=utf8
全部配置完成,重启mariadb
systemctl restart mariadb
之后进入MariaDB查看字符集
MysqL> show variables like "%character%";show variables like "%collation%";
显示为
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/MysqL/charsets/ |
+--------------------------+----------------------------+
8 rows in set (0.00 sec)
+----------------------+-----------------+
| Variable_name | Value |
+----------------------+-----------------+
| collation_connection | utf8_unicode_ci |
| collation_database | utf8_unicode_ci |
| collation_server | utf8_unicode_ci |
+----------------------+-----------------+
3 rows in set (0.00 sec)
字符集配置完成。
3、添加用户,设置权限
创建用户命令
MysqL>create user username@localhost identified by 'password';
直接创建用户并授权的命令
MysqL>grant all on . to username@localhost indentified by 'password';
授予外网登陆权限
MysqL>grant all privileges on . to username@'%' identified by 'password';
授予权限并且可以授权
MysqL>grant all privileges on . to username@'hostname' identified by 'password' with grant option;
简单的用户和权限配置基本就这样了。
其中只授予部分权限把 其中 all privileges或者all改为select,insert,update,delete,create,drop,index,alter,grant,references,reload,shutdown,process,file其中一部分。
CentOS 7.4 上搭建 LAMP(CentOS 7.4、httpd-2.4.6、MariaDB 5.5.56、PHP 5.4.16)
在CentOS 7.4(LAMP)上安装Apache,PHP和MariaDB
在本教程中,我使用IP地址为192.168.10.10的主机
这些设置可能会有所不同,因此您必须在适当的位置替换它们。
版本说明
- Linux:CentOS 7.4
- Apache:httpd-2.4.6
- MariaDB:MariaDB 5.5.56
- PHP:PHP 5.4.16
配置SELinux和Firewalld服务
在本教程中我们关闭SELinux 服务,因此我们可以这样操作:
[root@kangvcar1 ~]# vim /etc/selinux/config
SELINUX=disabled # 修改SELinux配置文件的SELINUX参数为disabled,重启后生效
[root@kangvcar1 ~]# setenforce 0 # 此命令可以让SELinux临时关闭并立即生效
在教程中我们不关闭Firewalld服务,因为在生产环境中我们应该开启它以更加安全的工作,同时我们配置开放http和https服务来提供互联网上的主机访问。因此我们可以这样操作:
[root@kangvcar1 ~]# systemctl start firewalld
[root@kangvcar1 ~]# firewall-cmd --permanent --zone=public --add-service=http # 放行 http 服务
[root@kangvcar1 ~]# firewall-cmd --permanent --zone=public --add-service=https # 放行 https 服务
[root@kangvcar1 ~]# firewall-cmd --reload
如果互联网无法访问站点,可能要到服务器提供商的控制台放行相应端口
安装 httpd 2.4.6
CentOS 7附带Apache 2.4。因此我们可以像这样安装它:
[root@kangvcar1 ~]# yum -y install httpd # 安装httpd-2.4
## 为httpd创建系统启动链接(以便httpd在系统引导时自动启动)并启动httpd服务器:
[root@kangvcar1 ~]# systemctl start httpd
[root@kangvcar1 ~]# systemctl enable httpd
安装MariaDB 5.5.56
MariaDB是MySQL分支。MariaDB与MySQL兼容,我选择在这里使用MariaDB而不是MySQL是因为CentOS7.4默认提供了MariaDB的rpm包。运行以下命令以yum安装MariaDB:
[root@kangvcar1 ~]# yum -y install mariadb-server mariadb
## 为MariaDB创建系统启动链接(以便MariaDB在系统引导时自动启动)并启动MariaDB服务器:
[root@kangvcar1 ~]# systemctl start mariadb
[root@kangvcar1 ~]# systemctl enable mariadb
执行MariaDB初始化脚本并为root用户设置密码:
[root@kangvcar1 ~]# mysql_secure_installation
注意:对于所有MariaDB 服务器在生产中使用,建议运行此脚本的所有部分!请仔细阅读每一步!
安装 PHP 5.4.16
PHP最新版已经到了7.1 。安装方法大同小异,这里我们安装CentOS7.4默认提供的PHP 5.4.16 。运行以下命令以yum安装PHP:
[root@kangvcar1 ~]# yum -y install php
安装PHP之后我们必须重新启动Apache:
[root@kangvcar1 ~]# systemctl restart httpd
测试PHP5 是否和Apache关联起来,并获取有关您的PHP5安装的详细信息。我们现在创建一个小型PHP文件(index.php)并在浏览器中调用它。该文件将显示大量有关我们PHP安装的有用信息:
[root@kangvcar1 ~]# vim /var/www/html/index.php
<?php
phpinfo();
?>
在浏览器打开 http://192.168.10.10 即可看到PHP的信息,正如您所看到的,PHP5正在运行,它正在通过Apache 2.0 Handler进行工作,如Server API行中所示。如果向下滚动,您将看到所有已在PHP5中启用的模块。MySQL没有在那里列出,这意味着我们在PHP5中还没有MySQL支持。为了在PHP中获得MySQL支持,我们可以安装php-mysql
软件包。最好安装一些其他PHP5模块,以及您可能需要它们用于您的应用程序。您可以搜索可用的PHP5模块,如下所示:
[root@kangvcar1 ~]# yum search php # 搜索可用的php模块
## 选择你需要的,并像这样安装它们:
[root@kangvcar1 ~]# yum -y install php-mysql
在下一步中,我将安装一些CMS系统需要的常见PHP模块,如Wordpress,Joomla和Drupal:
[root@kangvcar1 ~]# yum -y install php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel
安装完成后,重新启动httpd服务,然后再次打开 http://192.168.10.10 即可看到PHP的更多扩展信息:
[root@kangvcar1 ~]# systemctl restart httpd
安装phpMyAdmin-4.4.15.10
我将在这里添加EPEL repo以安装最新的phpMyAdmin,如下所示:
[root@kangvcar1 ~]# yum -y install epel-release
[root@kangvcar1 ~]# yum -y install phpmyadmin
然后修改配置文件以允许其他主机访问(默认只允许本地127.0.0.1访问),在<Directory /usr/share/phpMyAdmin/>
容器内注释<RequireAny>
配置,然后在<Directory /usr/share/phpMyAdmin/>
容器内添加Require all granted
配置即可:
[root@kangvcar1 ~]# vim /etc/httpd/conf.d/phpMyAdmin.conf
<Directory /usr/share/phpMyAdmin/>
AddDefaultCharset UTF-8
<IfModule mod_authz_core.c>
# Apache 2.4
# <RequireAny>
# Require ip 127.0.0.1
# Require ip ::1
# </RequireAny>
Require all granted #添加此行
</IfModule>
<IfModule !mod_authz_core.c>
# Apache 2.2
Order Deny,Allow
Deny from All
Allow from 127.0.0.1
Allow from ::1
</IfModule>
Options none
AllowOverride Limit
Require all granted
</Directory>
重新启动httpd服务,在浏览器打开 http://192.168.10.10/phpmyadmin 即可。
关于CentOS 7 两步安装启动 Mysql和mariadb的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于4.56-MariaDB 的密码重置 4.57 MariaDB 慢查询日志 4.58 Tomcat_JDK 部署 4.59 zrlog 安装 4.60 Nginx 代理 Tomcat、CentOS 7 x64下Apache+MySQL(Mariadb)+PHP56的安装教程详解、CentOS 7.0 使用 yum 安装 MariaDB 与 MariaDB 的简单配置、CentOS 7.4 上搭建 LAMP(CentOS 7.4、httpd-2.4.6、MariaDB 5.5.56、PHP 5.4.16)的相关知识,请在本站寻找。
本文标签: