当前位置: 首页 > news >正文

Ubuntu 设置开机自动执行脚本

1. 建立service文件

sudo vim /etc/systemd/system/redis-server.service
2. redis service文件
[Unit]
Description=Advanced key-value store
After=network.target
Documentation=http://redis.io/documentation, man:redis-server(1)[Service]
Type=notify
ExecStart=/usr/bin/redis-server /etc/redis/redis.conf --supervised systemd --daemonize no
PIDFile=/run/redis/redis-server.pid
TimeoutStopSec=0
Restart=always
User=redis
Group=redis
RuntimeDirectory=redis
RuntimeDirectoryMode=2755UMask=007
PrivateTmp=yes
LimitNOFILE=65535
PrivateDevices=yes
ProtectHome=yes
ReadOnlyDirectories=/
ReadWritePaths=-/var/lib/redis
ReadWritePaths=-/var/log/redis
ReadWritePaths=-/var/run/redisNoNewPrivileges=true
CapabilityBoundingSet=CAP_SETGID CAP_SETUID CAP_SYS_RESOURCE
MemoryDenyWriteExecute=true
ProtectKernelModules=true
ProtectKernelTunables=true
ProtectControlGroups=true
RestrictRealtime=true
RestrictNamespaces=true
RestrictAddressFamilies=AF_INET AF_INET6 AF_UNIX# redis-server can write to its own config file when in cluster mode so we
# permit writing there by default. If you are not using this feature, it is
# recommended that you replace the following lines with "ProtectSystem=full".
ProtectSystem=true
ReadWriteDirectories=-/etc/redis[Install]
WantedBy=multi-user.target
Alias=redis.service
3. postgresql service文件
[Unit]
Description=PostgreSQL 14 database server
Documentation=man:postgres(1)
Documentation=http://www.postgresql.org/docs/14/static/
After=network.target[Service]
Type=forking
User=postgres
Group=postgres
ExecStart=/usr/bin/pg_ctl start -D /usr/local/postgresql-11.4/data -l /usr/local/postgresql-11.4/log/pg_server.log 
ExecStop=/usr/bin/pg_ctl stop -D /usr/local/postgresql-11.4/data -l /usr/local/postgresql-11.4/log/pg_server.log
ExecReload=/usr/bin/pg_ctl reload -D /usr/local/postgresql-11.4/data -l /usr/local/postgresql-11.4/log/pg_server.log
PIDFile=/usr/local/postgresql-11.4/data/postmaster.pid
TimeoutStopSec=0
Restart=always
User=postgres
Group=postgres
RuntimeDirectory=postgresql
RuntimeDirectoryMode=2755
UMask=007
PrivateTmp=yes
LimitNOFILE=65535
PrivateDevices=yes
ProtectHome=yes
ReadOnlyDirectories=/
ReadWriteDirectories=-/usr/local/postgresql-11.4
ReadWriteDirectories=-/etc/postgresql[Install]
WantedBy=multi-user.target
Alias=postgresql.service
注:EnvironmentFile 参数可以将命令中使用的变量统一管理,例如$KUBECONFIG 这类型的变量,然后定义的变量可以在整个service文件中使用
4. 启动服务并检查状态
$ systemctl daemon-reload
$ systemctl start redis
$ systemctl status redis
$ systemctl restart redis

5. 开机自启动 

$ systemctl enable redis

http://www.lryc.cn/news/177208.html

相关文章:

  • 【笔记】Splay
  • opencv英文识别tesseract-orc安装
  • JNA封装C/C++动态库在flink内使用记录
  • Android gradle dependency tree change(依赖树变化)监控实现
  • 5个流程图模板网站,帮你轻松绘制专业流程图
  • 【AI视野·今日Robot 机器人论文速览 第四十二期】Wed, 27 Sep 2023
  • 后端面试关键问题大总结
  • uni-app:实现图片周围的图片按照圆进行展示
  • Django之视图
  • 【软件工程_设计模式】——为什么要使用设计模式?
  • 大数据之Kafka
  • 灵活运用OSI模型提升排错能力
  • 【最新!企知道AES加密分析】使用Python实现完整解密算法
  • 前端架构师之11_JavaScript事件
  • 文本过滤工具:grep
  • 【Linux】生产者和消费者模型
  • 开发APP的费用是多少
  • start()方法源码分析
  • VUE_history模式下页面404错误
  • 现代数据架构-湖仓一体
  • 最新AI写作系统ChatGPT源码/支持GPT4.0+GPT联网提问/支持ai绘画Midjourney+Prompt应用+MJ以图生图+思维导图生成
  • Python机器学习实战-特征重要性分析方法(5):递归特征消除(附源码和实现效果)
  • 如何快速走出网站沙盒期(关于优化百度SEO提升排名)
  • ATA-8000系列射频功率放大器——应用场景介绍
  • 2009-2018年各省涉农贷款数据(wind)
  • window.print()打印及出现的问题
  • Fedora Linux 39 Beta 预估 10 月底发布正式版
  • 【zookeeper】基于Linux环境安装zookeeper集群
  • 什么是IoT数字孪生?
  • 俄罗斯四大平台速卖通、Joom、Ozon 和 UMKA中国卖家如何脱颖而出!