CentOS常用命令汇总

MySQL命令

  • 将新创建的数据分配某个用户访问

    grant all privileges on zhouzdb.* to ‘zhouz’@’%’ identified by ‘1234’;
    flush privileges

  • centos 7启动/查看服务

    systemctl start/restart mariadb.servcie

    启动或者重启服务

    systemctl status mariadb.service

    查看指定服务的启动状态日志,如有错误信息,则可以直接发现,比如启动失败等信息。

网络状态

  • 网络情况

netstat -anp

查看当前的网络端口占用情况,并关联相关的pid,方便查找进程相关信息。

Nodejs

  • 升级nodejs至最新版本

sudo npm cache clean -f
sudo npm install -g npm@latest
sudo npm install -g n
sudo n stable

这里的N指特定的nodejs的版本,比如4.7.3, 这些版本可以到https://registry.npmjs.org/n 可以查找到对应的版本。

磁盘空间

  • 查看当前电脑的磁盘分区
    df -hm
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda5       263G  133G  131G  51% /
devtmpfs        126G     0  126G   0% /dev
tmpfs           126G   12K  126G   1% /dev/shm
tmpfs           126G  795M  126G   1% /run
tmpfs           126G     0  126G   0% /sys/fs/cgroup
/dev/sdb1        33T   14T   18T  43% /data0
/dev/sda2       509M  168M  342M  33% /boot
tmpfs            26G     0   26G   0% /run/user/3457
参数说明: -h 表示以人类可以阅读的方式展示信息 -m 以M为单位, 默认以G为单位
  • 查看目录的空间使用情况
    du -hs
  235M
表示当前目录使用了235M的空间 参数说明:
   -a:显示目录占用的磁盘空间大小,还要显示其下目录和文件占用磁盘空间的大小
  -s:显示目录占用的磁盘空间大小,不要显示其下子目录和文件占用的磁盘空间大小
  -c:显示几个目录或文件占用的磁盘空间大小,还要统计它们的总和
  --max-depth=1  显示目录的层次深度

du -ha : 统计当前目录下所有文件和目录的大小,并统计综合

3.4M    ./img_2531.jpg
2.1M    ./svai.jpg
104K    ./zhangdong.jpg
436K    ./test1.jpg
180K    ./testimg/1.jpg
436K    ./testimg/10.jpg
620K    ./testimg/2.jpg
620K    ./testimg/3.jpg
1.6M    ./testimg/4.jpg
896K    ./testimg/5.jpg
624K    ./testimg/6.jpg
628K    ./testimg/7.jpg
624K    ./testimg/8.jpg
4.9M    ./testimg/9.jpg
11M     ./testimg
200M    ./tensorflow_gpu-1.6.0-cp36-cp36m-manylinux1_x86_64.whl
1.3M    ./pip-9.0.2.tar.gz
828K    ./setuptools-39.0.1.zip
17M     ./Python-3.6.4.tar.xz
235M    .

du -hc : 统计当前目录下的目录,并统计其大小

11M     ./testimg
235M    .
235M    total
testimg是当前目录下的子目录。
  • 查看当前目录所在的分区
    df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda5       263G  133G  131G  51% /
当前目录所在的磁盘分区为sda5
  • 查看所有分区
    fdisk -l

pip 常用设置

  • 超时设置
    在基于pip进行安装包的时候,偶尔会报出超时异常:
  File "/export/guanghan/webapps/chenjunfeng1/python36env/lib/python3.6/site-packages/pip/download.py", line 560, in resp_read
    decode_content=False):
  File "/export/guanghan/webapps/chenjunfeng1/python36env/lib/python3.6/site-packages/pip/_vendor/urllib3/response.py", line 436, in stream
    data = self.read(amt=amt, decode_content=decode_content)
  File "/export/guanghan/webapps/chenjunfeng1/python36env/lib/python3.6/site-packages/pip/_vendor/urllib3/response.py", line 401, in read
    raise IncompleteRead(self._fp_bytes_read, self.length_remaining)
  File "/export/guanghan/webapps/chenjunfeng1/python364/lib/python3.6/contextlib.py", line 99, in __exit__
    self.gen.throw(type, value, traceback)
  File "/export/guanghan/webapps/chenjunfeng1/python36env/lib/python3.6/site-packages/pip/_vendor/urllib3/response.py", line 307, in _error_catcher
    raise ReadTimeoutError(self._pool, None, 'Read timed out.')
pip._vendor.urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='pypi.python.org', port=443): Read timed out.

这种问题一般是由于网路比较慢导致的超时,所以需要添加timeout设置
具体的命令: pip install package_name –timeout 1000
这里的1000是超时时间,单位为秒

  • 安装指定版本

pip install package_name==2.3.7

  • 从本地安装whl文件

pip install xxxx.whl

说明: 在包名之后指定版本号,使用”==”

检查操作版本

uname -a

输出结果信息为:

Linux office.rackaid.net 2.6.32-220.2.1.el6.x86_64 #1 SMP
Fri Dec 23 02:21:33 CST 2011 ×86_64 ×86_64 ×86_64 GNU/Linux

cat /etc/redhat-release

输出结果信息为:

CentOS release 6.2 (Final)

用户增加

useradd ‘xxxx’
passwd ‘xxxx’

ifconfig

yum install net-tools

curl代理使用

测试socks5命令:

curl –socks5 125.119.175.48:8909 http://example.com/

测试http命令:

curl –connect-timeout 2 -x 127.0.0.1:8118 http://google.com

———- 万恶的分割线,怎么这么快就到底了—————————
To be Continued.

猜你喜欢

转载自blog.csdn.net/blueheart20/article/details/75009775