1. Install and configure JDK
$ java -version
First uninstall the jdk that comes with CentOS (yum is a batch uninstall, all related ones are uninstalled together):
$ yum -y remove java java-1.4.2-gcj-compat-1.4.2.0-40jpp.115
Then check the jdk version. There is no information, and the uninstallation is successful:
$ java -version
bash:/usr/bin/java:No such file or directory
Then start installing your own jdk (take the rpm file as an example):
first import it into the designated folder of CentOS (such as /wz_work/java)
and then directly decompress and install the rpm file:
$ rpm -ivh jdk-7u71-linux-x64.rpm
$ java -version
Next configure the environment variables:
$ vi /etc/profile
insert the following content at the bottom:
$ set java environment
JAVA_HOME=/usr/java/jdk1.7.0_71
JAVA_BIN=/usr/java/jdk1.7.0_71/bin
PATH= P A T H : PATH: PATH:JAVA_HOME/bin
CLASSPATH=.: J A V A _ H O M E / l i b / d t . j a r : JAVA\_HOME/lib/dt.jar: JAVA_HOME/lib/dt.jar:JAVA_HOME/lib/tools.jar:$JAVA_HOME/jre/lib/rt.jar
export JAVA_HOME
export JAVA_BIN
export PATH
export CLASSPATH
The way to edit the file:
after using vi to enter the file content, press i to edit the file, it will become:
–insert–
After editing, press Esc, then enter: wq to save and exit, enter: q not to save Exiting the cat command directly
is to view the file content and cannot be edited. For example:
$ cat /etc/profile
it takes effect immediately:
$ source /etc/profile
$ java -version
$ javac
$ javac -version
2. Install and configure Tomcat
Also upload the installation compressed package (taking apache-tomcat-7.0.70-windows-x64.zip as an example) to CentOS/wz_work/tomcat, and then decompress the compressed package:
$ unzip apache-tomcat-7.0.70-windows-x64.zip
$ mv apache-tomcat-7.0.70 tomcat7
At this time, there should be a .zip compressed package and a tomcat7 folder under the tomcat folder. The decompressed tomcat is placed under the tomcat7 folder. Next, configure the environment variables: Set the
$TOMCAT_HOME environment variable
$ vi ~/.bash_profile
TOMCAT\_HOME=/wz\_work/tomcat/tomcat7
export TOMCAT_HOME
-- 立即生效
#source ~/.bash_profile
-- 测试
#echo $TOMCAT_HOME
Compile and install the tomcat daemon service waiter program
$ cd $TOMCAT_HOME/bin/
$ tar -xvzf commons-daemon-native.tar.gz
$ cd commons-daemon-1.0.15-native-src/unix
Compile (note: you need to install make, gcc and other compilation tools first)
$ ./configure
The following error message may appear during execution:
*** Java compilation tools ***
checking for JDK location… configure: error: Java Home not defined. Rerun with --with-java=… parameter
This is caused by not specifying the jdk directory, then specify the with-java parameter (pointing to the jdk directory) as prompted. As follows:
$ ./configure --with-java=/usr/java/jdk1.7.0_71
After the operation is completed, the following information will be prompted to indicate that the operation was successful.
*** All done ***
Now you can issue “make”
Execute make:
$ make
After executing make, a jsvc file will be generated and copied to the bin directory of tomcat.
$ cp jsvc $TOMCAT_HOME/bin
There is a daemon.sh file in the tomcat/bin directory. This file is the service daemon that starts and shuts down tomcat.
Note: Some previous tomcat versions, such as tomcat 6.0.x, may not have this file. In fact, this file is placed here commons-daemon-xxx-native-src/unix/samples/Tomcat7.sh (there is another file in this directory) Tomcat5.sh),
but the new version of tomcat moved it to the bin directory and named it daemon.sh. Therefore, if you are using tomcat 6, copy the Tomcat7.sh file to the bin directory and name it daemon.sh.
Modify daemon.sh
$ cd $TOMCAT_HOME/bin
$ vi daemon.sh
Add service startup information at the beginning of the file, such as
#!/bin/sh
$ chkconfig: 2345 90 10
$ description: tomcat7
Find a configuration section similar to the following:
test “.$TOMCAT_USER” = . && TOMCAT_USER=tomcat
#Set JAVA_HOME to working JDK or JRE
#JAVA_HOME=/opt/jdk-1.6.0.22
Modify TOMCAT_USER=tomcat to the user name of the account you want to specify to run as. For example, specify the user name here as greenday
and remove the comment (i.e. "#") in front of JAVA_HOME=... and set it to the installation directory path of jdk. Finally , the modified configuration section becomes as follows:
test “.$TOMCAT_USER” = . && TOMCAT_USER=greenday
JAVA_HOME=/usr/java/jdk1.7.0_71
Then save and exit
. Modify the owner and add execution permissions.
$ chown -R greenday:greenday /wz_work/tomcat/tomcat7
$ chmod a+x /wz_work/tomcat/tomcat7/bin/*.sh
Test (after starting, you can go to the browser to access the local address to see if you can enter the Tomcat homepage)
$ ./daemon.sh start
$ ./daemon.sh stop
Add tomcat as a service
and create a soft link to the /etc/init.d/ directory:
$ ln -s /wz_work/tomcat/tomcat7/bin/daemon.sh /etc/init.d/tomcat7
This creates a service named tomcat7.
Start the tomcat7 service and test it in the browser:
$ /etc/init.d/tomcat7 start
$ /etc/init.d/tomcat7 stop
-- 测试:
$ service tomcat7 start
$ service tomcat7 stop
Set the tomcat service to start at boot
#chkconfig tomcat7 on
Check
[root@cent01 conf]# chkconfig --list|grep tomcat7
tomcat7 0:off 1:off 2:on 3:on 4:on 5:on 6:off
Turn off startup
chkconfig tomcat7 off
Configure port 80:
First go to the Tomcat installation directory and modify the 8080 port in the server.xml file to port 80:
Change port 8080 to port 80, and then check the CentOS port occupancy in Terminal. For example, to check the occupancy of port 80, use the following command:
$ lsof -i tcp:80
List all ports;
$ netstat -ntlp
1. Open the port:
Open the configuration file:
$ vi /etc/sysconfig/iptables
Add the following statement:
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
Save and exit, then restart the firewall:
$ service iptables restart
3. Install and configure MySQL
Since CentOS generally has MySQL by default, check the current installation first:
$ rpm -qa|grep -i mysql
或者:
$ yum list installed mysql*
After that, to uninstall the database that comes with CentOS, it is recommended to use the yum command, because the yum command can automatically delete dependencies related to mysql; if you use the rpm command, you need to manually delete the files related to mysql, which is more troublesome.
#yum remove mysql*
或者
#yum remove MySQL-python.x86_64
或者
#rpm -ev package
Delete the remaining files (if you uninstall using yum, there should be no remaining files):
$ rm -rf /var/lib/mysql
$ rm /etc/my.cnf
After uninstalling, you can use the whereis command to find mysql related files. Because the above was uninstalled using yum, mysql has been cleaned very cleanly. It will be very troublesome if you use rpm, and there are still many files that need to be cleaned manually.
$ whereis mysql
mysql:
After that, upload the downloaded MySQL installation package to CentOS and decompress it: Create a
new folder as follows (create it according to your own wishes, to store the compressed package):
$ mkdir /data/tools
$ cd /data/tools
$ rz
$ tar -xvf MySQL-5.5.54-1.linux2.6.x86_64.rpm-bundle.tar
Install the rpm (install in the following order):
$ yum localinstall MySQL-server-5.5.58-1.e16.x86_64.rpm
$ yum localinstall MySQL-devel-5.5.58-1.e16.x86_64.rpm
$ yum localinstall MySQL-client-5.5.58-1.e16.x86_64.rpm
$ yum localinstall MySQL-shared-compat-5.58-1.e16.x86_64.rpm
Start MySQL:
$ /etc/init.d/mysql start
Set to start every boot:
$ chkconfig --levels 345 mysqld on
Note:
mysqld may not be useful here. You can set it as follows:
copy the mysql.server file to /etc/init.d and name it mysqld:
$ cp /usr/share/mysql/mysql.server /etc/init.d/mysqld
$ chkconfig --add mysqld
In this way, you should be able to set up startup. Then execute the set startup command
and try connecting to MySQL:
$ mysql
After entering successfully, you can change the password:
mysql> set password = password('123456')
To exit:
$ \q
或者
$ exit
关闭连接
Open port 3306 and save:
$ /sbin/iptables -l INPUT -p tcp --dport 3306 -j ACCEPT
$ /etc/rc.d/init.d/iptables save
Check the encoding after entering mysql:
$ mysql
mysql> show variables like 'character%';
The following is to modify the database encoding:
modify the my.cnf file:
exit the database:
mysql> \q
bye
Close the database:
$ service mysqld stop
Stopping mysqld
Then modify my.cnf:
$ vi /etc/my.cnf
Add the following code under [client] and [mysqld] respectively:
[client]
default_character_set=utf8
[mysqld]
collation_server=utf8_general_ci
character_set_server=utf8
Restart the mysql service:
$ service mysqld restart