LINUX环境搭建及常用SHELL命令集锦
Linux环境搭建及常用shell命令集锦 .................................................................................................... 1 一:linux下安装jdk(安装版本:jdk-7u71-linux-x64.rpm) ....................................................... 4
1.先卸载服务器自带的jdk软件包 ........................................................................................ 4 2.使用rpm命令安装 ................................................................................................................... 5 3.配置环境变量 .............................................................................................................................. 5 4.使配置文件立即生效 ................................................................................................................ 5 5.由于系统中可能会有默认的其他版本JDK,所以,为了将我们的JDK设置为默认的JDK版本,还要进行如下工作 ...................................................................................... 5 6.执行下面命令,设置默认版本,此命令结束后,系统会列出当前存在的各种JDK版本,会提示你选择 .......................................................................................................... 5 7.测试是否安装成功 .................................................................................................................... 5 二:linux下安装tomcat7................................................................................................................... 5
1.下载jdk 1.7 .................................................................................................................................. 5 2.存放并解压jdk ........................................................................................................................... 6 3.tomcat7安装 ............................................................................................................................... 6 三.linux下安装Oracle 11g详细过程 ............................................................................................. 6
1.安装环境 ........................................................................................................................................ 6 2.解压缩 ............................................................................................................................................. 6 3.操作系统版本及补丁矩阵 ...................................................................................................... 6 4.网络、系统参数调整及说明 ................................................................................................. 7 5.目录结构及空间规划 ................................................................................................................ 8 6 ,数据库软件的安装和数据库的创建配置 ................................................................... 8 7,开始安装 .................................................................................................................................... 9 8,创建数据库 ............................................................................................................................. 10 四.linux下创建FTP用户和密码(ftp为vsftp) ................................................................... 10
1.root用户下创建用户 ............................................................................................................. 10 2.更改用户相应的权限设置 .................................................................................................... 10 3.限制用户只能访问/home/test,不能访问其他路径 ................................................... 10 4.如果容许用户修改密码,但是又没telnet登录系统的权限................................. 10 五.linux下备份,部署项目(以TNB项目为例) ................................................................. 11 六.工作中经常用到的linux shell命令总结 ............................................................................... 11
1.ctrl+A ---返回最前边的字符 ................................................................................................ 11 2.ctrl+R ---查询history时,提示用过的command .................................................... 11 3.vi中移动到行头,按数字0,移动到行尾按$即可 .................................................. 11 4.wget httpd://afdasfd.com 或者svn co httpd.//name.com 或者svn export url都可以下载 ............................................................................................................................. 11 5.vi&vim .......................................................................................................................................... 11 6.More阅读命令: ..................................................................................................................... 11 7.cp file1 file2 复制文件 ........................................................................................................ 12 8.less 阅读命令 ............................................................................................................................ 12 9.cat 阅读命令 ............................................................................................................................. 12 10.>file 清空文件内容 .............................................................................................................. 12 11.mv file file2 修改文件名称 ............................................................................................... 12 12.mv file ../file 修改文件路径 ............................................................................................. 12 13.find ./ -iname ‘file’ 查找文件名为file的路径,不区分大小写 ........................ 12 14.find ./ -name ‘file’ 查找文件名为file的路径,区分大小写 .............................. 12 15.head -20 file 取前30行并浏览 ...................................................................................... 12 16.tail -30 file 取末30行 ........................................................................................................ 12 17.history历史命令 ................................................................................................................... 12 18.修改已创建文件的时间 touch -c -t 0906270730 file ............................................ 12 19.mkdir file 创建新文件 ........................................................................................................ 12 20.wc –l file 统计行数............................................................................................................... 12
21.中文乱码的问题解决: ...................................................................................................... 12 22.crontab –l 查看crontab命令行 ..................................................................................... 13 23.重定向 ........................................................................................................................................ 13 24.ps –eaf | grep httpd 查找httpd进程 ........................................................................... 13 25.kill -9 PID 强制停止进程 ................................................................................................... 13 26.rpm –ivh a.rpm 安装rpm包 ........................................................................................... 13 27.chmod 111(可执行)/222(可读)/444(可写) file 权限 ........................................ 13 28.修改linux颜色 在vim .bash_profile里添加export
PS1=\
\\[\\033[1;35m\\]\\W\\[\\033[0m\\]]\\\\$\............................................................................... 13 29.syntax off可以vi下取消高亮显示语法。Syntax on可以显示 ........................ 13 30.su – username 切换用户账号 ....................................................................................... 13 31.top 显示进程完整路径和名称。 ................................................................................... 13 32.hostname 显示系统当前主机名和域名 ...................................................................... 13 33.date系统时间 ......................................................................................................................... 13 34.cal日历 ...................................................................................................................................... 13 35.pwd 绝对路径 ........................................................................................................................ 13 36.diff file1 file2 比较两文件................................................................................................. 13 37.vimdiff file1 file2 ................................................................................................................... 13 38.du file –k 显示文件大小 .................................................................................................... 14 39.tail –f file 动态查看文件内容 ..................................................................................... 14 40.grep ‘title’ file 在文件file中搜索带title的行 ......................................................... 14 41.grep ‘title’ file -10在文件file中搜索带title的行,并打印出上下10行内容 ............................................................................................................................................................. 14 42.sed –e ‘s/a/b/g’ file >file2 修改file中的a为b并导入file2中 ..................... 14 43.ls [a-z]*.conf 列出a到z开头文件,conf结尾的所有文件 .............................. 14 44.yum search packagename 搜索package ................................................................... 14 yum install packagename 安装package........................................................................... 14
45.tar –zxvf file.tar 解压缩 ..................................................................................................... 14 tar –cvf file.tar file 打包 ........................................................................................................... 14 46.ps –x 自己的进程 ................................................................................................................. 14 ps aux 所有人的进程 ................................................................................................................ 14 47.grep ’test’ file | head -5........................................................................................................ 14 48.grep ‘test’ file –n 显示出匹配的行号 ........................................................................... 14 49.du –h –max-depth=/home/liuyongb 查看空间大小 ............................................. 14 50.ln –s ~/file ~/bin/file 软连接 ........................................................................................ 14 51.find ./ -name ‘test’ | xargs rm –rf 本地查找后,进行删除 ................................. 14 52.df –hl 查看空间剩余 ........................................................................................................... 14 53.du –sh file 查看目录总大小 ............................................................................................. 14 54.ls | sort –n 按数字排序 ...................................................................................................... 14 55.ifconfig 显示机器ip地址 ................................................................................................. 14 56.改变文件用户的组和用户用chown。 比如file原来所属的组和用户为admin users,想改成yahoo users,则用sudo chown yahoo:users file即可 ................... 15 57.find ./|xargs grep 'Eragon' 在当前目录及子目录下的文件中找到包含某单词的文件? ....................................................................................................................................... 15 另附上机器打通方法: ................................................................................................................ 15
一:LINUX下安装JDK(安装版本:JDK-7U71-LINUX-X64.RPM)
1.先卸载服务器自带的JDK软件包
1.1 java -version ------查看服务器是否安装过jdk
java version \
OpenJDK Runtime Environment (IcedTea6 1.7.4) (rhel-1.21.b17.el6-i386) OpenJDK Client VM (build 14.0-b16, mixed mode)
1.2 rpm -qa |grep gcj ------查看服务器安装的jdk的软件包信息 libgcj-4.4.4-13.el6.i686
java-1.5.0-gcj-1.5.0.0-29.1.el6.i686
1.3 yum -y remove java-1.5.0-gcj-1.5.0.0-29.1.el6.i686 ------卸载软件包
2.使用RPM命令安装
rpm -ivh jdk-7u71-linux-x64.rpm
3.配置环境变量
3.1 cp /etc/profile /etc/profile.bak ------备份
3.2 vi /ect/profile ------编辑,在最后面添加下面内容 export JAVA_HOME=/usr/lib/jvm/java7 export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib export PATH=${JAVA_HOME}/bin:$PATH
4.使配置文件立即生效
source /etc/profile
5.由于系统中可能会有默认的其他版本JDK,所以,为了将我们的JDK设置为默认的JDK版本,还要进行如下工作
update-alternatives --install /usr/bin/java java /usr/lib/jvm/java7/bin/java 300 update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/java7/bin/javac 300 update-alternatives --install /usr/bin/jar jar /usr/lib/jvm/java7/bin/jar 300
update-alternatives --install /usr/bin/javah javah /usr/lib/jvm/java7/bin/javah 300 update-alternatives --install /usr/bin/javap javap /usr/lib/jvm/java7/bin/javap 300
6.执行下面命令,设置默认版本,此命令结束后,系统会列出当前存在的各种JDK版本,会提示你选择
update -alternatives --config java
7.测试是否安装成功
java –version
二:LINUX下安装TOMCAT7 1.下载JDK 1.7
1.1 首先打开Java SE的官网,选择屏幕中下方的Java SE 7u65 JDK下载;
1.2 根据自己的linux系统版本,使用wget命令下载jdk-7u65-linux-x64.tar.gz wget --no-cookie --header \p-cookie; s_nr=1407131063040; gpw_e24=http://www.oracle.com/t echnetwork/java/javase/downloads/jdk7-downloads-1880260.html; s_sq=[[B]]\