【问题标题】:add ssh to system start up in ubuntu [closed]在ubuntu中将ssh添加到系统启动[关闭]
【发布时间】:2013-09-19 00:22:04
【问题描述】:

是否可以在系统启动时添加此命令? 甚至在自动关闭时自动启动(未知原因)?

“ssh -fNg -L 3306:127.0.0.1:3306 用户@10.10.1.20”

我使用上面的命令让php PDO连接到另一台机器上的mysql服务器

通过 ssh 协议。

最后一天这个连接自动关闭,现在我要避免这个错误

制作一些故障安全方法。

方法。我找到了这个文件 /etc/ssh/ssh_config 但在这篇文章中

http://www.howtogeek.com/75007/stupid-geek-tricks-use-your-ssh-config-file-to-create-aliases-for-hosts/

它说我应该修改 ~/.ssh/config。我有点迷路了。

如果没有可用的ssh连接,是否可以让php检查ssh连接?

像在另一个文件“config.ini”中建立 ssh 批处理然后调用 mysql ?

【问题讨论】:

  • 也许使用标记为 @rebootcrontab 条目
  • 首先使用autossh 而不是普通的ssh 来管理失败后的重新连接。然后将 autossh 命令添加到您的启动脚本中以在重新启动后继续存在。

标签: php mysql linux ssh


【解决方案1】:

做一个每分钟运行的 cronjob:

文件:/etc/crontab

* * * * * youruser if [ 0 == $(netstat -ntlp | grep :3306 | wc -l) ]; then /usr/bin/ssh -fNg -L 3306:127.0.0.1:3306 User@10.10.1.20; fi;

您可能需要使用 -F /absolute/path/to/ssh.config 为 SSH 密钥等指定配置。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-20
    • 2011-11-13
    • 1970-01-01
    • 2015-02-13
    相关资源
    最近更新 更多