• linux命令菜鸟2.0--干货


    // 打印sql log
    $fd = fopen("/tmp/phplog.txt", "a+");
    fputs($fd,"----------------------------------------------SQL: $sql ----------------------------------- ");
    fclose($fd);

    ew
    // mysql导入库文件
    source /tmp/shop.sql;
    // 导出mysql库文件
    mysqldump -u root -p ecshop > shop.sql


    1、导出”�“™库ž�dbname的表结构(其中用‘裘�ž�root,密码ž�dbpasswd,生成的脚本名ž�db.sql)
    mysqldump -uroot -pdbpasswd -d dbname >db.sql;

    2、导出”�“™库ž�dbname某张表(test)结构
    mysqldump -uroot -pdbpasswd -d dbname test>db.sql;

    3、导出”�“™库ž�dbname所有表结构及表”�“™(不加-d)
    mysqldump -uroot -pdbpasswd dbname >db.sql;

    4、导出”�“™库ž�dbname某张表(test)结构及表”�“™(不加-d)
    mysqldump -u root -p ecshop ecs_template>ecs_template.sql;

    5、导出查询结果
    select * FROM TABLENAME INTO outfile 'TEST.TXT'

    // 压缩zip(压缩文件)
    zip -r filename.zip filesdir
    // 解压zip
    unzip filename.zip

    // 从一个目录复制文件到另一个目录
    cp -rf /root/shop/shop.zip /usr/local/htdocs

    // 把a服务器/usr/local/nginx/目录下的shop.zip复制到b服务器的tmp目录下
    scp -r /usr/local/nginx/shop.zip root@211.151.64.228:/tmp/

    // 删除shop文件夹
    rm -rf shop;

    // 重启nginx
    kill -hup `cat /opt/webapp/nginx/logs/nginx.pid`
    /opt/web/nginx/sbin/nginx -s reload

    // 重启php
    service php-fpm restart

    create database ecshop character set utf8

    // 查看jos_modules表的结构
    show create table jos_modules;

    // 查看php进程
    ps -ef|grep phplog
    // 查看nginx进程
    ps -ef|grep nginx

    // 查看错误日志
    grep "2013/08/11" error.log

    yum安装
    yum -y install wget

    安装lrzsz(rz命令没找到)
    yum -y install lrzsz

    安装vim
    yum install -y vim*


    linux安装mysql
    安装mysql客户端:
    yum install mysql
    安装mysql 服务器端:
    yum install mysql-server
    yum install mysql-revel
    数据库字符集设置
    mysql配置文件/etc/my.cnf中加入default-character-set=utf8
    启动mysql服务:
    service mysqld start或者/etc/init.d/mysqld start
    创建root管理员:
    mysqladmin -u root password Aa123qaz HypCX$123
    ph_iraq VIP Games

    linux下使用yum安装mysql
    http://www.2cto.com/database/201207/141878.html

    mysql 源码安装
    http://blog.csdn.net/dbanote/article/details/12170329


    卸载mysql
    http://blog.csdn.net/love__coder/article/details/6894566


    .tar
    解包:tar xvf FileName.tar
    打包:tar cvf FileName.tar DirName
    (注:tar是打包,不是压缩!)

    .gz
    解压1:gunzip FileName.gz
    解压2:gzip -d FileName.gz
    压缩:gzip FileName

    .tar.gz 和 .tgz
    解压:tar zxvf FileName.tar.gz
    压缩:tar zcvf FileName.tar.gz DirName

    本地获取其他机房服务器上的文件
    如远程主机的 IP 是 192.168.0.1,用户名是kyu,在命令行模式下:
    sftp kyu@192.168.0.1
    默认端口号为22,如果是其他端口号,例如22806,则使用命令:
    sftp -oPort=22806 kyu@192.168.0.1
    回车提示输入密码。
    进入提示符
    sftp>
    sftp从服务器上下载文件:
    sftp> get /var/www/kyu/index.php /home/kyu/
    sftp将本地文件上传到服务器
    sftp> put /home/fuyatao/downloads/Linuxgl.pdf /var/www/fuyatao/


    rpm安装mysql5.6以上版本
    先完全卸载mysql
    1,rpm -qa | grep -i mysql 查看系统中是否以rpm包安装的mysq
    2,卸载1查出的所有安装包 rpm -e (--nodeps) MySQL-client-5.1.49-1.glibc23
    3,查看有没有mysql服务chkconfig --list | grep -i mysql
    4,删除服务chkconfig --del mysql
    5,删除分散mysql文件夹
    whereis mysql
    rm -rf /usr/lib/mysql/
    rpm安装mysql
    1,tar xvf MySQL-5.6.13-1.linux_glibc2.5.x86_64.rpm-bundle.tar 解压MySQL-5.6.13-1.linux_glibc2.5.x86_64.rpm-bundle.tar
    2, rpm -ivh MySQL-server-5.6.13-1.linux_glibc2.5.x86_64.rpm
    3,rpm -ivh MySQL-client-5.6.13-1.linux_glibc2.5.x86_64.rpm
    4, rpm -ivh MySQL-devel-5.6.13-1.linux_glibc2.5.x86_64.rpm
    5, rpm -ivh MySQL-shared-5.6.13-1.linux_glibc2.5.x86_64.rpm
    5, rpm -ivh MySQL-shared-compat-5.6.13-1.linux_glibc2.5.x86_64.rpm
    6, rpm -ivh MySQL-embedded-5.6.13-1.linux_glibc2.5.x86_64.rpm
    7, rpm -ivh MySQL-test-5.6.13-1.linux_glibc2.5.x86_64.rpm
    8,重新启动系统 service mysql start


    查看nginx版本
    cd /usr/local/nginx/sbin
    ./nginx -v


    // 查看cap-appstore进程
    ps -ef|grep cap-appstore|grep -v grep|awk '{print $2}'
    // 干掉cap-appstore进程
    kill `ps -ef|grep cap-appstore|grep -v grep|awk '{print $2}'`
    // 赋予可执行权限
    chmod +x start_8201.sh

    // 添加,更改端口
    vi /etc/sysconfig/iptables
    service iptables restart 重启

    // 查看java进程
    ps -ef|grep java

    // 查看运行进程
    netstat -nap|grep 12005(进程号)


    SELECT REPLACE('www.mysql.com', 'w', 'Ww')
    update apk_info_from_360 set labels = REPLACE(labels,'u','\u') where labels <> ''
    update apk_info_from_360 set labels = substring_index(substring_index(str_json,'"tags":',-1),',"score"',1) where pname <> '';
    update apk_info_from_360 set labels = '' where labels like '%http:%';

    chmod +x 文件名 给文件增加可执行权限

    // root权限登录,新增用户
    insert into mysql.user(Host,User,Password) values('localhost','cvt',password('cvt123'));
    // root权限登录,给用户cvt添加oz_jf数据库的权限
    grant all privileges on oz_jf.* to cvt@% identified by 'cvt123';

    // mysql导入txt数据 如果文件存在于root目录下要加local
    load data infile "/路径/ecs_stats.txt" into table ecs_stats;

    chown -R apache.apache test.php

    修改服务器密码
    passwd

    curl -d 'post 内容' -v http://url
    // curl get请求
    curl -G -d "imsi=1231233123&lcd=480*720&version=0&format=json&channel=TYD000" http://211.151.209.102:8080/freeme/services/NewsWebService/getCategoryList

    抓包
    tcpdump host sdk.test4.g.uc.cn -w /tmp/xx4
    // 查看log
    tail /tmp/html_access.log -f |grep 404
    tail /tmp/html_access.log -f|grep "HTTP/1.0" 404"

    //查看流量
    vnstat -tr -i eth1

    SELECT * FROM oz_apk
    WHERE 'Robert Bob Smith III, PhD.' LIKE CONCAT('%',apk_name,'%')

    // link路径
    ln -s home.html index.html

    // 后台跑脚本
    nohup ./a.sh &
    nohup php xx.php &

    // iptables路径
    vi /etc/sysconfig/iptables
    // 重启iptables
    service iptables restart

    // 添加sftp账号
    useradd fengxia
    vi /etc/passwd
    8fengxia:x:503:504::/home/zhuoyou:/sbin/nologin
    cd /home/zhuoyou
    chown -R fengxia.fengxia .
    chown -R upload.apache .
    chown -R droiyunc.droiyunc .

    passwd fengxia

    useradd webuser
    passwd web123456 web654321

    // 查看数据库连接数
    show status like 'connection%';

    // 查看某一进程所占用的端口
    netstat -nap |grep 23883(进程号)

    // 重启mysql
    /etc/init.d/mysql restart

    // 查看端口占用
    netstat -anp | grep 48217

    // 查看当前文件打开进程
    lsof

    // 处理linux与windows回车不兼容
    cat 20140910.txt |col > 33.txt

    // 查看慢查询状态
    show variables like "%slow%";
    // 开启慢查询
    set global slow_query_log=on;
    select user,host,time from information_schema.processlist where user='klb';

    // linux使用memcache
    telnet 192.168.40.184 11211
    清空所有键值
    flush_all

    // 退出telnet
    ctrl+] 再输入quit

    // 判断链接是否通
    telnet localhost 8200

    // 查看端口使用情况
    netstat -na |grep 2560

    // 查看端口进程
    netstat -nap|grep 2580

    // 查看进程详情
    ps -ef|grep 8099

    // 安装nginx
    yum -y install openssl openssl-devel
    1、到www.openresty.org下载nginx
    2、解压 tar zxvf ngx_openresty-1.7.2.1.tar.gz
    3、进入到解压目录内运行下面代码(可能要先安装yum install pcre-devel)
    ./configure --prefix=/opt/web/nginx_helper
    --with-http_stub_status_module
    --with-http_iconv_module
    --with-http_gzip_static_module
    --with-luajit

    make
    make install
    4、本地查看nginx是否通了
    telnet localhost 80(如果telnet没装yum install telnet)

    //yum安装php
    yum install php
    yum install php-fpm
    设置php自启动
    chkconfig php-fpm on
    启动php
    service php-fpm start

    centos下php没有mysql扩展的话你可以直接yum install php-mysql;
    yum install php-pgsql

    //查看当前自启动程序
    chkconfig --list

    // 查看linux版本(64还是32位)
    file /sbin/init

    // 修改mysql root 密码
    mysqladmin -u root -p password 123456
    回车输入原密码

    // linux 安装pear
    wget http://pear.php.net/go-pear.phar
    php go-pear.phar
    pear 查看所有pear相关命令
    pear list 查看已经安装的package
    pear config-show 查看pear的配置
    pear config-get 查看某项配置
    pear config-set 设置某项配置

    // 压力测试步骤
    lua market_bench.lua 101013 1 debug
    ln -s body.101013.out _body.bin

    // ab压力测试
    ab -c 200 -n 10000 -p body.101013.out http://192.168.0.81:2560/

    // 安装aapt(前提是有apktool1.5.2.tar.bz2和apktool-install-linux-r05-ibot.tar.bz2这两个包)
    tar -xjf apktool1.5.2.tar.bz2
    tar -xjf apktool-install-linux-r05-ibot.tar.bz2
    cp apktool1.5.2/apktool.jar apktool-install-linux-r05-ibot/aapt /bin safe_modephp
    cp apktool-install-linux-r05-ibot/apktool /bin
    chmod 755 /bin/apktool.jar /bin/aapt /bin/apktool
    yum -y install glibc.i686 zlib.i686 libstdc++.i686 (在安装libstdc++.i686可能会有问题,32位和64位的库版本要一致)
    所以先更新
    yum update libstdc++-4.4.7-3.el6.x86_64
    再yum -y install libstdc++.i686


    // linux查找某个字符在哪个文件中(180.168.41.175是字符)
    find ./ -name "*" -exec grep 180.168.41.175 {} ; -print

    // 重启映射254
    先找到rinetd的进程,kill掉再执行下面命令
    rinetd -c /etc/rinetd.conf

    // 解决nginx启动时报下面的错误 /opt/web/nginx/sbin/nginx -c /opt/web/nginx/conf/nginx.conf
    nginx: [error] open() "/opt/web/nginx/logs/nginx.pid" failed (2: No such file or directory)

    // ftp远程传输目录
    lftp -u tydtech.com,4skxj0olo64w -e "mirror -R --verbose /home/html/mfiles/apks/ /newmarket1.kk874.com/mfiles/apks/" ftp://src1.ftp.cachecn.net
    lftp -u tydtech.com,4skxj0olo64w -e "mirror -R --verbose /home/lsz
    html/mfiles/icons/ /newmarket1.kk874.com/mfiles/icons/" ftp://src1.ftp.cachecn.net
    lftp -u tydtech.com,4skxj0olo64w -e "mirror -R --verbose /home/html/mfiles/channels/ /newmarket1.kk874.com/mfiles/channels/" ftp://src1.ftp.cachecn.net
    lftp -u tydtech.com,4skxj0olo64w -e "mirror -R --verbose /home/html/mfiles/imgs/ /newmarket1.kk874.com/mfiles/imgs/" ftp://src1.ftp.cachecn.net

    lftp -u tydtech.com,4skxj0olo64w -e "mirror -R --verbose /home/html/market/ /newmarket.kk874.com/market/" ftp://src1.ftp.cachecn.net

    nohup lftp -u tydtech.com,4skxj0olo64w -e "mirror -R --verbose /home/html/mfiles/icons/ /newmarket1.kk874.com/mfiles/icons/" ftp://src1.ftp.cachecn.net &
    lftp -u tydtech.com,4skxj0olo64w -e mirror -R --verbose /home/html/mfiles/ /newmarket1.kk874.com/mfiles/ 113.31.27.247

    nohup lftp -u tydtech.com,wIegW87y+ -e "mirror -R --verbose /opt/data/html/181/mfiles/channels/360/apks/2015/11/14/ /newmarket1.kk874.com/mfiles/channels/360/apks/2015/11/14/" ftp://src.ftp.tydtech.cachecn.net &


    //重启haproxy
    /usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/conf/haproxy_market.cfg
    /usr/local/sbin/haproxy -f /usr/local/conf/haproxy_market.cfg

    // 清除mysql链接数
    以root登录mysql flush hosts 命令
    // 赋予ip为192.168.40.183的服务器访问本服务器上的mysql权限,账号为market_log,密码为xde34fs
    GRANT ALL PRIVILEGES ON *.* TO 'market_log'@'192.168.40.182' IDENTIFIED BY 'xde34fs' WITH GRANT OPTION;
    GRANT ALL PRIVILEGES ON *.* TO 'market_log'@'192.168.40.183' IDENTIFIED BY 'xde34fs' WITH GRANT OPTION;
    GRANT ALL PRIVILEGES ON *.* TO 'market_ip'@'192.168.40.181' IDENTIFIED BY 'xkdeig' WITH GRANT OPTION;
    GRANT select,insert,update,delete ON oz_stats.* TO 'market_stats'@'192.168.40.190' IDENTIFIED BY 'jdnhe937' WITH GRANT OPTION;
    // 开放平台
    GRANT ALL PRIVILEGES ON *.* TO 'open'@'localhost' IDENTIFIED BY 'xnejd82je' WITH GRANT OPTION;
    GRANT ALL PRIVILEGES ON *.* TO 'market_stats'@'localhost' IDENTIFIED BY 'jdnhe937' WITH GRANT OPTION;
    GRANT ALL PRIVILEGES ON zy_cms.* TO 'zy_cms'@'localhost' IDENTIFIED BY 'jshfue874f' WITH GRANT OPTION;

    GRANT ALL PRIVILEGES ON *.* TO 'market_act'@'192.168.40.104' IDENTIFIED BY '283jue7mne' WITH GRANT OPTION;

    GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.3.%' IDENTIFIED BY '123456' WITH GRANT OPTION;
    GRANT ALL PRIVILEGES ON *.* TO 'root'@'10.0.10.%’ IDENTIFIED BY '123456' WITH GRANT OPTION;

    GRANT ALL PRIVILEGES ON *.* TO 'os_user'@'localhost' IDENTIFIED BY 'mxnhd874nh' WITH GRANT OPTION;

    GRANT ALL PRIVILEGES ON *.* TO 'open'@'192.168.40.%' IDENTIFIED BY 'xnejd82je' WITH GRANT OPTION;

    GRANT ALL PRIVILEGES ON *.* TO 'cmp'@'192.168.40.%' IDENTIFIED BY 'cmp123' WITH GRANT OPTION;

    GRANT ALL PRIVILEGES ON *.* TO 'gc_user'@'192.168.40.%' IDENTIFIED BY 'gcsolr123' WITH GRANT OPTION;

    GRANT ALL PRIVILEGES ON *.* TO 'market_log'@'192.168.40.%' IDENTIFIED BY 'xde34fs' WITH GRANT OPTION;
    GRANT ALL PRIVILEGES ON *.* TO 'market_log'@'localhost' IDENTIFIED BY 'xde34fs' WITH GRANT OPTION;
    GRANT ALL PRIVILEGES ON *.* TO 'charging'@'192.168.40.%' IDENTIFIED BY 'bdnse8364' WITH GRANT OPTION;

    GRANT select ON test.* TO 'test'@'localhost' IDENTIFIED BY '123456' WITH GRANT OPTION;

    grant select on oz_market.* to 'db_user'@'192.168.40.%' identified by 'xhsje832';

    GRANT ALL PRIVILEGES ON *.* TO 'xwq'@'192.168.40.%' IDENTIFIED BY 'mejdus23' WITH GRANT OPTION;
    grant select,update,delete,insert on oz_market.* to db_user;

    // 查看mysql链接情况
    show processlist
    // 查看当前并发量
    netstat -na|grep ESTA -c

    // 启动http
    service httpd start
    // http指定路径
    vi /etc/httpd/httpd.conf

    // 查看流量
    vnstat -i em1 -tr

    // locate不生效
    yum -y install mlocate
    updatedb
    locate my.cnf

    //redis基本操作
    redis-cli -p 6300
    auth Yt&UBBwRpFIV87mEontY
    select 1(选择数据库)
    dbsize(数据库中的数据量)

    // 产看硬盘信息
    fdisk -l

    SELECT CONCAT( 'drop table ', table_name, ';' ) FROM information_schema.tables WHERE table_name LIKE 'oz_market_visit_rec_%';

    //mysql初始密码保存文件
    /root/.mysql_secret

    //创建数据库指定编码
    create database zg_log character set utf8;

    // 查看mysql主从数据库同步状态
    show slave statusG;

    // 通过进程号查看服务
    ps axu|grep 20598(进程号)

    // 去除重复行
    cat 360_labels.txt | sort -u > tt.txt


    // 同步linux时间为北京时间
    先安装ntp
    yum install ntp
    /etc/init.d/ntpd start
    再执行ntpdate ntp.api.bz

    // wget
    -m 镜像:相当于同时使用-r和-N参数。
    -c 断点续传(备注:使用断点续传要求服务器支持断点续传),
    -r 递归下载(目录下的所有文件,包括子目录),
    -np 递归下载不搜索上层目录,
    -k 把绝对链接转为相对链接,这样下载之后的网页方便浏览。
    -L 递归时不进入其他主机,
    -p 下载网页所需要的所有文件。

    -b:后台下载,Wget默认的是把文件下载到当前目录
    wget -b -c -r -np -k -L -p http://192.168.40.181:1081/logo/
    wget -b -m http://192.168.40.181:1081/logo/
    nohup wget -c -t0 -T120 -i list.txt &
    nohup wget -m http://192.168.40.181:1081/market/ &
    nohup wget -m http://192.168.40.180:1081/market/ &


    //查看iPhone在act_logs.log中出现的记录
    grep -i 'iPhone' act_logs.log
    //查看/opt/websvr/nginx/conf下的所有文件中包含8080字符的文件
    grep -R "8080" /opt/websvr/nginx/conf

    aapt dump badging XiaoMeiXV2.0_XiaoMeidy_27.apk
    // 查看服务器当前链接情况
    netstat -na |grep ESTA |grep 80|grep -v 8080 |awk '{print $5}'|sort
    // 查看8080端口的当前连接数(-c)
    netstat -na |grep ESTA |grep 8080
    netstat -na |grep ESTA |grep 80|grep -v 8080 |awk '{print $5}'|sort
    // 查看文件行数
    I -l sms_recv_history_20150301.txt

    // mysql数据目录迁移
    1. service mysqld stop
    2. 在/app 下新建一个目录mysqldir : mkdir mysqldir #在新分区上建立mysqldir目录
    3. cd /usr/local/mysql && cp -r /app/mysqldir 新数据拷到新目录mysqldir下
    4. rm -rf mysql //把原来的数据目录删掉
    5 ln -s /app/mysqldir mysql
    6. service mysqld start
    本以为没啥问题,运行第6条命令后发现mysql起不来,所如下错误:
    Starting MySQL. ERROR! Thequit without updating PID file (/usr/local/mysql/data/AY13121220352352963dZ.pid).
    运行service mysqld status输出如下提示信息:
    ERROR! MySQL is not running, but lock file (/var/lock/subsys/mysql) exists
    ok 这个问题应该很常见了,我的解决办法是运行如下命令:
    1. chown -R mysql:mysql /app/mysqldir #设置新目录权限归mysql用户所有
    2. rm -f /var/lock/subsys/mysql
    再执行service mysqld start 大功告成
    这时候有可能还不行,这是要关闭selinux
    1、vi /etc/selinux/config 将中的SELINUX=enforcing改成SELINUX=disabled,然后保存,这时候的selinux是没有生效的,要重启mysql后才会生效
    #SELINUX=enforcing
    SELINUX=disabled
    2、执行setenforce 0
    3、执行sestatus -v,查看2操作是否生效
    4、启动mysql,这样就ok了

    补充:做软链接
    如果这一步不做,mysql可以启动,但是网站的数据库链接会报错:
    Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'
    做链接的命令如下:
    ln -s /usr/mysql/mysql.sock /var/lib/mysql/mysql.sock
    最后,打开mysql服务,一切OK


    【注意】,更改mysql的sock目录后,可能原来的php链接mysql会失败,因为php.ini中的mysql.default_socket = 是默认是没有设置路径的,这是后需要将php.ini中的mysql.default_socket = /opt/mysql/mysql.sock(迁移mysql后的sock路径,同/etc/my.conf中的路径)
    然后在重启php-fpm,service php-fpm start


    SELECT concat('drop table ',TABLE_NAME,';') FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_SCHEMA = 'oz_log' and TABLE_NAME like 'oz_market_visit_rec%' into outfile '/tmp/drop_oz_market_visit_rec.sql';

    //拉包时php未安装mbstring.so
    PHP Fatal error: Call to undefined function mb_detect_encoding() in /opt/applet/capture/1mobile/simple_html_dom.php on line 1234
    yum install php-mbstring

    //修复表
    repair table stats;

    insert into sms_recv_history (phone,content,sentdate) select phone,content,sentdate from test;

    // 查看mysql进程等待时间
    show global variables like'wait_timeout';
    // 设置mysql进程等待时间
    set global wait_timeout=10;

    // linux 安装sqlite
    1.源码安装步骤如下:
    1)wget http://www.sqlite.org/sqlite-3.5.6.tar.gz
    2)tar -xzvf sqlite-3.5.6.tar.gz
    3)cd sqlite-3.5.6
    4)./configure --disable-tcl ##加上这个选项则不需要TCL,否则在2.4内核上编译通不过
    5)make
    6)make install

    2.测试是否安装成功
    # cd /usr/lcoal/bin
    # ./sqlite3 text.db
    如果安装成功,会出现下面这样的信息
    SQLite version 3.5.6
    Enter ".help" for instructions
    sqlite>


    抓包
    adb shell
    su
    cd /data/local
    .tcp.sh
    pull /sdcard/capture.pcap push3.pcap

    验证configuration情况:identify -list configure
    验证支持的图片格式:identify -list format
    // 命令直接转图片大小
    convert -resize 100x100 6.jpg 66.jpg

    //单独启动solr
    java -Djetty.port=2571 -jar start.jar

    // vnstat 带宽查询
    vnstat -tr -i em1


    vi /etc/hosts
    添加 Beijingny003

    通过vi /etc/security/limits.conf 添加如下配置参数:修改之后保存,注销当前用户,重新登录,通过ulimit -a 查看修改的状态是否生效。

    * soft  nofile  1000000
    * hard  nofile  1000000
    需要指出的是,尽管我们可以将单个进程打开的最大句柄数修改的非常大,
    但是当句柄数达到一定数量级之后,处理效率将出现明显下降,因此,需要根据服务器的硬件配置和处理能力进行合理设置。如果单个服务器性能不行也可以通过集群的方式实现。


    镜像同步
    rsync相关信息如下:
    rsync帐号:tydtech.com
    rsync密码:wIegW87y+
    rsync同步模块:rsync_tydtech_com
    rsync传输文件可通过:rsync -auzv 文件名 tydtech.com@src.ftp.tydtech.cachecn.net::rsync_tydtech_com/ 输入密码上传即可
    rsync_tydtech_com 这个模块对应的目录是tydtech.com/
    tydtech.com/ 这个目录下有对应目录
    newmarket1.kk874.com newmarket.kk874.com
    请将文件传至对应域名的路径下即可~

    快网ftp
    src1.ftp.cachecn.net
    src.ftp.tydtech.cachecn.net
    ftp账号:tydtech.com
    密码:4skxj0olo64w

    ftp src1.ftp.cachecn.net

    // url直接跳转至appstore
    itms-apps://itunes.apple.com/cn/app/jie-zou-da-shi/id493901993?mt=8

    // linux 打jar包(进入文件目录内)
    jar cf xxx.jar *
    // 解压jar包
    jar -xvf xxx.jar

    //
    netstat -pant |awk '/^tcp/ {++state[$6]} END {for(key in state) printf("%-10s %d ",key,state[key]) }'
    // 查看http的并发请求数及其TCP连接状态的linux命令
    netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a, S[a]}'


    Mac安装Brew
    安装命令如下:
    curl -LsSf http://github.com/mxcl/homebrew/tarball/master | sudo tar xvz -C/usr/local --strip 1

    当brew安装成功后,就可以随意安装自己想要的软件了,例如wget,命令如下:
    sudo brew install wget

    卸载的话,命令如下:
    sudo brew uninstall wget

    查看安装软件的话,命令如下:
    sudo brew search /apache*/

    注意/apache*/是使用的正则表达式,用/分割。

    siege压力测试方式
    siege -c 20 -r 2 -f www.chedong.com.url
    siege -c 100 -t 1s -f http://192.168.0.81:8889/feedback
    参数说明:
    -c 20 并发20个用户
    -r 2 重复循环2次
    -f www.chedong.com.url 任务列表:URL列表

    linux处理-开头文件
    rm -- -filename
    查看端口占用
    lsof -i:80


    ubuntu上安装mysql非常简单只需要几条命令就可以完成。
    1. sudo apt-get install mysql-server
    2. apt-get isntall mysql-client
    3. sudo apt-get install libmysqlclient-dev


    rsync -auzv --bwlimit=10000 --password-file=passwd.txt 14/ tydtech.com@113.31.27.247::rsync_tydtech_com/newmarket1.kk874.com/mfiles/channels/360/apks/2015/11/14/ > rsync_14.log 2>&1 &

    文件传输
    scp /Users/wangqi/Downloads/en_sql_server_2014_business_intelligence_with_service_pack_1_x64_dvd_6668451.iso root@10.0.10.209:/tmp/
    scp root@121.40.79.40:/tmp/avcp_work.zip /tmp/

    安装postgresql
    yum install postgre*
    初始化postgre
    service postgresql initdb
    启动postgresql
    /etc/init.d/postgresql start
    切换系统用户postgres
    su postgres
    创建数据库:createdb -h 127.0.0.1 -p 5432 -U postgres testdb
    连接数据库:psql -h 127.0.0.1 -p 5432 -U postgres testdb
    删除数据库:dropdb -h 127.0.0.1 -p 5432 -U postgres testdb
    说明:-h表示主机(Host),-p表示端口(Port),-U表示用户(User)
    创建数据表:create table tbl(a int);
    删除数据表:drop table tbl;
    插入数据:insert into tbl(a) values(1);
    查看数据:select * from tbl;
    备份数据库:pg_dump -U postgres testdb > d:/testdb.dmp
    pg_dump -U postgres avcp_work -t vs_user_rank > /tmp/vs_user_rank.dmp
    恢复数据库:psql -U postgres testdb < d:/testdb.dmp
    q 退出postgresql数据库,建议使用?查看帮助信息!
    passwd postgres 设置密码
    createuser dbuser with password '123456'
    访问postgresql:psql -U dbuser -d test -h 127.0.0.1 -p 5432
    查看所有库:l
    查看所有表: dt
    查看某个表的结构: d 表名
    更改数据库字段类型: alter table vs_shower_cash_exchange_log alter column remain_num type numeric(12,2) DEFAULT 0 NOT NULL;
    SELECT DISTINCT
    a.attnum as num,
    a.attname as name,
    format_type(a.atttypid, a.atttypmod) as typ,
    a.attnotnull as notnull,
    com.description as comment,
    coalesce(i.indisprimary,false) as primary_key,
    def.adsrc as default
    FROM pg_attribute a
    JOIN pg_class pgc ON pgc.oid = a.attrelid
    LEFT JOIN pg_index i ON
    (pgc.oid = i.indrelid AND i.indkey[0] = a.attnum)
    LEFT JOIN pg_description com on
    (pgc.oid = com.objoid AND a.attnum = com.objsubid)
    LEFT JOIN pg_attrdef def ON
    (a.attrelid = def.adrelid AND a.attnum = def.adnum)
    WHERE a.attnum > 0 AND pgc.oid = a.attrelid
    AND pg_table_is_visible(pgc.oid)
    AND NOT a.attisdropped
    AND pgc.relname = 'vs_gift_info'
    ORDER BY a.attnum;

    选择某个database:c “database”
    查看建标语句(类似于mysql的手腕show create table)
    ./pg_dump -U avcp_work -s -d avcp_work -t avcp_action_permission

    创建用户
    createuser -h 127.0.0.1 -p 5432 -drSP select_videio
    createuser -h 10.117.55.89 -p 5432 -drSP avcp_work
    postgresql内网服务器访问配置pg_hba.conf,postgresql.conf
    访问postgre
    psql -h 127.0.0.1 -U avcp_work avcp_work

    // jdk安装
    rpm -ivh jdk-7u25-linux-x64.rpm
    vi /etc/profile
    export JAVA_HOME=/usr/java/jdk1.7.0_25
    PATH=$JAVA_HOME/bin:$PATH
    source /etc/profile

    // mono
    網上說安裝Mono之前必須要先安裝這些包:
    gcc gcc-c++ bison pkgconfig glib2-devel gettext make libpng-devel libjpeg-devel libtiff-devel libexif-devel giflib-devel libX11-devel freetype-devel fontconfig-devel cairo-devel
    由於本人在安裝CentOS 6.3的時候選擇的是Development模式,想必這些包都已經默認安裝在內了,但為了安全起見還是使用rpm命令對其一個個做了檢測確保已經安裝過,檢測命令大致如下:
    # rpm -qa libexif*
    經過一輪檢測,發現確實有幾個漏網之魚,遂使用 yum install 將其一一安裝到位。
    下載安裝mono 3.0.12
    # cd /usr/local/src
    wget http://download.mono-project.com/sources/libgdiplus/libgdiplus-2.10.tar.bz2
    tar -jxvf libgdiplus-2.10.tar.bz2
    cd libgdiplus-2.10
    ./configure --prefix=/usr
    make && make install
    # wget http://download.mono-project.com/sources/mono/mono-3.0.12.tar.bz2
    # tar -jxvf mono-3.0.12.tar.bz2
    # cd mono-3.0.12
    # ./configure --prefix=/usr
    # make && make install
    漫長的等待之後,調用下mono看看吧。進入/usr/lib/mono 目錄就可以看到熟悉的.NET程序集咯...

    解决no input file specifiled
    1、更改php.ini cig.fix_pathinfo=0改为cig.fix_pathinfo=1


    开发步骤
    git clone http://10.128.112.2:3000/droi/lua.git
    git add 修改過的檔案
    git commit –m ‘修改檔案註釋’
    git push这时候输入账号密码,文件提交成功

    git建库
    git clone git@120.26.224.211:/opt/git/pingku.git

    check
    curl -X POST -H "Content-Type:application/json"​ -d @input.json http://10.128.112.80:8000/add.lua


    http://newmarket.oo523.com:8080/market/apkupdate/2015/01/29/roz84gac7h/SecurityService.apk

    lsof -i :7892

    // mysql主备问题
    flush logs;
    show master status;

    // master_log_file是master的mysql-bin文件
    reset slave;
    change master to master_host='192.168.40.186', master_user='repl', master_password='repl123456', master_port=3306,master_log_file='mysql-bin.017679', master_log_pos=1;


    DELIMITER $$
    CREATE FUNCTION `nextval`(seq_name varchar(50))
    RETURNS decimal(10,0)
    begin
    declare ret INT(10);
    update oz_sequence set current_value=current_value+increment where name=seq_name; select current_value into ret from oz_sequence where name=seq_name;
    return ret;
    END $$
    DELIMITER;

    maven使用
    安装环境变量
    vim打开/etc/profile文件 加入如下代码:
    export M2_HOME=/Users/wanyakun/Documents/apache-maven-3.2.3
    export PATH=$PATH:$M2_HOME/bin

    编译(进入工程项目 cd xxx/avcp-dms):mvn compile

    search.maven.org

    // maven安装本地包
    —dms
    mvn install:install-file -Dfile=/Users/wangqi/.m2/repository/com/skymobi/avcp-dms-base/1.002/avcp-dms-base-1.002.jar -DgroupId=com.skymobi -DartifactId=avcp-dms-base -Dversion=1.002 -Dpackaging=jar

    mvn install:install-file -Dfile=/Users/wangqi/.m2/repository/com/skymobi/avcp-common/1.024/avcp-common-1.024.jar -DgroupId=com.skymobi -DartifactId=avcp-common -Dversion=1.024 -Dpackaging=jar

    mvn install:install-file -Dfile=/Users/wangqi/.m2/repository/com/skymobi/avcp-file/1.002/avcp-file-1.002.jar -DgroupId=com.skymobi -DartifactId=avcp-file -Dversion=1.002 -Dpackaging=jar

    mvn install:install-file -Dfile=/Users/wangqi/.m2/repository/avcp-session-skyuserinfo/avcp-session-skyuserinfo/2.000/avcp-session-skyuserinfo-2.000.jar -DgroupId=avcp-session-skyuserinfo -DartifactId=avcp-session-skyuserinfo -Dversion=2.000 -Dpackaging=jar

    —das
    mvn install:install-file -Dfile=/Users/wangqi/.m2/repository/com/skymobi/avcp-common/1.021/avcp-common-1.021.jar -DgroupId=com.skymobi -DartifactId=avcp-common -Dversion=1.021 -Dpackaging=jar

    mvn install:install-file -Dfile=/Users/wangqi/.m2/repository/skymobi/skymobi-ssh3-extend/1.0.1/skymobi-ssh3-extend-1.0.1.jar -DgroupId=skymobi -DartifactId=skymobi-ssh3-extend -Dversion=1.01 -Dpackaging=jar

    // yum安装memcache
    yum search memcached
    yum -y install memcached
    memcached -d -u root -m 768 -c 4096 -p 11211
    验证安装结果
    memcached -h
    php -m | grep memcache

    安装redis
    yum install redis
    如果出错先wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
    rpm -ivh epel-release-6-8.noarch.rpm
    再yum install redis
    安装php-redis扩展
    yum install php-redis
    启动redis,并设定开机自动启动
    service redis start
    chkconfig redis on

    ucmq

    将ucmq.ini文件http_listen_addr=192.168.3.171这个地址改为真实内网地址,或者直接0.0.0.0
    将output_log_level=DEBUG 改为INFO 不然log非常大
    /usr/local/ucmq/bin/ucmq -c /usr/local/ucmq/conf/ucmq.ini -d

    fastdfs
    解压FastDFS_v4.06.tar.gz
    cd FastDFS
    ./make.sh
    ./make.sh install
    /usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf

    //mongo
    yum -y install mongodb-server mongodb
    service mongod start #启动mongodb 服务
    pstree -p | grep mongod #进程列表
    chkconfig mongod on #开机启动mongod服务

    yum install glibc.i686(mongo启动时会出现/lib/ld-linux.so.2: bad ELF interpreter: No such file or directory)
    /usr/local/mongodb/bin/mongod -dbpath=/opt/db_data/mg_data/data -logpath=/opt/db_data/mg_data/logs/mongodb.log -logappend&


    // whatprovides 查看yum哪个包包含想要的库
    yum whatprovides libstdc++.so.6

    //mongo
    // 建database
    use avcp
    // 查看database(show databases)
    show dbs
    // 查看某database的表
    show collections
    //导入bson文件
    ./mongorestore --port 5282 -d avcp /opt/tmp/WasuForm.bson
    // 访问mongo
    ./mongo -port 5282

    // 查看服务对应的端口 比如:redis
    netstat -lnp|grep redis

    // mac下启动php
    //postgre 复制表
    select * into avcp_user_access_log_201603 from avcp_user_access_log where 1=0;

    // Linux查看文件 按时间排序
    ll -rt
    // linux全局替换文件
    sed -i 's/172.22.1.158:18081/120.26.218.80:2201/' *.ftl
    sed -i 's/10.117.49.245/192.168.0.248/' config.properties
    sed -i 's/10.51.11.158/192.168.0.248/' config.properties
    sed -i 's/10.168.104.77/192.168.0.248/' config.properties

    sed -i 's/10.117.49.245/192.168.0.248/' jdbc.properties
    sed -i 's/10.51.11.158/192.168.0.248/' jdbc.properties
    sed -i 's/10.168.104.77/192.168.0.248/' jdbc.properties


    sed -i 's/120.26.129.44/192.168.0.248/' config.properties

    sed -i 's/10.168.104.77/10.168.30.15/' context.xml
    sed -i 's/10.168.104.77/10.168.30.15/' jdbc.properties

    grep -R "10.117.49.245" ./
    sed -i 's/10.117.49.245/10.117.62.141/' jdbc.properties
    grep -R "10.168.30.15" ./
    sed -i 's/10.168.30.15/10.117.62.141/' jdbc.properties

    sed -i ’s/1.4.1/1.6.2/‘ latest


    // 同步
    rsync -auzv /opt/data/html/180/180/apk/2016/03/18/lwp4w2sutl/10003411_cf-v50-v1_0_6_0-76-2016-03-14-16-30_p.apk tydtech.com@113.31.27.247::rsync_tydtech_com/XXXXX路径

    // linux安装ftp
    rpm -qa |grep vsftpd
    yum install vsftpd
    service vsftpd start

    // poster导出数据库
    ./psql -U postgres avcp_work >/tmp/a_work

    // postgresql导出某张表数据
    copy avcp_banner to '/tmp/avcp_banner.txt';
    // postgresql导入某张表数据
    copy avcp_banner from '/tmp/avcp_banner.txt';


    // 查看pg建表语句
    ./pg_dump -U avcp_work -s -d avcp_work -t avcp_banner

    // 查看进程数
    netstat -anpo | grep "java"| wc -l

    转图片颜色:find . -name '*.png' -exec convert {} -fuzz 10% -fill 'rgb(255,0,0)' -opaque 'rgb(232,42,131)' {} ;

    // 导出查询结果
    avcp_work=> o /tmp/xx.txt
    avcp_work=> select b.sky_id as 主播id,
    avcp_work-> a.create_date,
    avcp_work-> c.id as 房间号,
    avcp_work-> b.nick_name as 主播昵称,
    avcp_work-> a.live_time as 开播时长_分钟
    avcp_work-> from vs_rp_shower_daily_info a
    avcp_work-> left join avcp_user_info b
    avcp_work-> on a.vs_id = b.sky_id
    avcp_work-> left join avcp_room_info c
    avcp_work-> on a.vs_id = c.sky_id
    avcp_work-> where a.live_time >0 and a.create_date >= '2016-08-01' and a.create_date <= '2016-08-31'
    avcp_work-> order by b.sky_id,a.create_date,a.live_time desc;


    715

    beego依赖的第三方包有如下:
    session模块:github.com/astaxie/beego/session
    session模块中支持redis引擎:github.com/garyburd/redigo/redis
    session模块中支持mysql引擎:github.com/go-sql-driver/mysql
    模板函数中支持markdown转化:github.com/russross/blackfriday

    csv导出:

    <sql>
    show variables like '%secure%'; #查询mysql可操作目录

    select * from `database`.`tablename`
    where TradingDay='20170419'
    into outfile '/path/table.csv'
    fields terminated by ','
    optionally enclosed by '"'
    lines terminated by' ' ;
    </sql>

    csv导入:

    <sql>
    show variables like '%secure%'; #查询mysql可操作目录,把之前生成的csv复制进此目录下

    load data infile '/path/table.csv'
    into table `database`.`tablename`
    fields terminated by ','
    optionally enclosed by '"'
    lines terminated by ' ';
    </sql>


    yum clean all
    yum makecache

    阿里云服务器漏洞修复
    https://blog.csdn.net/qiuqiuLovecode/article/details/77745418?locationNum=6&fps=1

    查看系统位数32/64:getconf LONG_BIT
    查看内核版本:uname -r
    列出所有版本信息:lsb_release -a

    22端口开放
    /etc/init.d/sshd start
    如果提示no such file or directory 则需要安装ssh :yum install openssl-server

    阿里云centos6.5安装docker
    https://blog.csdn.net/xingkong22star/article/details/46925365
    解决centos yum update更新系统时出错"package is a duplicate with"
    列出重复的包:package-cleanup --dupes
    删除重复的包:package-cleanup --cleandupes


    CentOS7.4默认数据库为mariadb可以使用yum安装MySQL5.6
    wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm
    rpm -ivh mysql-community-release-el7-5.noarch.rpm
    yum install mysql-community-server
    service mysql start
    mysqladmin -uroot -p password new_password


    列举匹配已安装的java的软件包:yum list installed | grep java

    centos7.4安装jdk
    yum list installed|grep java
    yum -y list java*
    yum -y install java-1.8.0-openjdk*
    java -version

    show variables like '%secure%';

  • 相关阅读:
    webapi 中使用 protobuf
    apache httpclient cache 实现可缓存的http客户端
    编译nginx时提示undefined reference to 'pcre_free_study' 的问题及解决
    深入理解JVM内存回收机制(不包含垃圾收集器)
    从JDK源码理解java引用
    Buffer的创建及使用源码分析——ByteBuffer为例
    二叉树的子结构、深度以及重建二叉树
    数据结构——树与二叉树的遍历
    Java NIO之Buffer的使用
    Java多线程之synchronized详解
  • 原文地址:https://www.cnblogs.com/Darkqueen/p/9850640.html
Copyright © 2020-2023  润新知