|
|
-
Zookeeper run as non-root
Matthew Sims 2012-08-14, 21:02
Hello, we're just starting to implement a Zookeeper where I work on a Red Hat system.
We've set everything up and it starts up just fine. The only issue is that the process is run by the root user.
sudo /etc/init.d/zookeeper start
I have a zookeeper user ready to go. The init script we have makes a java call to start up the process.
start) echo -n "Starting zookeeper ... " if [ -f $ZOOPIDFILE ]; then if kill -0 `cat $ZOOPIDFILE` > /dev/null 2>&1; then echo $command already running as process `cat $ZOOPIDFILE`. exit 0 fi fi nohup $JAVA "-Dzookeeper.log.dir=${ZOO_LOG_DIR}" "-Dzookeeper.root.logger=${ZOO_LOG4J_PROP}" \ -cp "$CLASSPATH" $JVMFLAGS $ZOOMAIN "$ZOOCFG" > "$_ZOO_DAEMON_OUT" 2>&1 < /dev/null & if [ $? -eq 0 ] then if /bin/echo -n $! > "$ZOOPIDFILE" then sleep 1 echo STARTED else echo FAILED TO WRITE PID exit 1 fi else echo SERVER DID NOT START exit 1 fi ;; I've looked in to editing this script, including /etc/init.d/functions and calling the daemon function to run the start as user zookeeper. But this forks the process and the PID file is updated with the daemon process, not the zookeeper process. This causes the stop feature to fail.
Before I go about re-writing this init script, I figure someone else must have a proper way of starting this up as a non-root user.
-
Re: Zookeeper run as non-root
nn chuong411 2012-08-15, 02:42
Hi Matthew, Re-writing srcript is a costly job. I've also run zookeeper as a non-root user since last month. Everything still go fine up to now and here are what I have done: -Download zookeeper, up-pack it and upload to my server under /home/zookeeper (home for zookeeper user) -Configure zoo.cfg at each server, mostly change dataDir back to some folder under /home/zookeeper -Create a myid file under dataDir at each server -Writing a bash script which first move to bin folder and then invoke zkServer.sh start -Log in to server using zookeeper account and run above script. That's all. Honestly, I don't have any need to automatically start zookeeper at start-up time, so placing any script under /etc/init.d/ is not under my consideration. Hope this will help you. P/S: make sure all above files and folder belong to zookeeper, not root user.
On Wed, Aug 15, 2012 at 4:02 AM, Matthew Sims <[EMAIL PROTECTED]> wrote:
> > Hello, we're just starting to implement a Zookeeper where I work on a Red > Hat system. > > We've set everything up and it starts up just fine. The only issue is that > the process is run by the root user. > > sudo /etc/init.d/zookeeper start > > I have a zookeeper user ready to go. The init script we have makes a java > call to start up the process. > > start) > echo -n "Starting zookeeper ... " > if [ -f $ZOOPIDFILE ]; then > if kill -0 `cat $ZOOPIDFILE` > /dev/null 2>&1; then > echo $command already running as process `cat $ZOOPIDFILE`. > exit 0 > fi > fi > nohup $JAVA "-Dzookeeper.log.dir=${ZOO_LOG_DIR}" > "-Dzookeeper.root.logger=${ZOO_LOG4J_PROP}" \ > -cp "$CLASSPATH" $JVMFLAGS $ZOOMAIN "$ZOOCFG" > "$_ZOO_DAEMON_OUT" > 2>&1 < /dev/null & > if [ $? -eq 0 ] > then > if /bin/echo -n $! > "$ZOOPIDFILE" > then > sleep 1 > echo STARTED > else > echo FAILED TO WRITE PID > exit 1 > fi > else > echo SERVER DID NOT START > exit 1 > fi > ;; > > > I've looked in to editing this script, including /etc/init.d/functions and > calling the daemon function to run the start as user zookeeper. But this > forks the process and the PID file is updated with the daemon process, not > the zookeeper process. This causes the stop feature to fail. > > Before I go about re-writing this init script, I figure someone else must > have a proper way of starting this up as a non-root user. > > > -- Nguyen Nam Chuong Software Engineer - VNG Cooperation Ho Chi Minh City - Vietnam
-
Re: Zookeeper run as non-root
Matthew Sims 2012-08-15, 17:42
Thank you for the response. But this isn't quite ideal for my production environment.
I would think zookeeper would have an init script that would handle this, sorta like how mysql starts up, parent process is root but child is mysql.
Anyone else know if there's a standard init script for this? Or do I need to write my own? :)
> Hi Matthew, > Re-writing srcript is a costly job. I've also run zookeeper as a > non-root user since last month. Everything still go fine up to now and > here > are what I have done: > -Download zookeeper, up-pack it and upload to my server under > /home/zookeeper (home for zookeeper user) > -Configure zoo.cfg at each server, mostly change dataDir back to > some folder under /home/zookeeper > -Create a myid file under dataDir at each server > -Writing a bash script which first move to bin folder and then invoke > zkServer.sh start > -Log in to server using zookeeper account and run above script. > That's all. > Honestly, I don't have any need to automatically start zookeeper at > start-up time, so placing any script under /etc/init.d/ is not under my > consideration. Hope this will help you. > P/S: make sure all above files and folder belong to zookeeper, not root > user. > > On Wed, Aug 15, 2012 at 4:02 AM, Matthew Sims <[EMAIL PROTECTED]> wrote: > >> >> Hello, we're just starting to implement a Zookeeper where I work on a >> Red >> Hat system. >> >> We've set everything up and it starts up just fine. The only issue is >> that >> the process is run by the root user. >> >> sudo /etc/init.d/zookeeper start >> >> I have a zookeeper user ready to go. The init script we have makes a >> java >> call to start up the process. >> >> start) >> echo -n "Starting zookeeper ... " >> if [ -f $ZOOPIDFILE ]; then >> if kill -0 `cat $ZOOPIDFILE` > /dev/null 2>&1; then >> echo $command already running as process `cat $ZOOPIDFILE`. >> exit 0 >> fi >> fi >> nohup $JAVA "-Dzookeeper.log.dir=${ZOO_LOG_DIR}" >> "-Dzookeeper.root.logger=${ZOO_LOG4J_PROP}" \ >> -cp "$CLASSPATH" $JVMFLAGS $ZOOMAIN "$ZOOCFG" > "$_ZOO_DAEMON_OUT" >> 2>&1 < /dev/null & >> if [ $? -eq 0 ] >> then >> if /bin/echo -n $! > "$ZOOPIDFILE" >> then >> sleep 1 >> echo STARTED >> else >> echo FAILED TO WRITE PID >> exit 1 >> fi >> else >> echo SERVER DID NOT START >> exit 1 >> fi >> ;; >> >> >> I've looked in to editing this script, including /etc/init.d/functions >> and >> calling the daemon function to run the start as user zookeeper. But this >> forks the process and the PID file is updated with the daemon process, >> not >> the zookeeper process. This causes the stop feature to fail. >> >> Before I go about re-writing this init script, I figure someone else >> must >> have a proper way of starting this up as a non-root user. >> >> >> > > > -- > Nguyen Nam Chuong > Software Engineer - VNG Cooperation > Ho Chi Minh City - Vietnam > -- Matthew Sims
-
Re: Zookeeper run as non-root
Tadeusz Andrzej Kadłubows... 2012-08-16, 08:04
W dniu 14.08.2012 23:02, Matthew Sims pisze: > Hello, we're just starting to implement a Zookeeper where I work on a Red > Hat system. > > We've set everything up and it starts up just fine. The only issue is that > the process is run by the root user. > > sudo /etc/init.d/zookeeper start > > I have a zookeeper user ready to go. The init script we have makes a java > call to start up the process. > > start) > echo -n "Starting zookeeper ... " > if [ -f $ZOOPIDFILE ]; then > if kill -0 `cat $ZOOPIDFILE` > /dev/null 2>&1; then > echo $command already running as process `cat $ZOOPIDFILE`. > exit 0 > fi > fi > nohup $JAVA "-Dzookeeper.log.dir=${ZOO_LOG_DIR}" > "-Dzookeeper.root.logger=${ZOO_LOG4J_PROP}" \ > -cp "$CLASSPATH" $JVMFLAGS $ZOOMAIN "$ZOOCFG" > "$_ZOO_DAEMON_OUT" > 2>&1 < /dev/null & > if [ $? -eq 0 ] > then > if /bin/echo -n $! > "$ZOOPIDFILE" > then > sleep 1 > echo STARTED > else > echo FAILED TO WRITE PID > exit 1 > fi > else > echo SERVER DID NOT START > exit 1 > fi > ;; > > > I've looked in to editing this script, including /etc/init.d/functions and > calling the daemon function to run the start as user zookeeper. But this > forks the process and the PID file is updated with the daemon process, not > the zookeeper process. This causes the stop feature to fail. > > Before I go about re-writing this init script, I figure someone else must > have a proper way of starting this up as a non-root user. I run ZooKeeper on Centos 6 (which is a clone of Red Hat Enterprise Linux 6). I use upstart to manage the ZooKeeper service. In the upstart job configuration I have an exec stanza:
exec su -c "/usr/java/default/bin/java [-D this, -D that etc.] org.apache.zookeeper.server.quorum.QuorumPeerMain /etc/zookeeper/z oo.cfg" zookeeper
In newer upstart version than what's available in RHEL 6 there's a "setuid" stanza, which is as an straightforward solution to this problem as can be.
Best regards,
-- Tadeusz Andrzej Kadłubowski Dział Rozwoju Technologii Wirtualna Polska S.A.
"WIRTUALNA POLSKA" Spolka Akcyjna z siedziba w Gdansku przy ul. Traugutta 115 C, wpisana do Krajowego Rejestru Sadowego - Rejestru Przedsiebiorcow prowadzonego przez Sad Rejonowy Gdansk - Polnoc w Gdansku pod numerem KRS 0000068548, o kapitale zakladowym 67.980.024,00 zlotych oplaconym w calosci oraz Numerze Identyfikacji Podatkowej 957-07-51-216.
|
|