解决还原centos后 根目录空间不足的情况

环境:kvm
系统:CentOS7
故障描述:10g的ssd,可使用大小仅有2g
解决过程:

    某次重装系统后,安装软件总提示磁盘空间不足,检查之下发现仅有2G空间,实则明明是10G的ssd,以下为排错过程:

1、df -h查看vda1大小为2.7G

#df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 2.7G 2.4G 236M 91% /
devtmpfs 234M 0 234M 0% /dev
tmpfs 244M 0 244M 0% /dev/shm
tmpfs 244M 4.5M 240M 2% /run
tmpfs 244M 0 244M 0% /sys/fs/cgroup
tmpfs 49M 0 49M 0% /run/user/0

2、fdisk查看vda1一共9959232个block,大小应为9959232KB=9.725.8GB

#fdisk -l
Disk /dev/vda: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000f3770
   Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *        2048    19920511     9959232   83  Linux
/dev/vda2        19920512    20969087      524288   82  Linux swap / Solaris

3、尝试能否通过新建分区解决的时候,发现了另一个bug,居然能看到主机的真实磁盘大小!

#fdisk /dev/vda
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Command (m for help): u
Changing display/entry units to cylinders (DEPRECATED!).

Command (m for help): n
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): p
Partition number (3,4, default 3): 3
First cylinder (1306-20805, default 1306): 
Using default value 1306
Last cylinder, +cylinders or +size{K,M,G} (1306-20805, default 20805): 
Using default value 20805
Partition 3 of type Linux and of size 149.4 GiB is set                                   

//剩余149.4G,加上我自己的10G,这块SSD的大小应该是160G的,当然仅此而已了,想要盗用还是不可能的,至少我办不到。囧

Command (m for help): q

fdisk -l                                                                                                   

//虽然fdisk看到的vda3貌似很厉害的样子

Disk /dev/vda: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000f3770

Device Boot Start End Blocks Id System
/dev/vda1 * 2048 19920511 9959232 83 Linux
/dev/vda2 19920512 20969087 524288 82 Linux swap / Solaris
/dev/vda3 20969088 334232324 156631618+ 83 Linux

4、partprobe的时候果然报错了哈哈哈

#partprobe 
Error: Can't have a partition outside the disk!

5、fdisk看到的vda1大小正常,并且也没有多余的可用空间来新建分区,说明问题不是出在磁盘空间分配上,此路不通。

所以删除那个奇葩的vda3,尝试resize方法

#resize2fs /dev/vda1 (其实核心就是这个命令)
resize2fs 1.42.9 (28-Dec-2013) Filesystem at /dev/vda1 is mounted on /; on-line resizing required old_desc_blocks = 1, new_desc_blocks = 2 The filesystem on /dev/vda1 is now 2489808 blocks long.

6、fdisk数据并无变化,但df显示磁盘空间终于正常了,安装程序也不会再提示磁盘空间不足,故障排除。

fdisk -l

Disk /dev/vda: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000f3770

Device Boot Start End Blocks Id System
/dev/vda1 * 2048 19920511 9959232 83 Linux
/dev/vda2 19920512 20969087 524288 82 Linux swap / Solaris

# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/vda1 9.3G 2.4G 6.6G 27% /
devtmpfs 234M 0 234M 0% /dev
tmpfs 244M 0 244M 0% /dev/shm
tmpfs 244M 4.5M 240M 2% /run
tmpfs 244M 0 244M 0% /sys/fs/cgroup
tmpfs 49M 0 49M 0% /run/user/0

用yum快速搭建LAMP平台

实验环境:

[root@nmserver-7 html]# cat  /etc/redhat-release 
CentOS release 7.3.1611 (AltArch) 

[root@nmserver–7 html]

# uname -a Linux nmserver-7.test.com 3.10.0-514.el7.centos.plus.i686 #1 SMP Wed Jan 25 12:55:04 UTC 2017 i686 i686 i386 GNU/Linux

1、安装apache

  1.1 安装apache

[root@nmserver-7 ~]# yum install httpd httpd-devel

  1.2 启动apache服务

[root@nmserver-7 ~]# systemctl start  httpd

  1.3 设置httpd服务开机启动

[root@nmserver-7 ~]# systemctl enable  httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.

  1.4 查看服务状态

复制代码
[root@nmserver-7 ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled) Active: active (running) since 五 2017-07-21 17:21:37 CST; 6min ago Docs: man:httpd(8) man:apachectl(8) Main PID: 2449 (httpd) Status: "Total requests: 11; Current requests/sec: 0; Current traffic: 0 B/sec" CGroup: /system.slice/httpd.service ├─2449 /usr/sbin/httpd -DFOREGROUND ├─2450 /usr/sbin/httpd -DFOREGROUND ├─2451 /usr/sbin/httpd -DFOREGROUND ├─2452 /usr/sbin/httpd -DFOREGROUND ├─2453 /usr/sbin/httpd -DFOREGROUND ├─2454 /usr/sbin/httpd -DFOREGROUND ├─2493 /usr/sbin/httpd -DFOREGROUND ├─2494 /usr/sbin/httpd -DFOREGROUND └─2495 /usr/sbin/httpd -DFOREGROUND 7月 21 17:21:35 nmserver-7.test.com systemd[1]: Starting The Apache HTTP Server... 7月 21 17:21:36 nmserver-7.test.com httpd[2449]: AH00558: httpd: Could not reliably determine the server's fully q...ssage 7月 21 17:21:37 nmserver-7.test.com systemd[1]: Started The Apache HTTP Server. Hint: Some lines were ellipsized, use -l to show in full.
复制代码

  1.5 防火墙设置开启80端口

[root@nmserver-7 ~]# firewall-cmd --permanent --zone=public  --add-service=http 
success

[root@nmserver–7 ~]

# firewall-cmd –permanent –zone=public –add-service=https

success

[root@nmserver–7 ~]


# firewall-cmd –reload

success

  1.6确认80端口监听中

复制代码
[root@nmserver-7 ~]# netstat -tulp 
Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:ssh 0.0.0.0:* LISTEN 1084/sshd tcp 0 0 localhost:smtp 0.0.0.0:* LISTEN 1486/master tcp6 0 0 [::]:ssh [::]:* LISTEN 1084/sshd tcp6 0 0 localhost:smtp [::]:* LISTEN 1486/master tcp6 0 0 [::]:http [::]:* LISTEN 2449/httpd udp 0 0 localhost:323 0.0.0.0:* 592/chronyd udp6 0 0 localhost:323 [::]:* 592/chronyd
复制代码

  1.8 查服务器IP

复制代码
[root@nmserver-7 ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:56:bc:cf brd ff:ff:ff:ff:ff:ff
    inet 192.168.8.9/24 brd 192.168.8.255 scope global ens33
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe56:bccf/64 scope link 
       valid_lft forever preferred_lft forever
3: bridge0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN qlen 1000
    link/ether ea:89:d5:c7:32:73 brd ff:ff:ff:ff:ff:ff
复制代码

  1.9 浏览器登陆

2、安装mysql

  2.1安装mysql

[root@nmserver-7 ~]# yum install mariadb mariadb-server mariadb-libs mariadb-devel
root@nmserver-7 ~]# rpm -qa |grep maria 
mariadb-libs-5.5.52-1.el7.i686
mariadb-5.5.52-1.el7.i686
mariadb-server-5.5.52-1.el7.i686
mariadb-devel-5.5.52-1.el7.i686

  2.2 开启mysql服务,并设置开机启动,检查mysql状态

复制代码
[root@nmserver-7 ~]# systemctl start  mariadb 

[root@nmserver–7 ~]

# systemctl enable mariadb

Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.

[root@nmserver–7 ~]

# systemctl status mariadb

● mariadb.service – MariaDB database server Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled) Active: active (running) since 六 2017-07-22 21:19:20 CST; 21s ago Main PID: 9603 (mysqld_safe) CGroup: /system.slice/mariadb.service ├─9603 /bin/sh /usr/bin/mysqld_safe –basedir=/usr └─9760 /usr/libexec/mysqld –basedir=/usr –datadir=/v… 7月 22 21:19:15 nmserver-7.test.com mariadb-prepare-db-dir[9524]: … 7月 22 21:19:15 nmserver-7.test.com mariadb-prepare-db-dir[9524]: … 7月 22 21:19:15 nmserver-7.test.com mariadb-prepare-db-dir[9524]: … 7月 22 21:19:15 nmserver-7.test.com mariadb-prepare-db-dir[9524]: … 7月 22 21:19:15 nmserver-7.test.com mariadb-prepare-db-dir[9524]: … 7月 22 21:19:15 nmserver-7.test.com mariadb-prepare-db-dir[9524]: … 7月 22 21:19:15 nmserver-7.test.com mariadb-prepare-db-dir[9524]: … 7月 22 21:19:16 nmserver-7.test.com mysqld_safe[9603]: 170722 21… 7月 22 21:19:16 nmserver-7.test.com mysqld_safe[9603]: 170722 21… 7月 22 21:19:20 nmserver-7.test.com systemd[1]: Started MariaDB …

复制代码
复制代码
[root@nmserver-7 ~]# netstat -tulp 
Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:ssh 0.0.0.0:* LISTEN 1084/sshd
tcp 0 0 0.0.0.0:mysql 0.0.0.0:* LISTEN 9760/mysqld
tcp6 0 0 [::]:ssh [::]:* LISTEN 1084/sshd tcp6 0 0 [::]:http [::]:* LISTEN 2449/httpd udp 0 0 localhost:323 0.0.0.0:* 592/chronyd udp6 0 0 localhost:323 [::]:* 592/chronyd
复制代码

  2.3 数据库安全设置

复制代码
[root@nmserver-7 ~]# mysql_secure_installation  NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB       SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we'll need the current password for the root user.  If you've just installed MariaDB, 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 MariaDB root user without the proper authorisation. Set root password? [Y/n] y 
New password: Re-enter new password: Password updated successfully! Reloading privilege tables.. ... Success! By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB 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] n ... skipping. By default, MariaDB 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] 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] y ... Success! Cleaning up... All done! If you've completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB!
复制代码

  2.4 登陆数据库测试

复制代码
[root@nmserver-7 ~]# mysql -uroot -p Enter password:  Welcome to the MariaDB monitor.  Commands end with ; or \g. Your MariaDB connection id is 11 Server version: 5.5.52-MariaDB MariaDB Server Copyright (c) 2000, 2016, 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 | +--------------------+ 3 rows in set (0.02 sec) MariaDB [(none)]>
复制代码

3、安装PHP

  3.1 安装php

[root@nmserver-7 ~]# yum -y install php
[root@nmserver-7 ~]# rpm -ql php 
/etc/httpd/conf.d/php.conf
/etc/httpd/conf.modules.d/10-php.conf
/usr/lib/httpd/modules/libphp5.so
/usr/share/httpd/icons/php.gif
/var/lib/php/session

  3.2 将php与mysql关联起来

复制代码
[root@nmserver-7 ~]# yum install php-mysql

[root@nmserver–7 ~]

# rpm -ql php-mysql

/etc/php.d/mysql.ini /etc/php.d/mysqli.ini

/etc/php.d/pdo_mysql.ini

/usr/lib/php/modules/mysql.so

/usr/lib/php/modules/mysqli.so

/usr/lib/php/modules/pdo_mysql.so

复制代码

  3.3 安装常用PHP模块

[root@nmserver-7 ~]# yum install -y php-gd php-ldap php-odbc php-pear php-xml php-xmlrpc php-mbstring php-snmp php-soap curl curl-devel php-bcmath

  3.4 测试PHP

复制代码
[root@nmserver-7 ~]# cd  /var/www/html/
[root@nmserver-7 html]# ls
[root@nmserver-7 html]# pwd
/var/www/html
[root@nmserver-7 html]# vi info.php

<?php
        phpinfo();
?>
~                                                                                        
~                                                                                        
~                                                                                        
~                                                                                        
~                                                                                        
~                                                                                        
~                                                                                        
~        :wq
复制代码

  3.5重启apache服务器

[root@nmserver-7 html]# systemctl restart httpd

  3.6测试PHP

  在自己电脑浏览器输入 192.168.8.9/info.php,你可以看到已经安装的模块;

至此,CentOS7下LAMP环境搭建好了!下一步可以安装zabbix了!

树莓派服务器(第十章: mysql-5.6.34 编译安装)

centos mysql-5.6.34 编译安装:

准备工作:
yum install gcc gcc-c++ ncurses-devel perl

安装cmake:
yum install cmake
或源码安装:
wget http://www.cmake.org/files/v2.8/cmake-2.8.10.2.tar.gz   
tar -xzvf cmake-2.8.10.2.tar.gz   
cd cmake-2.8.10.2   
./bootstrap ; make ; make install   
cd ~  

新增mysql用户组:
groupadd mysql  
新增mysql用户:
useradd -r -g mysql mysql
新建mysql安装目录:
mkdir -p /usr/local/mysql  
新建mysql数据库数据文件目录:
mkdir -p /data/mysqldb  

 wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.34.tar.gz
 tar -zxvf mysql-5.6.34.tar.gz
 cd mysql-5.6.34

从mysql5.5起,mysql源码安装开始使用cmake了,设置源码编译配置脚本:
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_UNIX_ADDR=/usr/local/mysql/mysql.sock -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DMYSQL_DATADIR=/data1/mysqldb -DMYSQL_TCP_PORT=3306 -DENABLE_DOWNLOADS=1

make -j4

make install

修改mysql目录所有者和组:
cd /usr/local/mysql   
chown -R mysql:mysql ./ 

cd /data/mysqldb  
chown -R mysql:mysql ./  

初始化mysql数据库:
cd /usr/local/mysql   
scripts/mysql_install_db –user=mysql –datadir=/data/mysqldb

复制mysql服务启动配置文件:
cp /usr/local/mysql/support-files/my-default.cnf /etc/my.cnf  

giedt /etc/my.cnf

[client]

port    = 3306
socket = /var/lib/mysql/mysql.sock

[mysqld]

user    = mysql
port    = 3306
socket = /var/lib/mysql/mysql.sock
basedir = /usr/local/mysql
datadir = /data1/mysqldb
log-error = /data/mysqldb/mysql_error.log
pid-file = /data/mysqldb/mysql.pid

复制mysql服务启动脚本及加入PATH路径:
cp support-files/mysql.server /etc/init.d/mysqld 

vim /etc/profile 

      PATH=/usr/local/mysql/bin:/usr/local/mysql/lib:$PATH

      export PATH

source /etc/profile  

启动mysql服务并加入开机自启动(可选这个步骤,以后可以自己启动的):
service mysqld start 
chkconfig –level 35 mysqld on

检查mysql服务是否启动:
netstat -tulnp | grep 3306   
mysql -u root -p   

修改MySQL用户root的密码:
mysqladmin -u root password ‘123456’

注:也可运行安全设置脚本,修改MySQL用户root的密码,同时可禁止root远程连接,移除test数据库和匿名用户:
/usr/local/mysql/bin/mysql_secure_installation  


MySQL问题解决:-bash:mysql:command not found  
因为mysql命令的路径在/usr/local/mysql/bin下面,所以你直接使用mysql命令时,  
系统在/usr/bin下面查此命令,所以找不到了   
   解决办法是:  
 ln -s /usr/local/mysql/bin/mysql /usr/bin 做个链接即可 

ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/usr/local/mysql/mysql.sock’ (2)
1、先查看 /etc/rc.d/init.d/mysqld status 看看mysql服务是否已经启动.
另外看看是不是权限问题.
$service mysqld start

$service mysql start
–我开始遇到的就是因为服务没启动,因为第一次玩mysql不是很熟悉,呵呵。

2、确定你的mysql.sock是不是在那个位置,
mysql -u 你的mysql用户名 -p -S /var/lib/mysql/mysql.sock

如果错啦,就修改/etc/my.cnf:

[client]

socket = /var/lib/mysql/mysql.sock

[mysqld]

socket = /var/lib/mysql/mysql.sock

3、如果是权限问题,则先改变权限 #chown -R mysql:mysql /var/lib/mysql

[root@localhost ~]

# /etc/init.d/mysqld start
启动 MySQL: [ 确定 ]

[root@localhost ~]

# mysql -uroot -p

ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2)
原因是,/var/lib/mysql 的访问权限问题。

shell> chown -R mysql:mysql /var/lib/mysql

接着启动服务器

shell> /etc/init.d/mysql start

服务器正常启动后察看 /var/lib/mysql 自动生成mysql.sock文件。

4、修改/etc/my.conf:

[mysqld]

datadir=/usr/local/mysql/data
socket=/var/lib/mysql/mysql.sock

[mysql.server]

user=mysql
basedir=/usr/local/mysql

If there is not currently a section called [client], add one at the bottom of the file and copy the socket= line under the [mysqld] section such as:

[client]

socket=/var/lib/mysql/mysql.sock

如果发现问题依旧,尝试运行/etc/init.d/mysql start报错:Starting MySQLCouldn’t find MySQL manager or server

如是mysqld服务没启,运行/usr/local/mysql/bin/mysqld_safe &

作者:兔子ming_
来源:CSDN
原文:https://blog.csdn.net/hxmcnu/article/details/53269102
版权声明:本文为博主原创文章,转载请附上博文链接!