Configure Tomcat, MySQL boot on Linux

Source: Internet
Author: User
Tags chmod

1. Tomcat Boot up

Method One, modify the system files (already tried, can)

1. Modify/etc/rc.d/rc.local
Vi/etc/rc.d/rc.local

2. Add the following two lines of script, remember the two lines, only the second line is not, you must add the first row. At the end of the/etc/rc.d/rc.local file, add:

Export java_home=/usr/java/jdk1.7.0_60
/usr/local/tomcat/bin/startup.sh start
Description:/usr/java/jdk1.7.0_60 is the JDK installation directory
/usr/local/tomcat is a tomcat-installed directory

3. Note: Modify the rc.local file to be executable
chmod +x rc.local

Method Two,

Shell script Startup

Setting up the boot-up service in Linux requires a/ETC/RCX.D under the load. In addition, you need to/etc/init.d some startup scripts. In fact, it is very simple to export the required environment variables, such as Java_home,jre_home, Catalina_home, Catalina_base and so on, and then directly call $catalina_home/bin/ Startup.sh will be able to start successfully.

The first step: we create a new file under/ETC/INIT.D Tomcat (need to operate under root privileges)

[Java]View PlainCopyprint?
    1. Vi/etc/init.d/tomcat

Write down the following code, Tomcat self-launching script:

[Java]View PlainCopyprint?
  1. #!/bin/sh
  2. # chkconfig: 345
  3. # Description:auto-starts Tomcat
  4. #/ETC/INIT.D/TOMCATD
  5. # Tomcat Auto-start
  6. # Source function library.
  7. #. /etc/init.d/functions
  8. # source Networking configuration.
  9. #. /etc/sysconfig/network
  10. retval=0
  11. Export JAVA_HOME=/USR/JAVA/JDK1. 7.0_60
  12. Export JRE_HOME=/USR/JAVA/JDK1. 7.0_60/jre
  13. Export Catalina_home=/usr/local/tomcat
  14. Export Catalina_base=/usr/local/tomcat
  15. Start ()
  16. {
  17. if [-f $CATALINA _home/bin/startup.sh];
  18. Then
  19. echo $"Starting Tomcat"
  20. $CATALINA _home/bin/startup.sh
  21. Retval=$?
  22. echo "OK"
  23. return $RETVAL
  24. Fi
  25. }
  26. Stop ()
  27. {
  28. if [-f $CATALINA _home/bin/shutdown.sh];
  29. Then
  30. echo $"Stopping Tomcat"
  31. $CATALINA _home/bin/shutdown.sh
  32. Retval=$?
  33. Sleep 1
  34. PS-FWWU Root | grep tomcat|grep-v grep | Grep-v PID | awk ' {print $} ' |xargs Kill-9
  35. echo "OK"
  36. # [$RETVAL-eq 0] && rm-f/var/lock/ ...
  37. return $RETVAL
  38. Fi
  39. }
  40. Case "$" in
  41. Start
  42. Start
  43. ;;
  44. Stop
  45. Stop
  46. ;;
  47. Restart
  48. echo $"restaring Tomcat"
  49. $0 Stop
  50. Sleep 1
  51. $0 Start
  52. ;;
  53. *)
  54. echo $"Usage: $ {start|stop|restart}"
  55. Exit 1
  56. ;;
  57. Esac
  58. Exit $RETVAL

Here is a special reminder to note that this sentence Ps-fwwu root | grep tomcat|grep-v grep | Grep-v PID | awk ' {print $} ' |xargs kill-9, the person familiar with the Linux command should be aware of the meaning of this sentence, here simply say the first half, query the root user tomcat process PID, personal changes according to the actual situation.

Step two: After you save the exit, add executable permissions to it

[Java]View PlainCopyprint?
    1. chmod +x/etc/init.d/tomcat


Step Three: Mount

Connect the shell file link to the/etc/rc2.d/directory. The numbers in the/etc/rcx.d/directory for Linux represent the different run level, which is the order in which the boot starts, Ubuntu9.10 There are 0-5 six level, can not be casually connected to other directories, it may be in that directory when the program started Tomcat needed to some of the library has not been loaded, with the ln command link tomcat links Past: sudo ln-s/etc/init.d/ Tomcat/etc/rc2.d/s16tomcat. The naming rules under the RCX.D directory are very specific, more different needs may be the beginning of s, may also be the beginning of K, after the numbers represent their starting order, detailed look at the Readme file in their respective directories.

[Java]View PlainCopyprint?
    1. Ln-s/etc/init.d/tomcat/etc/rc2.d/s16tomcat


Fourth step: Set the script to boot from

Set this script to automatically execute when the system starts, and stop automatically when the system shuts down, using the following command:

[Java]View PlainCopyprint?
    1. Chkconfig--add Tomcat


Fifth Step: Verify

Execute sudo reboot. After rebooting, you will find that Tomcat has run successfully.

Digression: After adding this script we start, stop, restart Tomcat to use the command directly

[Java]View PlainCopyprint?
    1. Service Tomcat Start
    2. Service Tomcat Stop
    3. Service Tomcat Restart


Other tomcat settings commands are: Chkconfig--list Tomcat chkconfig Tomcat on, and you can try to find out what the effect is.

Mysql

Command echo "service mysqld start" >>/etc/rc.local

Or go to/etc/directory, direct vim rc.local edit rc.local file, add "service mysqld start" in the last line, save exit

You can use chkconf--list

View the configuration of the boot start

Configure Tomcat, MySQL boot on Linux

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.