1.centos7设置oracle数据库开机自启

1、root用户修改

vi /etc/oratab
orcl:/u01/app/oracle/product/12/db_1:N
将上面的N改为Y

2、oracle用户修改

su - oracle
cd $ORACLE_HOME/bin
vi dbstart
修改 #ORACLE_HOME_LISTNER=$1 为 ORACLE_HOME_LISTNER=$ORACLE_HOME
vi dbshut
修改 #ORACLE_HOME_LISTNER=$1 为 ORACLE_HOME_LISTNER=$ORACLE_HOME

3、root用户修改

chmod 777 /etc/rc.d/rc.local
vi /etc/rc.d/rc.local
添加 su - oracle -lc dbstart

2.CentOS 7上配置MySQL5.7开机自启动方法

CentOS7开始使得以往老版本系统服务的/etc/init.d的启动脚本的方式就此改变,在CentOS7中所有对服务的管理都集中到了systemctl当中。
systemctl是一个系统管理守护进程、工具和库的集合,用于取代以往的System V、service和chkconfig命令。

a.创建用于启动MySQL的配置文件

  1. touch /usr/lib/systemd/system/mysqld.service
  2. cd /usr/lib/systemd/system
  3. vi mysqld.service
  4. 编辑mysqld.service文件,加入如下内容:
  5. [Unit]
  6. Description=MySQL Server
  7. Documentation=man:mysqld(8)
  8. Documentation=http://dev.mysql.com/doc/refman/en/using-systemd.html
  9. After=network.target
  10. After=syslog.target
  11. [Install]
  12. WantedBy=multi-user.target
  13. [Service]
  14. User=mysql
  15. Group=mysql
  16. ExecStart=/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf
  17. LimitNOFILE = 5000
  18. 保存退出
  19. 备注:ExecStart=/usr/local/mysql/bin/mysqld (此处请对应修改为MySQL程序所在的路径)
  20. 查找mysqld路径,例如:
  21. [root@localhost system]# which mysqld
  22. /usr/local/mysql/bin/mysqld

[root@localhost system]# which mysqld
/usr/local/mysql/bin/mysqld

b.通过systemctl方式启动mysql5.7:

[root@localhost system]# systemctl start mysqld

c.检查MySQL运行状态:

[root@localhost system]# mysql -p
Enter password:
输入密码登录进去。

d.用  \s  检查MySQL运行状态:

mysql> \s
显示出mysql输出状态
———————
mysql Ver 14.14 Distrib 5.7.18, for linux-glibc2.5 (x86_64) using EditLine wrapper
Connection id: 6
Current database:
Current user: root@localhost
SSL: Not in use
Current pager: stdout
Using outfile: ‘’
Using delimiter: ;
Server version: 5.7.18-log MySQL Community Server (GPL)
Protocol version: 10
Connection: Localhost via UNIX socket
Server characterset: latin1
Db characterset: latin1
Client characterset: utf8
Conn. characterset: utf8
UNIX socket: /tmp/mysql.sock
Uptime: 45 sec
Threads: 3 Questions: 6 Slow queries: 0 Opens: 108 Flush tables: 1 Open tables: 101 Queries per second avg: 0.133
———————

e.关闭防火墙:

[root@localhost system]# systemctl stop firewalld.service
[root@localhost system]# systemctl disable firewalld.service
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.Fedoraproject.FirewallD1.service.

f.设置mysql的开机启动:

[root@localhost system]# systemctl enable mysqld
Created symlink from /etc/systemd/system/multi-user.target.wants/mysqld.service to /usr/lib/systemd/system/mysqld.service.

g.检查mysqld.service是否为enabled

[root@localhost system]# systemctl list-unit-files | grep mysqld
mysqld.service enabled

#取消mysql的开机自启动:

[root@localhost system]# systemctl disable mysqld
Removed symlink /etc/systemd/system/multi-user.target.wants/mysqld.service.
[root@localhost system]# systemctl list-unit-files | grep mysqld
mysqld.service disabled
本文永久更新链接地址http://www.linuxidc.com/Linux/2017-10/147829.htm