简体   繁体   中英

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

I tried to run redis in Vagrantbox(with Ubuntu image) an forward port 6379 to the port 16379 of the host machine, but for reasons I can't do this. So, I use Vagrantfile like this:

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

and ansible playbook:

- 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

Which do simple stuff, install and configure redis with config file below:

appendonly yes

appendfilename "/var/appendonly.aof"
appendfsync everysec

bind 0.0.0.0

So, when I try to ping on the host machine I have an error below:

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

When I run ping inside the guest machine everything works:

vm> redis-cli ping
PONG

Any ideas?

the problem was in the line: appendfilename "/var/appendonly.aof"

If I run redis-server redis.conf manually, I'll see an error:

'appendfilename "/var/appendonly.aof"' appendfilename can't be a path, just a filename

For some reasons ansible doesn't show this error

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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