Linux 常用命令 day2

来源:互联网 发布:mysql数据库分组查询 编辑:程序博客网 时间:2024/05/29 18:18

一、命令

1、linux 三剑客 grep、sed、awk

例子 : data.txt文件有内容   old oldboy test  

问题一:查找文件里的有关old的字符串

创建:  cat >data.txt<<EOF

old

oldboy

test

EOF

第三剑客--> grep   -v test data.txt   grep old data.txt

第二剑客--> sed -n /old/p data.txt  sed /test/d data.txt

第一剑客--> awk /old/ data.txt awk /[^test]/ data.txt


问题二: 文件有100行内容 筛选出20~30行的数据

创建文件     seq 1 100 > test.txt

1).sed -n 20,30p test.txt

2).awk '{if(NR>19&&NR<31) print $0}'


2、find

按文件名查找 find / -type f -name test.txt

将查找的结果删除    1.  find / -type f -name test.txt -exec rm -f {}  \;    

    2.  find / -type f -name test.txt | xargs rm -f 

将查找到的data.txt文件里的window字符串替换成linux

find / -type f -name data.txt | xargs sed -i s#window#linux#g



三、安装lamp

准备环境

yum添加163

地址:

http://mirrors.163.com/.help/centos.html

下载方式:

wgethttp://mirrors.163.com/.help/CentOS6-Base-163.repo

使用 yum 程序安装所需开发包(以下为标准的rpm包名称)
yum -y install gcc gcc-c++ gcc-g77 flex bison autoconf automake bzip2-develzlib-devel ncurses-devel libjpeg-devel libpng-devel libtiff-develfreetype-devel pam-devel openssl-devel libxml2-devel gettext-devel pcre-devel
mysql-devel net-snmp-develcurl-devel perl-DBI

1.安装mysql

yum -y installmysql mysql-server

自启动:
chkconfig --level 235 mysqld on


启动服务:
/etc/init.d/mysqld start

 
配置mysql的密码:
mysqladmin -u root password 123456 (
自行修改!!)

mysql的配置文件:
/etc/my.cnf

2.安装apache

yum -yinstall httpd

自启动:
chkconfig --level 235 httpd on


启动服务:
/etc/init.d/httpd start

apacheweb存放目录:
/var/www/html

apache的配置文件:
/etc/httpd/conf/httpd.conf


3.安装php

yum -y installphp

重启httpd服务激活php
/etc/init.d/httpd restart

测试php是否安装完成
vim /var/www/html/info.php

<?php
phpinfo();
?>

安装php的组件:

搜索php组件:
yum search php

安装常用组件:
yum -y install php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xmlphp-xmlrpc  php-bcmath php-mbstring

记得安装完要重启httpd服务激活组件:
/etc/init.d/httpd restart


4.一条命令安装

yum-y install gcc gcc-c++ gcc-g77 flex bison autoconf automake bzip2-develzlib-devel ncurses-devel libjpeg-devel libpng-devel libtiff-develfreetype-devel pam-devel openssl-devel libxml2-devel gettext-devel pcre-develmysql-devel net-snmp-develcurl-devel perl-DBI mysql mysql-server httpdphp php-mysql php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc  php-bcmath php-mbstring php-devel


5.安装ftp服务

http://www.linuxidc.com/Linux/2015-06/118442.htm


6.安装memcached

一、准备编译环境

在 linux 编译,需要 gcc,make,cmake,autoconf,libtool 等工具,
这几件工具, 以后还要编译 redis 等使用,所以请先装.
在 linux 系统联网后,用如下命令安装
#yum install gcc make cmake autoconf libtool

二、编译memcached

memcached 依赖于 libevent 库,因此我们需要先安装 libevent.
分别到 libevent.org 和 memcached.org 下载最新的 stable 版本(稳定版).
先编译 libevent ,再编译 memcached,
编译 memcached 时要指定 libevent 的路径.
过程如下: 假设源码在/usr/local/src 下, 安装在/usr/local 下


# tar zxvf libevent-2.0.21-stable.tar.gz
# cd libevent-2.0.21-stable
# ./configure --prefix=/usr/local/libevent
# 如果出错,读报错信息,查看原因,一般是缺少库
# make && make install
# tar zxvf memcached-1.4.5.tag.gz
# cd memcached-1.4.5
#./configure--prefix=/usr/local/memcached \
--with-libevent=/usr/local/libevent
# make && make install


7.php编译memcached扩展:

1: 到软件的官方(如 memcached)或 pecl.php.net 去寻找扩展源码并下载解压
2: 进入到 解压 目录
3: 根据当前的 php 版本动态的创建扩展的 configure 文件
#/xxx/path/php/bin/phpize \
--with-php-config=/xxx/path/php/bin/php-config
4: ./configure -with-php-config=/xxx/path/php/bin/php-config
5: make && make install
6:把生成的.so 扩展, 在 php.ini 里引入.
7:重启 apache

这里安装了 memcached-3.0.3版本 需要 libmemcached

wget https://launchpad.net/libmemcached/1.0/1.0.9/+download/libmemcached-1.0.9.tar.gz

进入解压目录

./configure --prefix=/usr/local/libmemcached --with-memcached

make && make install

遇到以下问题 

In file included from memcached/assoc.c:14:
memcached/memcached.h:18:19: error: event.h: No such file or directory

    In file included from memcached/assoc.c:14:
    memcached/memcached.h:358: error: field ‘notify_event’ has incomplete type
    memcached/memcached.h:380: error: field ‘event’ has incomplete type
    make[1]: *** [memcached/memcached_memcached-assoc.o] Error 1
    make[1]: Leaving directory `/usr/local/src/libmemcached-1.0.8'
    make: *** [all] Error 2
解决:
yum install libevent-devel

8.安装redis:
1、上 redis.io 官网 下载redis
2、解压 tar zxvf redis 
3、make 
4、make PREFIX=/path/redis install 指定安装目录
5、进去/path/redis安装目录
6、复制redis解压的目录里的 redis.conf配置文件到安装目录
7、启动redis ./bin/redis-server ./redis.conf
8、客户端连接 ./bin/redis-cli
 























0 0
原创粉丝点击