ZooKeeper configuration is designed so that you can install the same configuration file on all servers in the cluster without changes. This simplifies ops. The component that defines the local node configuration is the myid file.
The configuration you define is not common to all servers. All servers in the server list must be tied to a private IP address available to other nodes on the network. You see that your server is starting offline because you are bound to localhost. Thus, the problem is that other servers in the cluster do not see localhost.
Your configuration should look larger:
tickTime=2000 initLimit=10 syncLimit=5 dataDir=/opt/zookeeper/data clientPort=2181 server.1=<private ip of ec2 instance 1>:2888:3888 server.2=<private ip of ec2 instance 2>:2888:3888 server.3=<private ip of ec2 instance 3>:2888:3888
The two ports listed in each server definition are respectively the quorum and election ports used by ZooKeeper nodes to exchange information with each other. Usually there is no need to change these ports, and you should try to maintain them equally on all servers to ensure consistency.
In addition, as I said, you should be able to share the same configuration file in all instances. The only thing to change is the myid file.
You will probably need to create a security group and open a client port to access clients, and quorum / election ports will be available to other ZooKeeper servers.
Finally, you can refer to the user interface to help manage the cluster. Netflix creates a decent interface that will give you an idea of your cluster, and will also help clear old logs and save snapshots to S3 (ZooKeeper accepts snapshots but does not delete old transaction logs, so your disk will eventually be full if they are not removed properly). But once it is configured correctly, you can also see how the ZooKeeper servers connect to each other in the logs.
EDIT
@czerasz notes that starting with version 3.4.0 you can use the autopurge.snapRetainCount and autopurge.purgeInterval directives to keep your pictures clean.
@chomp notes that some users had to use 0.0.0.0 for the IP address of the local server to configure ZooKeeper on EC2. In other words, replace <private ip of ec2 instance 1> with 0.0.0.0 in the configuration file with instance 1 . This contradicts the way ZooKeeper configuration files are designed, but may be necessary for EC2.