Linux自有服务
问题1:CentOS7中service和chkconfig没法使用php
答:CentOS7操做系统中,已经抛弃service和chkconfig命令了,虽 然有些服务如network仍是能够操做,可是官网建议使用systemctl代 替service和chkconfig。node
系统服务管理:mysql
# systemctl start|stop|restart|reload|status 服务名称linux
开机启动项管理:sql
开机启动数据库
# systemctl enable 服务名称vim
开机不启动centos
# systemctl disable 服务名称bash
问题2:CentOS7中iptables没法使用?服务器
咱们以前在CentOS6.x中,使用的是iptables防火墙,怎么在 CentOS7.x中没法使用了呢?
答:在CentOS7中已经将防火墙由iptables切换为firewalld
扩展:firewalld防火墙的使用能够搜索一下firewall-cmd工具或参 考咱们的视频哈
问题3:CentOS6与CentOS7运行模式区别
答:CentOS6与CentOS7的运行模式有所不一样
[root@centos7 ~]# cat /etc/inittab
# inittab is no longer used when using systemd.
#
# ADDING CONFIGURATION HERE WILL HAVE NO EFFECT ON YOUR
SYSTEM.
#
# Ctrl-Alt-Delete is handled by
/usr/lib/systemd/system/ctrl-alt-del.target
#
# systemd uses 'targets' instead of runlevels. By
default, there are two main targets:
## multi-user.target: analogous to runlevel 3
# graphical.target: analogous to runlevel 5
#
# To view current default target, run:
# systemctl get-default
#
# To set a default target, run:
# systemctl set-default TARGET.target
#
CentOS6 CentOS7
0 shutdown.target(关机模式)
1 rescure.target(单用户/救援模式)
2 multi-user,without NFS(字符模式可是缺乏NFS服务)
3 multi-user.target(字符模式)
4 unused(未使用的模式,系统保留)
5 graphical.target(图形模式)
6 reboot.target(重启模式)
可是在CentOS7版本中,咱们须要使用systemctl的方式进行切换:
获取Linux默认级别
# systemctl get-default
设置Linux默认级别(字符模式)
# systemctl set-default multi-user.target
问题4:计划任务的时间老是写很差怎么办呢?
答:时间格式主要是分时日月周,给你推荐一个网站https://qqe2.c om/cron
看到这里,就所有搞定了吧!
问题5:rpm卸载依赖,Failed dependencies
问题重现:
出现以上问题的主要缘由:你要卸载的软件与其余软件存在依赖关系
解决方案:
方案一:若是关联软件不重要,能够先使用rpm卸载依赖软件,然 后在从新卸载此软件
方案二:若是不想卸载依赖软件,能够考虑使用强制卸载
# rpm -e vim-common-7.4.629-6.el7.x86_64 --nodeps
Linux进程检测与控制
问题1:服务器有4核CPU,如何查看每一核心的负载状况?
# top 按交换快捷键"1"
问题2:使用top命令,发现CPU负载过大,接下来怎 么办?
答:查看占用CPU最多的进程,按交互操做快捷键P,P(大写): 表示将结果按照CPU 使用率从高到低进行降序排列
问题3:使用top命令,发现内存可用量很小,接下来 怎么办?
答:查看占用MEM内存最多的进程,使用交互快捷键M(大写): 表示将结果按照内存(MEM)从高到低进行降序排列
问题4:如何获取服务器的CPU个数
# cat /proc/cpuinfo |grep "physical id" |sort |uniq |wc -l
问题5:如何查看每一个物理CPU含有的核心个数
# cat /proc/cpuinfo |grep "cpu cores" |uniq |wc -l
问题6:如何查看每一个CPU核心含有的线程数
# cat /proc/cpuinfo |grep "processor"|wc -l
YUM包管理工具与LAMP架构
问题1:wget下载mysql数据库时提示command not found
错误重现:
[root@itheima ~]# wget http://dev.mysql.com/get/mysqlcommunity-release-el7-5.noarch.rpm
bash: wget: command not found...
出现以上问题的主要缘由在于wget程序并无安装。
解决方案:使用yum安装wget程序
[root@itheima ~]# yum install wget -y
...
Installed:
wget.x86_64 0:1.14-18.el7_6.1
Complete!
[root@itheima ~]# wget http://dev.mysql.com/get/mysqlcommunity-release-el7-5.noarch.rpm
问题2:Existing lock /var/run/yum.pid: another copy is running
错误重现:
Existing lock /var/run/yum.pid: another copy is running
as pid 8706.
Another app is currently holding the yum lock; waiting
for it to exit...
The other application is: PackageKit
Memory : 104 M RSS (521 MB VSZ)
Started: Sat Mar 23 15:04:42 2019 - 00:59 ago
State : Sleeping, pid: 8706
Another app is currently holding the yum lock; waiting
for it to exit...
The other application is: PackageKit
Memory : 104 M RSS (521 MB VSZ)
Started: Sat Mar 23 15:04:42 2019 - 01:01 ago
State : Sleeping, pid: 8706
Another app is currently holding the yum lock; waiting
for it to exit...
The other application is: PackageKit
Memory : 104 M RSS (521 MB VSZ)
Started: Sat Mar 23 15:04:42 2019 - 01:03 ago
State : Sleeping, pid: 8706
......
出现以上问题的主要缘由在于:另一个应用正在锁住进程锁。 waiting for it to exit... 意为该应用等待解锁。此外,由上图可知, yum的pid号为8706。
解决方案:
[root@itheima ~]# rm -f /var/run/yum.pid
问题3:Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
错误重现:
出现以上问题的主要缘由在于MySQL没有启动。
解决方案:使用systemctl启动MySQL
# systemctl start mysqld
问题4:访问具体的PHP页面,可是老是提示Test Page...
问题重现:搭建完LAMP之后,编写PHP代码,访问公网IP/PHP页 面,不管怎么访问一直都提示Test Page...
http://公网IP/demo.php
出现以上问题的主要缘由在于SELinux没有关闭,致使出现了以上问题。
解决方案:
① 临时关闭SELinux
# setenforce 0
② 永久关闭SELinux
# vim /etc/selinux/config
SELINUX=disabled
问题5:MySQL和MariaDB有什么区别?
答:
① MariaDB是MySQL的一个替代品
② MySQL已经被Oracle闭源了,而MariaDB是开源的
③ MariaDB包括的一些新特性使它优于MySQL。MariaDB跟 MySQL在绝大多数方面是兼容的,对于开发者来讲,几乎感受不到 任何不一样。
资料拓展:MariaDB由MySQL的创始人Michael Widenius(英语: Michael Widenius)主导开发,他早前曾以10亿美圆的价格,将 本身建立的公司MySQL AB卖给了SUN,此后,随着SUN被甲骨 文收购,MySQL的全部权也落入Oracle的手中。MariaDB名称来 自Michael Widenius的女儿Maria的名字。
问题6:如何在CentOS7中安装MySQL?
在CentOS7中, yum install mysql -y 安装的是MariaDB,怎么 安装MySQL数据库呢?
第一步:下载MySQL的YUM源
# wget http://dev.mysql.com/get/mysql-communityrelease-el7-5.noarch.rpm
第二步:安装MySQL的YUM源软件包
# rpm -ivh mysql-community-release-el7-5.noarch.rpm
第三步:安装MySQL软件
# yum -y install mysql-community-server
第四步:启动MySQL软件
# systemctl start mysqld
第五步:初始化MySQL数据库
# mysql_secure_installation