LINUX environment: MySQL and Oracle start automatically after booting

  1. MySQL configuration self-start
    #Add the MySQL startup service to the system service, and set the startup to start automatically: (chkconfig command redhat system)

Create a soft connection:

[root@ethan-testdb ~]# ln -s /MySQLsoft/MySQL /usr/local/MySQL
 
[root@ethan-testdb ~]# pwd
/usr/local/MySQL/support-files
[root@ethan-testdb ~]# cp MySQL.server /etc/init.d/MySQLd
 
[root@ethan-testdb ~]# /etc/init.d/MySQLd
startStarting MySQL.. SUCCESS!

Grant execution permissions:

[root@ethan-testdb ~]# chmod +x /etc/init.d/MySQLd
添加服务:
[root@ethan-testdb ~]# chkconfig --add MySQLd
显示服务列表:
[root@ethan-testdb ~]# chkconfig --list
如果看到MySQL的服务,并且3,4,5都是on的话则成功,如果是off,则使用如下命令:
[root@ethan-testdb ~]# chkconfig --level 345 MySQLd on

At this point, MySQL has been successfully set up after booting.

One question: What about
Oracle's self-startup?

The answer is:
dbstart, dbstart are the boot scripts. When the system starts, it will execute the dbstart script file, it will read the oratab file, and it will start the corresponding instance automatically when it reads Y.

Configuration steps:

Install Oracle Linux system (Red Hat Enterprise Linux 7.2, Oracle 12c)
1. Check if ORACLE_HOME is set

$ echo $ORACLE_HOME/u01/app/oracle/product/12.2.0/dbhome_1

After installing oracle on Linux, the following error may be reported when using the dbstart command for the first time:

[oracle@ethandb home_1]$ cd bin/[oracle@ethan bin]$ ll | grep dbs
-rwxr-x---. 1 oracle oinstall 6088 1月 1 2000 dbshut
-rwxr-x---. 1 oracle oinstall 13892 12月 11 16:01 dbstart

When executed for the first time, the error is reported as follows:

[oracle@ethan bin]$ dbstart
ORACLE_HOME_LISTNER is not SET, unable to auto-start Oracle Net Listener Usage: /oracle/app/oracle/product/12.2.1/dbhome_1/

Error message: ORACLE_HOME_LISTNER is not set

Reason: There is a problem with the settings of ORACLE_HOME_LISTNER in the dbstart and dbshut script files. Open two files respectively to find them: edit dbstart with vi, ORACLE_HOME_LISTNER= 1, modify it to ORACLEHOMELISTNER=1, modify it to ORACLE_HOME_LISTNER=1,Revised change is O R & lt A C L EHOMELI S T N E R= ORACLE_HOME
or
ORACLE_HOME_LISTNER=/oracle/app/oracle/product/12.2.1/dbhome_1/
Note: $ORACLE_HOME environment setting is correct

2. Edit the file /etc/oratab
dbca will automatically create the /etc/oratab file when building the database

[oracle@ethan bin]# vi /etc/oratab

# Entries are of the form:
#   $ORACLE_SID:$ORACLE_HOME:<N|Y>:

Change "ethanDB:/oracle/app/oracle/product/12.2.1/dbhome_1/:N"
to "ethanDB:/oracle/app/oracle/product/12.2.1/dbhome_1/:Y".
After modification, save and exit

3. Edit the /etc/rc.d/rc.local startup file and add the database startup script dbstart

#vi /etc/rc.d/rc.local    ---末尾添加:
su - oracle -lc “/oracle/app/oracle/product/12.2.1/dbhome_1/bin/lsnrctl start”
su - oracle -lc /oracle/app/oracle/product/12.2.1/dbhome_1/bin/dbstart

If there are multiple instances in the server, you need to specify the instance when the monitor is started

su - oracle -lc “/oracle/app/oracle/product/12.2.1/dbhome_1/bin/lsnrctl start ethanDB”
su - oracle -lc “/oracle/app/oracle/product/12.2.1/dbhome_1/bin/lsnrctl start dannielDB”
su - oracle -lc /oracle/app/oracle/product/12.2.1/dbhome_1/bin/dbstart

Note: The -c in the command represents the execution of the script. The monitoring of the configuration is started in the script lsnrctl, and multiple startups are monitored and written; the instance is started with a dbstart command, it will read the oratab file, and it will start the corresponding instance automatically when it reads Y start up

4. Restart the host, check the database and monitor is self-starting

Brief review of related commands:

linux下设置实例自启动脚本:
oratab:实例是否自启动的注册信息
dbstart:开机启动脚本文件会读取oratab信息
rc.local:开机后立即要做的文件
--“启动监听” lsnrctl start
--“启动数据库实例” dbstart
--“关闭数据库实例”dbshut
--“关闭监听”lsnrctl stop

【Conclusion】

  1. This article introduces in detail the practical steps of Mysql and Oracle start-up automatically, which has a strong reference;
  2. Usually we don’t set up auto-start at boot. The reason is: under normal circumstances, the library is convenient for regular start-stop management; but when we deploy the production database architecture, high availability is a must. If a library is abnormal, this Manual inspections are sometimes performed, and self-starting services sometimes interfere with the operation and judgment of the DBA. Therefore, in a production environment, it is not recommended to configure self-startup at boot; and the frequency of server startup and shutdown is low, and the change process is generally strictly followed. It is better to follow the normal operation of the library.
  3. The above two points are my own thoughts, if there is something wrong, please correct me.

Guess you like

Origin blog.csdn.net/qq_40907977/article/details/114633549