繁体   English   中英

Redis in Vagrant(Ubuntu):如何转发redis端口?

[英]Redis in Vagrant(Ubuntu): how to forward redis port?

我试图在Vagrantbox(带有Ubuntu映像)中将redis运行到主机端口16379的前向端口6379,但由于原因我不能这样做。 所以,我像这样使用Vagrantfile:

VAGRANTFILE_API_VERSION = "2"

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
  config.vm.box = "ubuntu/trusty64"
  config.vm.network "forwarded_port", guest: 6379, host: 16379
  config.vm.provision "ansible" do |ansible|
    ansible.playbook = "playbook.yml"
  end
end

和ansible剧本:

- name: Prepare redis host
  hosts: all
  sudo: true
  vars:
    redis_conf_path: /etc/redis.conf
  tasks:
    - name: set locale
      lineinfile: dest=/etc/default/locale line="LC_ALL=C"

    - name: install redis
      apt: name=redis-server update_cache=yes

    - name: create user redis
      user:
        name: redis
        system: yes
        home: "/var/lib/redis"
        shell: "/bin/false"

    - name: create the redis configuration file
      template:
        src: redis.conf.j2
        dest: "{{ redis_conf_path }}"
        mode: 0644
        backup: yes
      notify:
        - restart redis

    - name: start redis
      service:
        name: redis-server
        state: started
        arguments: "{{ redis_conf_path }}"
        enabled: yes

  handlers:
    - name: restart redis
      service:
        name: redis-server
        state: restarted
        enabled: yes

哪个做简单的事情,使用下面的配置文件安装和配置redis:

appendonly yes

appendfilename "/var/appendonly.aof"
appendfsync everysec

bind 0.0.0.0

所以,当我尝试ping主机时,我有一个错误如下:

host> redis-cli -p 16379 ping
Error: Server closed the connection

当我在客户机内运行ping时,一切正常:

vm> redis-cli ping
PONG

有任何想法吗?

问题在于:appendfilename“/var/appendonly.aof”

如果我手动运行redis-server redis.conf ,我会看到一个错误:

'appendfilename“/var/appendonly.aof”'appendfilename不能是路径,只是文件名

由于某些原因,ansible不会显示此错误

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM