linux系统设置开机自启shell文件和redis、mongondb

    xiaoxiao2022-07-12  140

    一、开机自启shell文件

    1、cd /etc/rc.d/init.d/ 进入文件夹,vi test.sh文件创建并编辑,按i进行编辑。 2、首行添加:

    #!/bin/sh # #chkconfig: 2345 80 90 #description: test

    作用是告诉系统这个是.sh文件,同时拥有开机执行权。 3、然后编写执行的代码,如:

    cd /opt/handler nohup java -jar FileServer.jar &

    4、写完代码后,按Esc,然后:wq保存退出。 5、给文件执行权,懒一点直接给全部权限:chmod 777 test 6、添加到开机自启:chkconfig --add test.sh 7、启动该服务:chkconfig test.sh on 8、检查是否在开机自启中已有该任务:chkconfig --list

    二、开机自启redis

    1、复制redis.conf配置文件:cp /usr/local/redis/utils/redis_init_script /etc/init.d/redis,进入目录创建并编辑:vi /etc/init.d/redis 2、首行插入:

    # chkconfig: 2345 10 90 # description: Start and Stop redis

    3、redis填写对应的启动路径 现在可以使用:启动、停止 和 重启服务,service redis start stop restart 4、写完代码后,按Esc,然后:wq保存退出。 5、给文件执行权,懒一点直接给全部权限:chmod 777 redis 6、添加到开机自启:chkconfig --add redis .sh 7、启动该服务:chkconfig redis .sh on 8、检查是否在开机自启中已有该任务:chkconfig --list 9、注意将redis后台运行开启,redis.conf //将daemonize no 改成daemonize yes

    三、mongondb自启

    1、配置好的mongondb.conf文件,内容如下:

    dbpath=/opt/mongodb/mongodb-3.4.0/data //数据库数据存放目录 logpath=/opt/mongodb/mongodb-3.4.0/log/mongodb.log //数据库日志存放目录 port=27017 //端口号 默认为27017 fork=true //以后台方式运行进程 journal=false //开启用户认证 storageEngine=mmapv1 //关闭http接口,默认关闭http端口访问

    2、vi /etc/init.d/mongodb,这里文件为新建的,和上面的mongondb.conf无关,内容如下

    #!/bin/sh # #chkconfig: 2345 80 90 #description: mongodb start() { /opt/mongodb/mongodb-3.4.0/bin/mongod -f /opt/mongodb/mongodb-3.4.0/etc/mongodb.conf //注意修改为自己的路径 } stop() { /opt/mongodb/mongodb-3.4.0/bin/mongod -f /opt/mongodb/mongodb-3.4.0/etc/mongodb.conf --shutdown //注意修改为自己的路径 } case "$1" in start) start ;; stop) stop ;; restart) stop start ;; *) echo $"Usage: $0 {start|stop|restart}" exit 1 esac

    4、写完代码后,按Esc,然后:wq保存退出。 5、给文件执行权,懒一点直接给全部权限:chmod 777 mongodb 6、添加到开机自启:chkconfig --add mongodb.sh 7、启动该服务:chkconfig mongodb.sh on 8、检查是否在开机自启中已有该任务:chkconfig --list

    最新回复(0)