The java environment and the tomcat deployment process on the centos server are self-starting and mysql is simply modified

This article records the deployment and self-starting of java and tomcat after the installation of centos, as well as the modification of the  mysql  database of the olds website system. The red part is the actual operation process.

Initial conditions: centos installation is complete (x86 desktop version 5.5), mysql installation is complete.

Basic knowledge: The centos terminal will be used (the first # symbol in the following commands is the default terminal command line prompt, and no actual input is required).

1. JAVA installation

1. Centos comes with OPENJDK, which is generally not used and needs to be uninstalled.

Use the command java -version to  view the java version, there will be the following information:

javaversion "1.6.0"

OpenJDK  Runtime Environment (build1.6.0-b09)

OpenJDK 64-Bit Server VM (build 1.6.0-b09, mixed mode)

Then use the command rpm -qa | grep java to view the installation package

The following information is displayed:

java-1.4.2-gcj-compat-1.4.2.0-40jpp.115

java-1.6.0-openjdk-1.6.0.0-1.7.b09.el5

Uninstall:

rpm -e--nodeps java-1.4.2-gcj-compat-1.4.2.0-40jpp.115

rpm -e --nodeps java-1.6.0-openjdk-1.6.0.0-1.7.b09.el5

Note that the middle of el5 above is the letter l, not the number 1

and some other commands

rpm-qa | grep gcj

rpm-qa | grep jdk

 If you can't find openjdksource, you can uninstall it like this

 yum -y remove javajava-1.4.2-gcj-compat-1.4.2.0-40jpp.115

 yum -y remove javajava-1.6.0-openjdk-1.6.0.0-1.7.b09.el5

2. Copy the downloaded java bin installation file (mine is jdk-6u45-  linux  -i586-rpm.bin) to the required place, and I put it in /usr/java.

Double-clicking on the desktop environment will automatically decompress it.

Type in the command line environment

# chmod 777jdk-1_5_0_14-linux-i586-rpm.bin

# ./jdk-1_5_0_14- linux -i586-rpm.bin

After the installation is complete, multiple files, one directory, and two shortcuts will be generated in the current directory. We only need to focus on that directory. Mine is /jdk1.6.0_45

3. Configure environment variables

Enter the /etc directory in the desktop environment, then double-click the profile file, it will be automatically opened with the editor gedit, and add the following content at the end of the file:

export JAVA_HOME=/usr/java/jdk1.6.0_45 

export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar

export PATH=$PATH:$JAVA_HOME/bin 

In the command line environment, enter the following command, and then add the above 3 lines as well.

# vi /etc/profile

Then to make the configuration take effect, enter the following at the command line:

# source /etc/profile

If successful, use the java -version command to see the following:

java version "1.6.0_45"

Java(TM) SE Runtime Environment (build 1.6.0_45-b06)

Java Hotspot(TM) Server VM (build 20.45-b01,mixed mode)

二、tomcat安装

1. 我下载的版本是apache-tomcat-7.0.61.tar.gz,在桌面环境里可以直接双击打开(和windows里的解压缩类似),将里面的文件夹放到需要的目录,我放到了/usr里。

主文件夹(apache-tomcat-7.0.61)里有一些文件夹比如bin,但还要自己建一个logs文件夹,不然会报无法碰触的错误。

2. 为tomcat服务添加防火墙记录以方便外网访问。

tomcat默认的端口是8080,所以要把8080端口添加到防火墙例外。

桌面环境下进入到/etc/sysconfig目录,双击iptables用编辑器打开,添加一条记录

-A RH-Firewall-l-INPUT -p tcp -m state --state NEW -m tcp --dport 8080 -j ACCEPT

这条写的和网上其他资料不一致,因为网上资料在我的电脑上不成功。加在文件最后可能会有问题,但不确定,我放在了其他类似记录一起。

命令行环境则输入# vi + /etc/sysconfig/iptables再添加记录。

在终端输入# service iptables restart以重启防火墙。

3. 现在就可以手动启动tomcat了,桌面环境下进入到/usr/apache-tomcat-7.0.61/bin目录,然后双击startup.sh,在弹出界面点击运行。等一段时间后就可以通过localhost:8080访问网站了。正常的话出现tomcat标志性的猫。

如果在第一步里没有建logs目录,那么网站就不能成功访问,但桌面环境下tomcat是不会报错的。如果用命令行启动tomcat则可以看到报错内容。

命令行环境输入# /usr/apache-tomcat-7.0.61/bin/startup.sh启动tomcat。

4.将tomcat服务添加到自启动列表,这样在服务器重启时就不需要手动去启动startup.sh了

这一功能网上有多种实现方式,我没有一一尝试,下面的方法是自己实践出来可以在我的环境中工作的。全部操作都在桌面下进行。

首先打开/etc/init.d目录,随便复制一个存在的文件,再重命名为tomcat,用文本编辑器打开,删掉原有内容。

将下面的内容拷贝进去并根据实际情况修改prog的名称,JAVA_HOME和TOMCAT_HOME的路径,这里的TOMCAT_HOME是可以自己取名的。

  1. #!/bin/bash  

  2. #  

  3. # tomcat startup script for the Tomcat server  

  4. #  

  5. # chkconfig: 345 80 20  

  6. # description: start the tomcat deamon  

  7. #  

  8. # Source function library  

  9. . /etc/rc.d/init.d/functions  

  10.   

  11. prog=tomcat  

  12. JAVA_HOME=/usr/java/jdk1.6.0_45  

  13. export JAVA_HOME  

  14. TOMCAT_HOME=/usr/apache-tomcat-7.0.61  

  15. export TOMCAT_HOME  

  16.   

  17. case "$1" in  

  18. start)  

  19.     echo "Starting Tomcat..."  

  20.     $TOMCAT_HOME/bin/startup.sh  

  21.     ;;  

  22.   

  23. stop)  

  24.     echo "Stopping Tomcat..."  

  25.     $CATALANA_HOME/bin/shutdown.sh  

  26.     ;;  

  27.   

  28. restart)  

  29.     echo "Stopping Tomcat..."  

  30.     $TOMCAT_HOME/bin/shutdown.sh  

  31.     sleep 2  

  32.     echo  

  33.     echo "Starting Tomcat..."  

  34.     $TOMCAT_HOME/bin/startup.sh  

  35.     ;;  

  36.   

  37. *)  

  38.     echo "Usage: $prog {start|stop|restart}"  

  39.     ;;  

  40. esac  

  41. exit 0  

然后在centos顶部的菜单里依次选择系统-管理-服务,出现服务配置窗口,可以看到左边列出了已经存在的服务,再点击菜单行动-添加服务,在弹出的对话框中输入tomcat(这是在上面文件中定义的,如果你有多个tomcat服务,可以取名为tomcat1,tomcat2等等),确定就可以了。

如果没什么意外,下次服务器重启的时候tomcat就会自己启动了。

三、mysql数据库修改

1. 进入mysql命令行

启动终端,输入# mysql -u root -p,根据提示输入密码再回车,终端的提示符就会变成 mysql>,表示已经进入了mysql的命令行模式。

2. 为某个表添加一个字段

mysql> show databases;

mysql> use database001;

mysql> show tables;

mysql> alter table table001 add column ip varchar(255);

3. 为某个表里的3个字段添加索引

mysql> alter table table002 add index index1 (jh);

mysql> alter table table002 add index index2 (csrq);

mysql> alter table table002 add index index3 (cssj);

4. 修改mysql的编码为utf8

由于某些情况下会出现中文乱码,所以将mysql的服务端、客户端、连接等统一设为utf8.

首先用如下命令查看mysql的编码

mysql> show variables like 'character%';

可能会是这样的结果:

+---------------------------+--------------------------------------------------------+

| Variable_name                 | Value                                                                         |

+---------------------------+--------------------------------------------------------+

| character_set_client          | latin1                                                                        |

| character_set_connection | latin1                                                                        |

| character_set_database    | utf8                                                                           |

| character_set_filesystem  | binary                                                                        |

| character_set_results        | latin1                                                                        |

| character_set_server        | latin1                                                                         |

| character_set_system      | latin1                                                                          |

| character_sets_dir           | /usr/share/mysql/charsets/                                        |

+--------------------------+---------------------------------------------------------+

可以看到很多设置都是拉丁,我们需要全部改为utf8.打开/etc/my.cnf文件,进行修改,修改后如下:

[mysqld]

default-character-set = utf8    #新增

character_set_server=utf8      #新增

init_connect='SET NAMES utf8'

datadir=/var/lib/mysql

socket=/var/lib/mysql/mysql.sock

user=mysql

symbolic-links=0

[mysqld_safe]

default-character-set = utf8    #新增

log-error=/var/log/mysqld.log

pid-file=/var/run/mysqld/mysqld.pid

[client]

default-character-set = utf8      #新增

[mysql.server]

default-character-set = utf8      #新增

[mysql]

default-character-set = utf8      #新增

然后保存关闭,使用命令#service mysqld restart重新启动mysql即可。

日期计算器

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327066592&siteId=291194637