yum update -y
yum list lrzsz*
yum install lrzsz -y
安装JDK,path之类的已经自动设置好了
yum list java*
yum install java-1.7.0-openjdk* -y
查看有没有安装过:
yum list installed mysql*
rpm -qa | grep mysql*
查看有没有安装包:
yum list mysql*
安装mysql客户端:
yum install mysql
安装mysql 服务器端:
yum install mysql-server
yum install mysql-devel
数据库字符集设置
mysql配置文件/etc/my.cnf中加入default-character-set=utf8
启动mysql服务:
service mysqld start
或者/etc/init.d/mysqld start
开机启动:
chkconfig --add mysqld
,
查看开机启动设置是否成功chkconfig –list | grep mysql*
mysqld 0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭
停止:
service mysqld stop
服务器直接关闭后mysql无法启动问题:
chown -R mysql:mysql /var/lib/mysql
/etc/rc.d/init.d/mysqld start
创建root管理员:
mysqladmin -u root password 123456
登录:
mysql -u root -p输入密码即可。
忘记密码:
service mysqld stop
mysqld_safe --user=root --skip-grant-tables
mysql -u root
use mysql
update user set password=password("new_pass") where user="root";
flush privileges;
开放防火墙的端口号
mysql增加权限:mysql库中的user表新增一条记录host为“%”,user为“root”。
数据库目录
/var/lib/mysql/
配置文件
/usr/share /mysql(mysql.server命令及配置文件)
相关命令
/usr/bin(mysqladmin mysqldump等命令)
启动脚本
/etc/rc.d/init.d/(启动脚本文件mysql的目录)
yum -y install tomcat6 tomcat6-webapps tomcat6-admin-webapps tomcat6-docs-webapp tomcat6-javadoc
如果报错误:No package tomcat6 available
则执行 :
yum search tomcat
查看yum有tomcat哪个版本的包
然后再执行上述install
yum -y install tomcat5 tomcat5-webapps tomcat5-admin-webapps tomcat5-docs-webapp tomcat5-javadoc
查看tomcat安装路径命令:
rpm -ql tomcat5 | cat -n
tomcat启动、关闭命令:
service tomcat5 start
service tomcat5 stop
service tomcat5 restart
yum install httpd -y
用root用户登陆到系统,打开一个终端输入
# rpm -qa|grep gcj
显示内容其中包含下面两行信息
# java-1.4.2-gcj-compat-1.4.2.0-27jpp
# java-1.4.2-gcj-compat-devel-l.4.2.0-27jpp
卸载
# rpm -e java-1.4.2-gcj-compat-devel-l.4.2.0-27jpp
# rpm -e java-1.4.2-gcj-compat-l.4.2.0-27jpp
卸载其他自己安装的JDK就直接用rpm -e
卸载rpm版的jdk:
#rpm -qa|grep jdk
显示:jdk-1.6.0_10-fcs
卸载:#rpm -e --nodeps jdk-1.6.0_10-fcs
[qyf@localhost ~]$ yum -y list java*
执行结果
[qyf@localhost ~]$ yum -y list java*
Loaded plugins: fastestmirror
base | 1.1 kB 00:00
base/primary | 995 kB 00:00
base 2789/2789
extras | 2.1 kB 00:00
extras/primary_db | 164 kB 00:20
updates | 1.9 kB 00:00
updates/primary_db | 422 kB 00:01
Available Packages
java-1.4.2-gcj-compat.i386 1.4.2.0-40jpp.115 base
java-1.4.2-gcj-compat-devel.i386 1.4.2.0-40jpp.115 base
java-1.4.2-gcj-compat-javadoc.i386 1.4.2.0-40jpp.115 base
java-1.4.2-gcj-compat-src.i386 1.4.2.0-40jpp.115 base
java-1.6.0-openjdk.i386 1:1.6.0.0-5.1.13.3.el5_10 updates
java-1.6.0-openjdk-demo.i386 1:1.6.0.0-5.1.13.3.el5_10 updates
java-1.6.0-openjdk-devel.i386 1:1.6.0.0-5.1.13.3.el5_10 updates
java-1.6.0-openjdk-javadoc.i386 1:1.6.0.0-5.1.13.3.el5_10 updates
java-1.6.0-openjdk-src.i386 1:1.6.0.0-5.1.13.3.el5_10 updates
java-1.7.0-openjdk.i386 1:1.7.0.55-2.4.7.1.el5_10 updates
java-1.7.0-openjdk-demo.i386 1:1.7.0.55-2.4.7.1.el5_10 updates
java-1.7.0-openjdk-devel.i386 1:1.7.0.55-2.4.7.1.el5_10 updates
java-1.7.0-openjdk-javadoc.i386 1:1.7.0.55-2.4.7.1.el5_10 updates
java-1.7.0-openjdk-src.i386 1:1.7.0.55-2.4.7.1.el5_10 updates
java_cup.i386 1:0.10-0.k.6jpp.1 base
java_cup-javadoc.i386 1:0.10-0.k.6jpp.1 base
java_cup-manual.i386 1:0.10-0.k.6jpp.1 base
javacc.i386 4.0-3jpp.3 base
javacc-demo.i386 4.0-3jpp.3 base
javacc-manual.i386 4.0-3jpp.3 base
2.使用root用户安装
安装时提醒必须使用root用户
[qyf@localhost ~]$ yum -y install java-1.6.0-openjdk*
执行结果:
[qyf@localhost ~]$ yum -y install java-1.6.0-openjdk*
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirror.bit.edu.cn
* extras: mirror.bit.edu.cn
* updates: centos.ustc.edu.cn
base | 1.1 kB 00:00
base/primary | 995 kB 00:07
base 2789/2789
extras | 2.1 kB 00:00
extras/primary_db | 164 kB 00:02
updates | 1.9 kB 00:00
updates/primary_db | 422 kB 00:07
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package java-1.6.0-openjdk.i386 1:1.6.0.0-5.1.13.3.el5_10 set to be updated
--> Processing Dependency: jpackage-utils >= 1.7.3-1jpp.2 for package: java-1.6.0-openjdk
--> Processing Dependency: libgif.so.4 for package: java-1.6.0-openjdk
--> Processing Dependency: tzdata-java for package: java-1.6.0-openjdk
---> Package java-1.6.0-openjdk-demo.i386 1:1.6.0.0-5.1.13.3.el5_10 set to be updated
---> Package java-1.6.0-openjdk-devel.i386 1:1.6.0.0-5.1.13.3.el5_10 set to be updated
---> Package java-1.6.0-openjdk-javadoc.i386 1:1.6.0.0-5.1.13.3.el5_10 set to be updated
---> Package java-1.6.0-openjdk-src.i386 1:1.6.0.0-5.1.13.3.el5_10 set to be updated
--> Running transaction check
---> Package giflib.i386 0:4.1.3-7.3.3.el5 set to be updated
---> Package jpackage-utils.noarch 0:1.7.3-1jpp.3.el5 set to be updated
---> Package tzdata-java.i386 0:2014b-1.el5 set to be updated
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository
Size
================================================================================
Installing:
java-1.6.0-openjdk i386 1:1.6.0.0-5.1.13.3.el5_10 updates 44 M
java-1.6.0-openjdk-demo i386 1:1.6.0.0-5.1.13.3.el5_10 updates 2.2 M
java-1.6.0-openjdk-devel i386 1:1.6.0.0-5.1.13.3.el5_10 updates 15 M
java-1.6.0-openjdk-javadoc i386 1:1.6.0.0-5.1.13.3.el5_10 updates 20 M
java-1.6.0-openjdk-src i386 1:1.6.0.0-5.1.13.3.el5_10 updates 39 M
Installing for dependencies:
giflib i386 4.1.3-7.3.3.el5 base 39 k
jpackage-utils noarch 1.7.3-1jpp.3.el5 base 60 k
tzdata-java i386 2014b-1.el5 updates 172 k
Transaction Summary
================================================================================
Install 8 Package(s)
Upgrade 0 Package(s)
Total download size: 120 M
Downloading Packages:
(1/8): giflib-4.1.3-7.3.3.el5.i386.rpm | 39 kB 00:00
(2/8): jpackage-utils-1.7.3-1jpp.3.el5.noarch.rpm | 60 kB 00:00
(3/8): tzdata-java-2014b-1.el5.i386.rpm | 172 kB 00:04
(4/8): java-1.6.0-openjdk-demo-1.6.0.0-5.1.13.3.el5_10.i386.rpm | 2.2 MB 00:47
(5/8): java-1.6.0-openjdk-devel-1.6.0.0-5.1.13.3.el5_10.i386.rpm | 15 MB 04:25
(6/8): java-1.6.0-openjdk-javadoc-1.6.0.0-5.1.13.3.el5_10.i386.rpm (17%) 19% [============ ] 81 kB/s | 3.8 MB 03:19 ETA
[qyf@localhost ~]$ java -version
[qyf@localhost ~]$ java -version
java version "1.6.0_30"
OpenJDK Runtime Environment (IcedTea6 1.13.3) (rhel-5.1.13.3.el5_10-i386)
OpenJDK Client VM (build 23.25-b01, mixed mode)
正确显示了jdk版本信息就说明安装成功了
默认情况下jdk安装得路径
/usr/lib/jvm
在centos linux上设置JAVA_HOME environment variable(JAVA_HOME环境变量)
rhel 和 centos linux 使用yum命令后,将 OpenSDK 安装到/usr/lib/jvm/ 下:
[[email protected] ~]# ls -l /usr/lib/jvm/
total 4
drwxr-xr-x. 3 root root 4096 Feb 24 17:00 java-1.7.0-openjdk-1.7.0.51.x86_64
lrwxrwxrwx. 1 root root 21 Feb 24 17:00 jre -> /etc/alternatives/jre
lrwxrwxrwx. 1 root root 27 Feb 24 17:00 jre-1.7.0 -> /etc/alternatives/jre_1.7.0
lrwxrwxrwx. 1 root root 38 Feb 24 17:00 jre-1.7.0-openjdk.x86_64 -> java-1.7.0-openjdk-1.7.0.51.x86_64/jre
lrwxrwxrwx. 1 root root 29 Feb 24 17:00 jre-openjdk -> /etc/alternatives/jre_openjdk
解释:输出的第二行的drwxr-xr-x.中的d表示是文件夹。其余的 l 表示链接。
接下来,设置环境变量
[root@dabu.info ~]# vi /etc/profile
将下面的三行粘贴到 /etc/profile 中:
export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.51.x86_64
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
保存关闭,后,执行:
[root@dabu.info ~]# source /etc/profile
让设置立即生效。
在输入以下命令,来确认这三个变量是否设成了我们想要的:
[root@dabu.info ~]# echo $JAVA_HOME
[root@dabu.info ~]# echo $CLASSPATH
[root@dabu.info ~]# echo $PATH
测试java是否安装配置成功
查看 java 版本,输入命令:
[root@dabu.info ~]# java -version
创建一个java小程序测试下,名字叫 HelloWorld.java ,输入以下命令:
[root@dabu.info ~]# touch HelloWorld.java
将以下代码复制到 HelloWorld.java 中 :
public class HelloWorld {
pu
blic static void main(String[] args) {
System.out.println("Hello, World! This is a test code by nixCraft!");
}
}
复制进去后,保存关闭文件。编译和运行这个小程序,输入以下命令:
[root@dabu.info ~]# javac HelloWorld.java
[root@dabu.info ~]# java HelloWorld
会得到以下显示:
Hello, World! This is a test code by nixCraft!
如何(怎样)运行 .jar 这类java应用?
语法如下:
[root@dabu.info ~]# java -jar file.jar
[root@dabu.info ~]# java -jar /path/to/my/java/app.jar
#/path/to/my/java/app.jar表示应用的路径
[root@dabu.info ~]# java -jar /path/to/my/java/app.jar arg1 arg2
# arg1表示参数1 ,arg2表示参数2