漂泊中的Redis(Ubuntu):如何转发Redis端口?
我尝试在Vagrantbox中运行redis(带有Ubuntu映像),将端口6379转发到主机的端口16379,但由于某些原因,我无法这样做。所以,我使用的文件如下:漂泊中的Redis(Ubuntu):如何转发Redis端口?,ubuntu,redis,vagrant,ansible,Ubuntu,Redis,Vagrant,Ansible,我尝试在Vagrantbox中运行redis(带有Ubuntu映像),将端口6379转发到主机的端口16379,但由于某些原因,我无法这样做。所以,我使用的文件如下: VAGRANTFILE_API_VERSION = "2" Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| config.vm.box = "ubuntu/trusty64" config.vm.network "forwarded_port", guest:
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未显示此错误问题出在以下行中: appendfilename“/var/appendonly.aof” 如果我手动运行redis server redis.conf,我将看到一个错误: “appendfilename”/var/appendonly.aof” appendfilename不能是路径,只能是文件名
由于某些原因,ansible没有显示此错误对不起,我在titleYep中忘记了一个单词“redis”,在它回答ping的虚拟机端口6379I中,我添加了此详细信息如果您在虚拟机创建后向您的vagrant文件添加了
转发的端口
参数,请不要忘记重新加载它。@KonstantinSuvorov对不起,我忘记了一个单词“redis”在titleYep内部,在虚拟机中,它响应端口6379I上的ping。我添加了此详细信息。如果您在虚拟机创建后向您的vagrant文件添加了forwarded\u port
参数,请不要忘了重新加载它。@KonstantinSuvorov I没有显示错误,当然它不会显示错误,因为您将Redis作为服务运行。问题与Ansible无关。当然,它不会显示错误,因为您将Redis作为服务运行。这个问题与Ansible无关。