linux 命令搜集-1
chroot /mnt/sysimage
批量文件名替换:rename 's/proc_sh_stone_/proc_sh_tool_/;' proc_sh_stone_*
日志分析:awk -F '|' 'int($3)>500 {printf $"\n"}' microsoul > microsoul1
网络配置:
vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE="eth0"
BOOTPROTO="static"
HWADDR="08:00:27:14:51:B2"
NM_CONTROLLED="yes"
ONBOOT="yes"
TYPE="Ethernet"
UUid="f9cb26d8-9f5a-43dd-9d63-9cf010e3e087"
BROADCAST="192.168.0.255"
IPADDR="192.168.0.103"
NETMASK="255.255.255.0"
GATEWAY="192.168.0.1"
vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=microsoul
GATEWAY=192.168.0.1
dhclient
ssh和防火墙配置:
yum -y install openssh-server openssh-clients
1.修改端口
vi /etc/ssh/sshd_config
将#Port 22的注释去掉并且改为其他端口
/usr/sbin/sshd -p 11111
为增强安全
先增加一个普通权限的用户:
useradd microsoul
passwd microsoul//设置密码
生产机器禁止ROOT远程SSH登录:
vi /etc/ssh/sshd_config
把
PermitRootLogin yes
改为
PermitRootLogin no
重启sshd服务
service sshd restart
重启SSH服务 /etc/init.d/sshd restart
2.防火墙开启端口
vi /etc/sysconfig/iptables
加入-A INPUT -m state –state NEW -m tcp -p tcp –dport 22 -j ACCEPT
service iptables save
重启防火墙 /etc/init.d/iptables restart
yum用axel进行下载:
1. 下载axel源码并安装axel:
wget http://alioth.debian.org/frs/download.php/3015/axel-2.4.tar.gz
tar zxvf axel-2.4.tar.gz
cd axel-2.4
./configure
make
make install
2. 下载配置文件axelget.conf与axelget.py到yum里:
cd /etc/yum/pluginconf.d/
wget http://cnfreesoft.googlecode.com/svn/trunk/axelget/axelget.conf
cd /usr/lib/yum-plugins/
wget http://cnfreesoft.googlecode.com/svn/trunk/axelget/axelget.py
最后确认 /etc/yum.conf中plugins=1
yum安装MySQL并设置密码
yum install mysql yum install mysql-server yum install mysql-devel chgrp -R mysql /var/lib/mysql chmod -R 770/var/lib/mysql service mysqld start mysql SET PASSWORD FOR 'root'@'localhost'= PASSWORD('secret_password');
mysqladmin -u root password "newpass"
mkdir /data/mysql
chown -R mysql:mysql /data/mysql
chcon -Rt mysqld_db_t /data/mysql
mysql_install_db
vi /etc/my.cnf
修改:datadir=/data/mysql
socket = /data/mysql/mysql.sock
group_concat_max_len = 102400
可以用SELECT @@group_concat_max_len;查询设置结果,也可以用set group_concat_max_len=102400来动态设置。
vi /etc/passwd
mysql:x:27:27:MySQL Server:/var/lib/mysql:/sbin/nologin
只导出存储过程:mysqldump -n -d -t -R
netstat -ntpl | grep 3306
更新
如要其他机器能访问,在mysql.user
中添加一个Host
为'%'
的user,然后flush priviledges;
,最后防火墙加一句类似这样的语句即可(开通3306
端口):
-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 3306-j ACCEPT
如果要reboot自启动:
chkconfig --levels 345 mysqld on
linux vim显示行号、语法高亮、自动缩进的设置
1、显示行号 在文件末端添加一新行,输入 set nu 2、语法高亮 在文件中找到 "syntax on 这一行,去掉前面的双引号",双引号是注释的意思 3、自动缩进 在文件末尾添加一行,输入 set autoindent 再添加一行,输入 set cindent 其中 autoindent 是自动缩进; cindent是特别针对 C语言语法自动缩进
tomcat 做为服务:
#!/bin/bash # # Startup script for the tomcat # # chkconfig: 345 80 15 # description: Tomcat is a Servlet+JSP Engine. # Source function library. export JDK_HOME=/usr/local/jdk1.6.0_31 export JAVA_HOME=/usr/local/jdk1.6.0_31 . /etc/rc.d/init.d/functions start(){ if [ -z $(/sbin/pidof java) ]; then echo "Starting tomcat" /usr/local/apache-tomcat-6.0.35/bin/startup.sh touch /var/lock/subsys/tomcat else echo "tomcat allready running" fi } stop(){ if [ ! -z $(/sbin/pidof java) ]; then echo "Shutting down tomcat" /usr/local/apache-tomcat-6.0.35/bin/shutdown.sh until [ -z $(/sbin/pidof java) ]; do :; done rm -f /var/lock/subsys/tomcat else echo "tomcat not running" fi } case "$1" in start) start ;; stop) stop ;; restart) stop start ;; status) /usr/local/apache-tomcat-6.0.35/bin/catalina.sh version ;;
chmod 755 /etc/rc.d/init.d/tomcat
chkconfig --add tomcat
chkconfig tomcat on
chkconfig --list tomcat
/etc/rc.d/init.d/tomcat start
yum只下载不安装
yum install --downloadonly --downloaddir=/tmp vsftpd
mysql远程登录:
Grant all privileges on *.* to 'root'@'%' identified by '123456' with grant option;
GRANT ALL PRIVILEGES ON db.* TO 'root'@'192.168.100.2' IDENTIFIED BY '123456' WITH GRANT OPTION;
grant select on 'mysql'.'proc' to 'root'@'192.168.100.2';
flush privileges;
mysql编译和安装
./configure --prefix=/usr/local/mysql --with-charset=utf8 --with-collation=utf8_general_ci --with-extra-charsets=all --with-plugins=innobase,partition
useradd mysql -g mysql -M -s /sbin/nologin
-g:指定新用户所属的用户组(group)
-M:不建立根目录
-s:定义其使用的shell,/sbin/nologin代表用户不能登录系统。