linux 一些常用查看命令

本文汇总了一系列用于Linux系统管理的实用命令,包括查看在线用户数、数据库操作、防火墙配置等,适合系统管理员及运维人员参考。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


查看Apache的在线用户数
netstat -an |grep ".80" |wc -l
netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'
ps -ef|grep http|wc -l


netstat -tan | grep "ESTABLISHED" | grep ":80" | wc -l

-----------------------------------

登录或连接mysql数据库服务
mysql -h主机地址 -u用户名 -p用户密码;
例子:[root@u /]# mysql -hxxx.xxx.xxx.xxx -u用户名 -p密码

 

 

[数据库添加用户]--

进入数据库命令
mysql -uroot -p
密码
进入>mysql

-grant select on 数据库.* to 用户名@登录主机 identified by "密码"
grant select,insert,update,delete on *.* to test1@"%" Identified by "abc";

grant select,insert,update,delete on 数据库名称.* to 用户@"指定访问的ip地址" Identified by "密码";
flush privileges;

 

----------------------------------------------

[数据库权限设置]
GRANT ALL PRIVILEGES ON *.* TO $DataBaseUser@localhost IDENTIFIED BY '$DataBasePwd' WITH GRANT OPTION;
mysql> UPDATE mysql.user SET Password = OLD_PASSWORD('ppadmin') WHERE Host = 'localhost' AND User = 'ppadmin';

//刷新系统权限表.
mysql> FLUSH PRIVILEGES;

[建立数据库]
CREATE DATABASE `mmclick071st` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;

[查看数据库参数]
mysqladmin -uroot -p variables

[查看数据库缓存]
show status like 'Qca%';
show status like 'Com_sel%';

[数据表修复]
myisamchk -r mmc_user_info_20070120.MYI


[数据库重启]/etc/init.d/mysql restart
停止:mysqladmin -u root -p shutdown
启动:mysqld_safe &

[数据库进程]
show processlist;


[防火墙查看]
iptables -nL
60028


[服务器连接数查看]
netstat -an|grep -c ":3360" 查mysql数据库的连接数

netstat -an |grep ".80" |wc -l:查看在线用户数
ps -ef|grep http|wc -l:查看apache并发数
netstat -anp|grep 80|wc
netstat -anp|grep 80|grep EST|wc -l
netstat -an|awk '/:80/{print $5}'|awk -F":" '{print $1}'|sort|uniq -c|sort -n
netstat -nap |grep mysql
netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'

[封IP]
iptables -I INPUT -s 221.221.185.115 -j DROP

[查看CPU]
uptime

[查看内存]
free -m

[查找安装软件包]
rpm -qa |grep

[查看目录大小]
du -h --max-depth=1

 


[apache自定义按日期分log]
CustomLog "|/usr/local/apache2/bin/rotatelogs /usr/local/apache2/logs/v.%Y_%m_%d.access.log 86400 480" common

[远程拷贝]
scp -P 9922 /data/mmclick/mmc_user_info_20070120.* root@xxx.xxx.xxx.xxx:/opt/.

[查找含有某字符的文件]
find / -name '*.jsp' -exec grep -l 'exec(' {} /;
find / -name "*.jsp" | xargs grep "exec("

[服务器时间同步]
ntpdate tick.stdtime.gov.tw

[TOMCAT CONNECTOR]
http://archive.apache.org/dist/jakarta/tomcat-connectors/jk/binaries/win32/jk-1.2.6/

[Apache编译]
./configure --prefix=/usr/local/apache2 --enable-module=so --enable-module=rewrite

[PHP编译]
./configure --prefix=/usr/local/php --with-zlib --with-zlib-dir=/lib --with-xml --enable-calendar --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr --with-config-file-path=/usr/local/lib
./configure --prefix=/usr/local/php4 --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql --with-config-file-path=/usr/local/php4 --with-gd --with-curl --enable-track-vars --with-zlib
./configure --prefix=/usr/local/php --with-zlib --with-zlib-dir=/lib --with-xml --enable-calendar --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr --with-config-file-path=/usr/local/lib
./configure --prefix=/usr/local/php4 --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql --with-config-file-path=/usr/local/php4 --with-gd --with-curl --enable-track-vars --with-zlib

[pureftpd 编译]
./configure --prefix=/usr/local/pureftpd --with-mysql --with-diraliases --with-ftpwho --with-throttling --without-inetd --without-shadow --with-quotas
groupadd ftpgroup
useradd -g ftpgroup -d /dev/null -s /etc ftpuser

 

//服务器所有定时执行任务:(文件存放)
  [root@u ~]# vi /etc/crontab
 
     顺便提一下crontab中的命令格式:
     第一个 * 表示分钟 (0-59),
     第二个 * 表示小时 (0-23),
     第三个 * 表示月份中的某一天 (1-31),
     第四个 * 表示一年中的某一月 (1-12),
     第五个 * 表示一周中的星期几 (0-6 with 0=Sunday).
   例子:01 01 * * * root run-parts /etc/cron.mmcrun01

 


//linux模拟执行浏览器文件(在定时文件中的语句)
(curl -s -o /dev/null)---无返回数据执行文件
curl -s -o /dev/null http://www.text.com/update/Update_a8_Transform.jsp

 //保存后再执行重启
  /etc/init.d/crond restart

 

 


//linux设置虚拟主机
[root@u vhosts]# vi /usr/local/apache2/conf/extra/httpd-vhosts.conf

<VirtualHost *:80>
    ServerAdmin webmaster@test.com
    DocumentRoot /opt/vhosts/www.test.com
    ServerName www.test.com(ServerAlias 指令中列出的名字就是用户可以用来访问同一个web站点的其它名字)
    ServerAlias test.com(别域名)
    DirectoryIndex index.html index.jsp
    ErrorLog logs/dummy-test.com-error_log
    CustomLog "|/usr/local/apache2/bin/rotatelogs /usr/local/apache2/logs/test.com.%Y_%m_%d.access.log 86400 480" combined
</VirtualHost>
//设置完虚拟项目后重启apache
[root@u bin]# /usr/local/apache2/bin/apachectl restart

 


---注意:tomcat的配置文件:server.xml是否已设置
例如:
 <Host name="test.com" debug="0" appBase="/opt/vhosts/test.com" autoDeploy="true">
- <Context path="" docBase="/opt/vhosts/test.com" debug="0" reloadable="true">
  <Logger className="org.apache.catalina.logger.FileLogger" directory="logs" prefix="wapmmclick_log." suffix=".txt" timestamp="true" />
  <Resource name="jdbc/mmclick" auth="Container" scope="Shareable" type="javax.sql.DataSource" maxActive="200" maxIdle="30" maxWait="20000" removeAbandoned="true" removeAbandonedTimeout="60" logAbandoned="true" username="mmclick" password="mmclick" driverClassName="com.mysql.jdbc.Driver" url="jdbc:mysql://127.0.0.1/mmclick?autoReconnect=true" />
  </Context>
  </Host>

测试域名是否成功绑定到目录(用HOST)

C:/WINDOWS/system32/drivers/etc

打开Hosts文件

加入***.***.***.***      xxxx.com

之后关闭浏览器,再开。
直接输入域名

 

-----------------------------

[查看服务器空间容量大小情况:]

[root@db mmclick]# df -h

 

-----------------------------------

[分页查看目录的内容命令]:less -目录名或文件名

最应该记住的命令就是  q  退出less

 

----------------------------------

查看端口:netstat   -an
--------------------


linux修改密码的命令

首先输入passwd 回车

出现:(current) UNIX password:

然后输入现在所用的密码 回车

出现:New password:

再输入新密码(新的密码必须是字母数字都有,不然的话不成功) 然后回车

与Windows下不同的是,输入的密码不会有星号代替,也出现明文,不要担心是不是自己键盘坏掉了------

 

-----------------------------------

apache的rewrite(实际就是设置虚拟主机,只不过在设置虚拟主机配置中加上rewrite功能)

把test.com/*mmc 映射到 index.php?xx=*

应该执行以下设置
进入服务器:
[root@localhost conf]# cd /usr/local/apache2/conf
[root@localhost conf]# vi httpd.conf  (主配置文件)

#开启重写横块功能
#Load Rewrite Module
LoadModule rewrite_module     modules/mod_rewrite.so  (重要)

#再找出设置扩展文件的功能字段


# Server-pool management (MPM specific) -------主的
#Include conf/extra/httpd-mpm.conf

# Multi-language error messages
#Include conf/extra/httpd-multilang-errordoc.conf

# Fancy directory listings
#Include conf/extra/httpd-autoindex.conf

# Language settings
#Include conf/extra/httpd-languages.conf

# User home directories
#Include conf/extra/httpd-userdir.conf

# Real-time info on requests and configuration
#Include conf/extra/httpd-info.conf

# Virtual hosts
Include conf/extra/httpd-vhosts.conf   --------(专门设置虚拟主机的扩展配置文件)

# Local access to the Apache HTTP Server Manual
#Include conf/extra/httpd-manual.conf

# Distributed authoring and versioning (WebDAV)
#Include conf/extra/httpd-dav.conf

# Various default settings
#Include conf/extra/httpd-default.conf

//linux设置虚拟主机并配置重写功能rewrite
[root@u vhosts]# vi /usr/local/apache2/conf/extra/httpd-vhosts.conf

<VirtualHost *:80>
    ServerAdmin webmaster@test.com
    DocumentRoot /opt/vhosts/test.com
    ServerName test.com
    ErrorLog logs/dummy-test.com-error_log
    CustomLog logs/dummy-test.com-access_log common
    <IfModule mod_rewrite.c>
            RewriteEngine  on ---------(重要)
            RewriteRule ^(.*)/([0-9]+)/.mmc$ $1/index.php?fid=$2   (重要)
           #rewritelog /usr/local/apache2/logs/rewrite.log
           #rewriteloglevel 9
    </IfModule>
</VirtualHost>

//设置完虚拟项目后重启apache
[root@u bin]# /usr/local/apache2/bin/apachectl restart

 

 


查找某文件位置
find / -name tomcat

 

---------------------

查找那些文件包含有某些文字的命令

grep "内容" -rl 目录

-r --子目录
-l --列出包含搜索内容的文件的文件名

sed -i 's/原内容/替换内容/g' 文件名
-s --表示替换
-g --所有包含该字段。
-i --直接替换原文件

sed -i 's/aaa/bbb/g' `grep "内容" -rl 目录`

查询包括指定文字的语句
grep "mmc_activesite_counter_day" -rll . >/root/listmmc

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值