• Ubuntu 设置开机自动执行脚本


    1. 建立service文件

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

    5. 开机自启动 

    $ systemctl enable redis

  • 相关阅读:
    多普勒效应与多普勒频移
    Java计算机网络篇-TCP
    2022华为机试真题 C++ 实现【最大股票收益】
    Nginx代理
    力扣--动态规划1027.最长等差数列
    TOWER 成就徽章 NFT 系列介绍——TOWER 生态系统的第一个灵魂通证(SBT)
    Linux的优缺点
    IntelliJ IDEA 2022.2 正式发布:已完全支持 Spring 6 和 Spring Boot 3了吗?
    Linux之(8)Vi/Vim的使用
    机器学习笔记 - YOLOv7 论文简述与推理
  • 原文地址:https://blog.csdn.net/qq_19734597/article/details/133297196