Linux常見問題:Linux自有服務、Linux進程檢測與控制、YUM包管理工具與LAMP架構

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

相關文章
相關標籤/搜索