问:
Call From <hostname>/<ip> to <hostname>:9000 failed on connection exception: java.net.ConnectException: Connection refused
I tried to deploy a test hadoop cluster environment. When I start it, all logs are right, but cann't run any hadoop command, and I found 9000 port didn't be listened.

Run hadoop command(ERROR, all commands are the same error):

```<code>hadoop-2.5.0/bin$ ./hdfs dfs -ls /
14/08/15 10:19:52 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
ls: Call From master-hadoop/172.17.65.225 to master-hadoop:9000 failed on connection exception: java.net.ConnectException: Connection refused; For more details see:  http://wiki.apache.org/hadoop/ConnectionRefused
</code>```

Namenode 9000 port doesn't be listened

```<code>hadoop-2.5.0/bin$ sudo netstat -ntap | grep 9000
Terminal console doesn't output anything.
</code>```

hadoop configuration:

core-site.xml

```<code><configuration>
    <property>
        <name>fs.defaultFS</name>
        <value>hdfs://master-hadoop:9000</value>
    </property>
    <property>
        <name>io.file.buffer.size</name>
        <value>131072</value>
    </property>
    <property>
        <name>hadoop.tmp.dir</name>
        <value>file:/home/hadoop/hadoop/tmp</value>
    </property>
</configuration>
</code>```

hdfs-site:xml

```<code><configuration>
    <property>
        <name>dfs.namenode.rpc-address</name>
        <value>master-hadoop:9001</value>
    </property>
    <property>
        <name>dfs.namenode.secondary.http-address</name>
        <value>secondary-hadoop:50090</value>
    </property>
    <property>
        <name>dfs.namenode.name.dir</name>
        <value>file:/home/hadoop/hadoop/dfs/name</value>
    </property>
    <property>
        <name>dfs.namenode.data.dir</name>
        <value>file:/home/hadoop/hadoop/dfs/data</value>
    </property>
    <property>
        <name>dfs.replication</name>
        <value>2</value>
    </property>
    <property>
        <name>dfs.webhdfs.enabled</name>
        <value>true</value>
    </property>
</configuration>
</code>```

mapred-site.xml

```<code><configuration>
    <property>
        <name>mapreduce.framework.name</name>
        <value>yarn</value>
    </property>
    <property>
        <name>mapreduce.jobhistory.address</name>
        <value>master-hadoop:10020</value>
    </property>
    <property>
        <name>mapreduce.jobhistory.webapp.address</name>
        <value>master-hadoop:19888</value>
    </property>
</configuration>
</code>```

yarn-site.xml

```<code><configuration>
    <property>
        <name>yarn.nodemanager.aux-services</name>
        <value>mapreduce-shuffle</value>
    </property>
    <property>
        <name>yarn.nodemanager.aux-services.mapreduce.shuffle.class</name>
        <value>org.apache.hadoop.mapred.ShuffleHandler</value>
    </property>
    <property>
        <name>yarn.resourcemanager.address</name>
        <value>master-hadoop:8032</value>
    </property>
    <property>
        <name>yarn.resourcemanager.scheduler.address</name>
        <value>master-hadoop:8030</value>
    </property>
    <property>
        <name>yarn.resourcemanager.resource-tracker.address</name>
        <value>master-hadoop:8031</value>
    </property>
    <property>
        <name>yarn.resourcemanager.admin.address</name>
        <value>master-hadoop:8033</value>
    </property>
    <property>
        <name>yarn.resourcemanager.webapp.address</name>
        <value>master-hadoop:8088</value>
    </property>
</configuration>
</code>```

Namenode /etc/hosts:

```<code>172.17.65.225  master-hadoop
127.0.0.1       master-hadoop

::1      master-hadoop localhost

172.17.65.151  slave1-hadoop
172.17.65.14   slave2-hadoop
172.17.65.117  secondary-hadoop
</code>```

Namenode format log:

hadoop-2.5.0/bin$ ./hdfs namenode -format

```<code>14/08/15 10:16:16 INFO namenode.NameNode: STARTUP_MSG:
/************************************************************
STARTUP_MSG: Starting NameNode
STARTUP_MSG:   host = master-hadoop/172.17.65.225
STARTUP_MSG:   args = [-format]
STARTUP_MSG:   version = 2.5.0
STARTUP_MSG:   classpath = /home/hadoop/hadoop/hadoop-2.5.0/etc/hadoop:/home/hadoop/hadoop/hadoop-2.5.0/share/hadoop/common/lib/jersey-json-1.9.jar:
...
:/home/hadoop/hadoop/hadoop-2.5.0/contrib/capacity-scheduler/*.jar
STARTUP_MSG:   build = http://svn.apache.org/repos/asf/hadoop/common -r 1616291; compiled by 'jenkins' on 2014-08-06T17:31Z
STARTUP_MSG:   java = 1.7.0_21
************************************************************/
14/08/15 10:16:16 INFO namenode.NameNode: registered UNIX signal handlers for [TERM, HUP, INT]
14/08/15 10:16:16 INFO namenode.NameNode: createNameNode [-format]
14/08/15 10:16:16 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
Formatting using clusterid: CID-4d27991c-4852-407c-9c6b-70df76994d13
14/08/15 10:16:16 INFO namenode.FSNamesystem: fsLock is fair:true
14/08/15 10:16:16 INFO blockmanagement.DatanodeManager: dfs.block.invalidate.limit=1000
14/08/15 10:16:16 INFO blockmanagement.DatanodeManager: dfs.namenode.datanode.registration.ip-hostname-check=true
14/08/15 10:16:16 INFO blockmanagement.BlockManager: dfs.namenode.startup.delay.block.deletion.sec is set to 000:00:00:00.000
14/08/15 10:16:16 INFO blockmanagement.BlockManager: The block deletion will start around 2014 Aug 15 10:16:16
14/08/15 10:16:16 INFO util.GSet: Computing capacity for map BlocksMap
14/08/15 10:16:16 INFO util.GSet: VM type       = 32-bit
14/08/15 10:16:16 INFO util.GSet: 2.0% max memory 888.9 MB = 17.8 MB
14/08/15 10:16:16 INFO util.GSet: capacity      = 2^22 = 4194304 entries
14/08/15 10:16:16 INFO blockmanagement.BlockManager: dfs.block.access.token.enable=false
14/08/15 10:16:16 INFO blockmanagement.BlockManager: defaultReplication         = 2
14/08/15 10:16:16 INFO blockmanagement.BlockManager: maxReplication             = 512
14/08/15 10:16:16 INFO blockmanagement.BlockManager: minReplication             = 1
14/08/15 10:16:16 INFO blockmanagement.BlockManager: maxReplicationStreams      = 2
14/08/15 10:16:16 INFO blockmanagement.BlockManager: shouldCheckForEnoughRacks  = false
14/08/15 10:16:16 INFO blockmanagement.BlockManager: replicationRecheckInterval = 3000
14/08/15 10:16:16 INFO blockmanagement.BlockManager: encryptDataTransfer        = false
14/08/15 10:16:16 INFO blockmanagement.BlockManager: maxNumBlocksToLog          = 1000
14/08/15 10:16:16 INFO namenode.FSNamesystem: fsOwner             = hadoop (auth:SIMPLE)
14/08/15 10:16:16 INFO namenode.FSNamesystem: supergroup          = supergroup
14/08/15 10:16:16 INFO namenode.FSNamesystem: isPermissionEnabled = true
14/08/15 10:16:16 INFO namenode.FSNamesystem: HA Enabled: false
14/08/15 10:16:16 INFO namenode.FSNamesystem: Append Enabled: true
14/08/15 10:16:17 INFO util.GSet: Computing capacity for map INodeMap
14/08/15 10:16:17 INFO util.GSet: VM type       = 32-bit
14/08/15 10:16:17 INFO util.GSet: 1.0% max memory 888.9 MB = 8.9 MB
14/08/15 10:16:17 INFO util.GSet: capacity      = 2^21 = 2097152 entries
14/08/15 10:16:17 INFO namenode.NameNode: Caching file names occuring more than 10 times
14/08/15 10:16:17 INFO util.GSet: Computing capacity for map cachedBlocks
14/08/15 10:16:17 INFO util.GSet: VM type       = 32-bit
14/08/15 10:16:17 INFO util.GSet: 0.25% max memory 888.9 MB = 2.2 MB
14/08/15 10:16:17 INFO util.GSet: capacity      = 2^19 = 524288 entries
14/08/15 10:16:17 INFO namenode.FSNamesystem: dfs.namenode.safemode.threshold-pct = 0.9990000128746033
14/08/15 10:16:17 INFO namenode.FSNamesystem: dfs.namenode.safemode.min.datanodes = 0
14/08/15 10:16:17 INFO namenode.FSNamesystem: dfs.namenode.safemode.extension     = 30000
14/08/15 10:16:17 INFO namenode.FSNamesystem: Retry cache on namenode is enabled
14/08/15 10:16:17 INFO namenode.FSNamesystem: Retry cache will use 0.03 of total heap and retry cache entry expiry time is 600000 millis
14/08/15 10:16:17 INFO util.GSet: Computing capacity for map NameNodeRetryCache
14/08/15 10:16:17 INFO util.GSet: VM type       = 32-bit
14/08/15 10:16:17 INFO util.GSet: 0.029999999329447746% max memory 888.9 MB = 273.1 KB
14/08/15 10:16:17 INFO util.GSet: capacity      = 2^16 = 65536 entries
14/08/15 10:16:17 INFO namenode.NNConf: ACLs enabled? false
14/08/15 10:16:17 INFO namenode.NNConf: XAttrs enabled? true
14/08/15 10:16:17 INFO namenode.NNConf: Maximum size of an xattr: 16384
14/08/15 10:16:17 INFO namenode.FSImage: Allocated new BlockPoolId: BP-1935486596-172.17.65.225-1408068977173
14/08/15 10:16:17 INFO common.Storage: Storage directory /home/hadoop/hadoop/dfs/name has been successfully formatted.
14/08/15 10:16:17 INFO namenode.NNStorageRetentionManager: Going to retain 1 images with txid >= 0
14/08/15 10:16:17 INFO util.ExitUtil: Exiting with status 0
14/08/15 10:16:17 INFO namenode.NameNode: SHUTDOWN_MSG:
/************************************************************
SHUTDOWN_MSG: Shutting down NameNode at master-hadoop/172.17.65.225
************************************************************/
</code>```

hadoop-hadoop-namenode-master-hadoop.log

```<code>2014-08-15 10:17:48,855 INFO org.apache.hadoop.hdfs.server.namenode.NameNode: STARTUP_MSG:
/************************************************************
STARTUP_MSG: Starting NameNode
STARTUP_MSG:   host = master-hadoop/172.17.65.225
STARTUP_MSG:   args = []
STARTUP_MSG:   version = 2.5.0
STARTUP_MSG:   classpath = /home/hadoop/hadoop/hadoop-2.5.0/etc/hadoop:/home/hadoop/hadoop/hadoop-2.5.0/share/hadoop/common/lib/jersey-json-1.9.jar:
...
...
:/contrib/capacity-scheduler/*.jar
STARTUP_MSG:   build = http://svn.apache.org/repos/asf/hadoop/common -r 1616291; compiled by 'jenkins' on 2014-08-06T17:31Z
STARTUP_MSG:   java = 1.7.0_21
************************************************************/
2014-08-15 10:17:48,870 INFO org.apache.hadoop.hdfs.server.namenode.NameNode: registered UNIX signal handlers for [TERM, HUP, INT]
2014-08-15 10:17:48,880 INFO org.apache.hadoop.hdfs.server.namenode.NameNode: createNameNode []
2014-08-15 10:17:49,117 INFO org.apache.hadoop.metrics2.impl.MetricsConfig: loaded properties from hadoop-metrics2.properties
2014-08-15 10:17:49,209 INFO org.apache.hadoop.metrics2.impl.MetricsSystemImpl: Scheduled snapshot period at 10 second(s).
2014-08-15 10:17:49,209 INFO org.apache.hadoop.metrics2.impl.MetricsSystemImpl: NameNode metrics system started
2014-08-15 10:17:49,211 INFO org.apache.hadoop.hdfs.server.namenode.NameNode: fs.defaultFS is hdfs://master-hadoop:9000
2014-08-15 10:17:49,211 INFO org.apache.hadoop.hdfs.server.namenode.NameNode: Clients are to use master-hadoop:9000 to access this namenode/service.
2014-08-15 10:17:49,389 WARN org.apache.hadoop.util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
2014-08-15 10:17:54,555 INFO org.apache.hadoop.hdfs.DFSUtil: Starting web server as: ${dfs.web.authentication.kerberos.principal}
2014-08-15 10:17:54,556 INFO org.apache.hadoop.hdfs.DFSUtil: Starting Web-server for hdfs at: http://0.0.0.0:50070
2014-08-15 10:17:54,605 INFO org.mortbay.log: Logging to org.slf4j.impl.Log4jLoggerAdapter(org.mortbay.log) via org.mortbay.log.Slf4jLog
2014-08-15 10:17:54,609 INFO org.apache.hadoop.http.HttpRequestLog: Http request log for http.requests.namenode is not defined
2014-08-15 10:17:54,620 INFO org.apache.hadoop.http.HttpServer2: Added global filter 'safety' (class=org.apache.hadoop.http.HttpServer2$QuotingInputFilter)
2014-08-15 10:17:54,622 INFO org.apache.hadoop.http.HttpServer2: Added filter static_user_filter (class=org.apache.hadoop.http.lib.StaticUserWebFilter$StaticUserFilter) to context hdfs
2014-08-15 10:17:54,622 INFO org.apache.hadoop.http.HttpServer2: Added filter static_user_filter (class=org.apache.hadoop.http.lib.StaticUserWebFilter$StaticUserFilter) to context logs
2014-08-15 10:17:54,623 INFO org.apache.hadoop.http.HttpServer2: Added filter static_user_filter (class=org.apache.hadoop.http.lib.StaticUserWebFilter$StaticUserFilter) to context static
2014-08-15 10:17:54,653 INFO org.apache.hadoop.http.HttpServer2: Added filter 'org.apache.hadoop.hdfs.web.AuthFilter' (class=org.apache.hadoop.hdfs.web.AuthFilter)
2014-08-15 10:17:54,655 INFO org.apache.hadoop.http.HttpServer2: addJerseyResourcePackage: packageName=org.apache.hadoop.hdfs.server.namenode.web.resources;org.apache.hadoop.hdfs.web.resources, pathSpec=/webhdfs/v1/*
2014-08-15 10:17:54,676 INFO org.apache.hadoop.http.HttpServer2: Jetty bound to port 50070
2014-08-15 10:17:54,676 INFO org.mortbay.log: jetty-6.1.26
2014-08-15 10:17:54,883 WARN org.apache.hadoop.security.authentication.server.AuthenticationFilter: 'signature.secret' configuration not set, using a random value as secret
2014-08-15 10:17:54,948 INFO org.mortbay.log: Started HttpServer2$SelectChannelConnectorWithSafeStartup@`0.0.0.0`:50070
2014-08-15 10:17:59,984 WARN org.apache.hadoop.hdfs.server.namenode.FSNamesystem: Only one image storage directory (dfs.namenode.name.dir) configured. Beware of data loss due to lack of redundant storage directories!
2014-08-15 10:17:59,984 WARN org.apache.hadoop.hdfs.server.namenode.FSNamesystem: Only one namespace edits storage directory (dfs.namenode.edits.dir) configured. Beware of data loss due to lack of redundant storage directories!
2014-08-15 10:18:00,023 INFO org.apache.hadoop.hdfs.server.namenode.FSNamesystem: fsLock is fair:true
2014-08-15 10:18:00,062 INFO org.apache.hadoop.hdfs.server.blockmanagement.DatanodeManager: dfs.block.invalidate.limit=1000
2014-08-15 10:18:00,062 INFO org.apache.hadoop.hdfs.server.blockmanagement.DatanodeManager: dfs.namenode.datanode.registration.ip-hostname-check=true
2014-08-15 10:18:00,065 INFO org.apache.hadoop.hdfs.server.blockmanagement.BlockManager: dfs.namenode.startup.delay.block.deletion.sec is set to 000:00:00:00.000
2014-08-15 10:18:00,066 INFO org.apache.hadoop.hdfs.server.blockmanagement.BlockManager: The block deletion will start around 2014 Aug 15 10:18:00
2014-08-15 10:18:00,068 INFO org.apache.hadoop.util.GSet: Computing capacity for map BlocksMap
2014-08-15 10:18:00,068 INFO org.apache.hadoop.util.GSet: VM type       = 32-bit
2014-08-15 10:18:00,069 INFO org.apache.hadoop.util.GSet: 2.0% max memory 888.9 MB = 17.8 MB
2014-08-15 10:18:00,069 INFO org.apache.hadoop.util.GSet: capacity      = 2^22 = 4194304 entries
2014-08-15 10:18:00,087 INFO org.apache.hadoop.hdfs.server.blockmanagement.BlockManager: dfs.block.access.token.enable=false
2014-08-15 10:18:00,087 INFO org.apache.hadoop.hdfs.server.blockmanagement.BlockManager: defaultReplication         = 2
2014-08-15 10:18:00,087 INFO org.apache.hadoop.hdfs.server.blockmanagement.BlockManager: maxReplication             = 512
2014-08-15 10:18:00,087 INFO org.apache.hadoop.hdfs.server.blockmanagement.BlockManager: minReplication             = 1
2014-08-15 10:18:00,087 INFO org.apache.hadoop.hdfs.server.blockmanagement.BlockManager: maxReplicationStreams      = 2
2014-08-15 10:18:00,087 INFO org.apache.hadoop.hdfs.server.blockmanagement.BlockManager: shouldCheckForEnoughRacks  = false
2014-08-15 10:18:00,087 INFO org.apache.hadoop.hdfs.server.blockmanagement.BlockManager: replicationRecheckInterval = 3000
2014-08-15 10:18:00,087 INFO org.apache.hadoop.hdfs.server.blockmanagement.BlockManager: encryptDataTransfer        = false
2014-08-15 10:18:00,087 INFO org.apache.hadoop.hdfs.server.blockmanagement.BlockManager: maxNumBlocksToLog          = 1000
2014-08-15 10:18:00,092 INFO org.apache.hadoop.hdfs.server.namenode.FSNamesystem: fsOwner             = hadoop (auth:SIMPLE)
2014-08-15 10:18:00,092 INFO org.apache.hadoop.hdfs.server.namenode.FSNamesystem: supergroup          = supergroup
2014-08-15 10:18:00,092 INFO org.apache.hadoop.hdfs.server.namenode.FSNamesystem: isPermissionEnabled = true
2014-08-15 10:18:00,092 INFO org.apache.hadoop.hdfs.server.namenode.FSNamesystem: HA Enabled: false
2014-08-15 10:18:00,094 INFO org.apache.hadoop.hdfs.server.namenode.FSNamesystem: Append Enabled: true
2014-08-15 10:18:00,279 INFO org.apache.hadoop.util.GSet: Computing capacity for map INodeMap
2014-08-15 10:18:00,279 INFO org.apache.hadoop.util.GSet: VM type       = 32-bit
2014-08-15 10:18:00,280 INFO org.apache.hadoop.util.GSet: 1.0% max memory 888.9 MB = 8.9 MB
2014-08-15 10:18:00,280 INFO org.apache.hadoop.util.GSet: capacity      = 2^21 = 2097152 entries
2014-08-15 10:18:00,297 INFO org.apache.hadoop.hdfs.server.namenode.NameNode: Caching file names occuring more than 10 times
2014-08-15 10:18:00,305 INFO org.apache.hadoop.util.GSet: Computing capacity for map cachedBlocks
2014-08-15 10:18:00,305 INFO org.apache.hadoop.util.GSet: VM type       = 32-bit
2014-08-15 10:18:00,306 INFO org.apache.hadoop.util.GSet: 0.25% max memory 888.9 MB = 2.2 MB
2014-08-15 10:18:00,306 INFO org.apache.hadoop.util.GSet: capacity      = 2^19 = 524288 entries
2014-08-15 10:18:00,308 INFO org.apache.hadoop.hdfs.server.namenode.FSNamesystem: dfs.namenode.safemode.threshold-pct = 0.9990000128746033
2014-08-15 10:18:00,308 INFO org.apache.hadoop.hdfs.server.namenode.FSNamesystem: dfs.namenode.safemode.min.datanodes = 0
2014-08-15 10:18:00,308 INFO org.apache.hadoop.hdfs.server.namenode.FSNamesystem: dfs.namenode.safemode.extension     = 30000
2014-08-15 10:18:00,310 INFO org.apache.hadoop.hdfs.server.namenode.FSNamesystem: Retry cache on namenode is enabled
2014-08-15 10:18:00,310 INFO org.apache.hadoop.hdfs.server.namenode.FSNamesystem: Retry cache will use 0.03 of total heap and retry cache entry expiry time is 600000 millis
2014-08-15 10:18:00,312 INFO org.apache.hadoop.util.GSet: Computing capacity for map NameNodeRetryCache
2014-08-15 10:18:00,312 INFO org.apache.hadoop.util.GSet: VM type       = 32-bit
2014-08-15 10:18:00,312 INFO org.apache.hadoop.util.GSet: 0.029999999329447746% max memory 888.9 MB = 273.1 KB
2014-08-15 10:18:00,312 INFO org.apache.hadoop.util.GSet: capacity      = 2^16 = 65536 entries
2014-08-15 10:18:00,316 INFO org.apache.hadoop.hdfs.server.namenode.NNConf: ACLs enabled? false
2014-08-15 10:18:00,316 INFO org.apache.hadoop.hdfs.server.namenode.NNConf: XAttrs enabled? true
2014-08-15 10:18:00,317 INFO org.apache.hadoop.hdfs.server.namenode.NNConf: Maximum size of an xattr: 16384
2014-08-15 10:18:00,355 INFO org.apache.hadoop.hdfs.server.common.Storage: Lock on /home/hadoop/hadoop/dfs/name/in_use.lock acquired by nodename 21145@master-hadoop
2014-08-15 10:18:00,433 INFO org.apache.hadoop.hdfs.server.namenode.FileJournalManager: Recovering unfinalized segments in /home/hadoop/hadoop/dfs/name/current
2014-08-15 10:18:00,433 INFO org.apache.hadoop.hdfs.server.namenode.FSImage: No edit log streams selected.
2014-08-15 10:18:00,488 INFO org.apache.hadoop.hdfs.server.namenode.FSImageFormatPBINode: Loading 1 INodes.
2014-08-15 10:18:00,534 INFO org.apache.hadoop.hdfs.server.namenode.FSImageFormatProtobuf: Loaded FSImage in 0 seconds.
2014-08-15 10:18:00,534 INFO org.apache.hadoop.hdfs.server.namenode.FSImage: Loaded image for txid 0 from /home/hadoop/hadoop/dfs/name/current/fsimage_0000000000000000000
2014-08-15 10:18:00,542 INFO org.apache.hadoop.hdfs.server.namenode.FSNamesystem: Need to save fs image? false (staleImage=false, haEnabled=false, isRollingUpgrade=false)
2014-08-15 10:18:00,543 INFO org.apache.hadoop.hdfs.server.namenode.FSEditLog: Starting log segment at 1
2014-08-15 10:18:00,689 INFO org.apache.hadoop.hdfs.server.namenode.NameCache: initialized with 0 entries 0 lookups
2014-08-15 10:18:00,689 INFO org.apache.hadoop.hdfs.server.namenode.FSNamesystem: Finished loading FSImage in 372 msecs
2014-08-15 10:18:00,902 INFO org.apache.hadoop.hdfs.server.namenode.NameNode: RPC server is binding to master-hadoop:9001
2014-08-15 10:18:00,909 INFO org.apache.hadoop.ipc.CallQueueManager: Using callQueue class java.util.concurrent.LinkedBlockingQueue
2014-08-15 10:18:00,923 INFO org.apache.hadoop.ipc.Server: Starting Socket Reader #1 for port 9001
2014-08-15 10:18:00,954 INFO org.apache.hadoop.hdfs.server.namenode.FSNamesystem: Registered FSNamesystemState MBean
2014-08-15 10:18:00,963 INFO org.apache.hadoop.hdfs.server.namenode.FSNamesystem: Number of blocks under construction: 0
2014-08-15 10:18:00,963 INFO org.apache.hadoop.hdfs.server.namenode.FSNamesystem: Number of blocks under construction: 0
2014-08-15 10:18:00,963 INFO org.apache.hadoop.hdfs.server.namenode.FSNamesystem: initializing replication queues
2014-08-15 10:18:00,963 INFO org.apache.hadoop.hdfs.StateChange: STATE* Leaving safe mode after 0 secs
2014-08-15 10:18:00,963 INFO org.apache.hadoop.hdfs.StateChange: STATE* Network topology has 0 racks and 0 datanodes
2014-08-15 10:18:00,964 INFO org.apache.hadoop.hdfs.StateChange: STATE* UnderReplicatedBlocks has 0 blocks
2014-08-15 10:18:00,982 INFO org.apache.hadoop.hdfs.server.blockmanagement.BlockManager: Total number of blocks            = 0
2014-08-15 10:18:00,994 INFO org.apache.hadoop.hdfs.server.blockmanagement.BlockManager: Number of invalid blocks          = 0
2014-08-15 10:18:00,994 INFO org.apache.hadoop.hdfs.server.blockmanagement.BlockManager: Number of under-replicated blocks = 0
2014-08-15 10:18:00,994 INFO org.apache.hadoop.hdfs.server.blockmanagement.BlockManager: Number of  over-replicated blocks = 0
2014-08-15 10:18:00,994 INFO org.apache.hadoop.hdfs.server.blockmanagement.BlockManager: Number of blocks being written    = 0
2014-08-15 10:18:00,994 INFO org.apache.hadoop.hdfs.StateChange: STATE* Replication Queue initialization scan for invalid, over- and under-replicated blocks completed in 31 msec
2014-08-15 10:18:01,010 INFO org.apache.hadoop.ipc.Server: IPC Server Responder: starting
2014-08-15 10:18:01,011 INFO org.apache.hadoop.ipc.Server: IPC Server listener on 9001: starting
2014-08-15 10:18:01,131 INFO org.apache.hadoop.hdfs.server.namenode.NameNode: NameNode RPC up at: master-hadoop/172.17.65.225:9001
2014-08-15 10:18:01,132 INFO org.apache.hadoop.hdfs.server.namenode.FSNamesystem: Starting services required for active state
2014-08-15 10:18:01,142 INFO org.apache.hadoop.hdfs.server.blockmanagement.CacheReplicationMonitor: Starting CacheReplicationMonitor with interval 30000 milliseconds
2014-08-15 10:18:01,142 INFO org.apache.hadoop.hdfs.server.blockmanagement.CacheReplicationMonitor: Rescanning because of pending operations
2014-08-15 10:18:01,147 INFO org.apache.hadoop.hdfs.server.blockmanagement.CacheReplicationMonitor: Scanned 0 directive(s) and 0 block(s) in 5 millisecond(s).
2014-08-15 10:18:02,566 INFO org.apache.hadoop.hdfs.StateChange: BLOCK* registerDatanode: from DatanodeRegistration(172.17.65.14, datanodeUuid=e3b6ade5-3534-4f5f-99fa-959bbbd9dce9, infoPort=50075, ipcPort=50020, storageInfo=lv=-55;cid=CID-4d27991c-4852-407c-9c6b-70df76994d13;nsid=995055688;c=0) storage e3b6ade5-3534-4f5f-99fa-959bbbd9dce9
2014-08-15 10:18:02,571 INFO org.apache.hadoop.net.NetworkTopology: Adding a new node: /default-rack/172.17.65.14:50010
2014-08-15 10:18:02,648 INFO org.apache.hadoop.hdfs.server.blockmanagement.DatanodeDescriptor: Adding new storage ID DS-8dee85fa-82b5-40a6-98e4-db44cca23371 for DN 172.17.65.14:50010
2014-08-15 10:18:02,698 INFO org.apache.hadoop.hdfs.server.blockmanagement.BlockManager: BLOCK* processReport: Received first block report from DatanodeStorage[DS-8dee85fa-82b5-40a6-98e4-db44cca23371,DISK,NORMAL] after starting up or becoming active. Its block contents are no longer considered stale
2014-08-15 10:18:02,698 INFO BlockStateChange: BLOCK* processReport: from storage DS-8dee85fa-82b5-40a6-98e4-db44cca23371 node DatanodeRegistration(172.17.65.14, datanodeUuid=e3b6ade5-3534-4f5f-99fa-959bbbd9dce9, infoPort=50075, ipcPort=50020, storageInfo=lv=-55;cid=CID-4d27991c-4852-407c-9c6b-70df76994d13;nsid=995055688;c=0), blocks: 0, hasStaleStorages: false, processing time: 3 msecs
2014-08-15 10:18:05,783 INFO org.apache.hadoop.hdfs.server.namenode.FSNamesystem: there are no corrupt file blocks.
2014-08-15 10:18:09,235 INFO org.apache.hadoop.hdfs.server.namenode.FSNamesystem: there are no corrupt file blocks.
2014-08-15 10:18:14,099 INFO org.apache.hadoop.hdfs.server.namenode.FSNamesystem: there are no corrupt file blocks.
2014-08-15 10:18:14,578 INFO org.apache.hadoop.hdfs.StateChange: BLOCK* registerDatanode: from DatanodeRegistration(172.17.65.151, datanodeUuid=43bc6f34-b8ad-4355-9fe4-9951f40e982a, infoPort=50075, ipcPort=50020, storageInfo=lv=-55;cid=CID-4d27991c-4852-407c-9c6b-70df76994d13;nsid=995055688;c=0) storage 43bc6f34-b8ad-4355-9fe4-9951f40e982a
2014-08-15 10:18:14,578 INFO org.apache.hadoop.net.NetworkTopology: Adding a new node: /default-rack/172.17.65.151:50010
2014-08-15 10:18:14,628 INFO org.apache.hadoop.hdfs.server.blockmanagement.DatanodeDescriptor: Adding new storage ID DS-1e42ed67-0da7-476a-9e67-d778cd56b2b1 for DN 172.17.65.151:50010
2014-08-15 10:18:14,660 INFO org.apache.hadoop.hdfs.server.blockmanagement.BlockManager: BLOCK* processReport: Received first block report from DatanodeStorage[DS-1e42ed67-0da7-476a-9e67-d778cd56b2b1,DISK,NORMAL] after starting up or becoming active. Its block contents are no longer considered stale
2014-08-15 10:18:14,660 INFO BlockStateChange: BLOCK* processReport: from storage DS-1e42ed67-0da7-476a-9e67-d778cd56b2b1 node DatanodeRegistration(172.17.65.151, datanodeUuid=43bc6f34-b8ad-4355-9fe4-9951f40e982a, infoPort=50075, ipcPort=50020, storageInfo=lv=-55;cid=CID-4d27991c-4852-407c-9c6b-70df76994d13;nsid=995055688;c=0), blocks: 0, hasStaleStorages: false, processing time: 1 msecs
2014-08-15 10:18:19,074 INFO org.apache.hadoop.hdfs.server.namenode.FSNamesystem: there are no corrupt file blocks.
2014-08-15 10:18:31,143 INFO org.apache.hadoop.hdfs.server.blockmanagement.CacheReplicationMonitor: Rescanning after 30000 milliseconds
2014-08-15 10:18:31,144 INFO org.apache.hadoop.hdfs.server.blockmanagement.CacheReplicationMonitor: Scanned 0 directive(s) and 0 block(s) in 1 millisecond(s).
2014-08-15 10:19:01,143 INFO org.apache.hadoop.hdfs.server.blockmanagement.CacheReplicationMonitor: Rescanning after 30000 milliseconds
2014-08-15 10:19:01,144 INFO org.apache.hadoop.hdfs.server.blockmanagement.CacheReplicationMonitor: Scanned 0 directive(s) and 0 block(s) in 1 millisecond(s).
2014-08-15 10:19:01,521 INFO org.apache.hadoop.hdfs.server.namenode.FSNamesystem: Roll Edit Log from 172.17.65.117
2014-08-15 10:19:01,521 INFO org.apache.hadoop.hdfs.server.namenode.FSEditLog: Rolling edit logs
2014-08-15 10:19:01,521 INFO org.apache.hadoop.hdfs.server.namenode.FSEditLog: Ending log segment 1
2014-08-15 10:19:01,522 INFO org.apache.hadoop.hdfs.server.namenode.FSEditLog: Number of transactions: 2 Total time for transactions(ms): 0 Number of transactions batched in Syncs: 0 Number of syncs: 2 SyncTimes(ms): 55
2014-08-15 10:19:01,536 INFO org.apache.hadoop.hdfs.server.namenode.FSEditLog: Number of transactions: 2 Total time for transactions(ms): 0 Number of transactions batched in Syncs: 0 Number of syncs: 3 SyncTimes(ms): 69
2014-08-15 10:19:01,538 INFO org.apache.hadoop.hdfs.server.namenode.FileJournalManager: Finalizing edits file /home/hadoop/hadoop/dfs/name/current/edits_inprogress_0000000000000000001 -> /home/hadoop/hadoop/dfs/name/current/edits_0000000000000000001-0000000000000000002
2014-08-15 10:19:01,542 INFO org.apache.hadoop.hdfs.server.namenode.FSEditLog: Starting log segment at 3
2014-08-15 10:19:02,094 WARN org.apache.hadoop.security.ssl.FileBasedKeyStoresFactory: The property 'ssl.client.truststore.location' has not been set, no TrustStore will be loaded
2014-08-15 10:19:02,969 INFO org.apache.hadoop.hdfs.server.namenode.TransferFsImage: Transfer took 0.05s at 0.00 KB/s
2014-08-15 10:19:02,969 INFO org.apache.hadoop.hdfs.server.namenode.TransferFsImage: Downloaded file fsimage.ckpt_0000000000000000002 size 353 bytes.
2014-08-15 10:19:03,014 INFO org.apache.hadoop.hdfs.server.namenode.NNStorageRetentionManager: Going to retain 2 images with txid >= 0
2014-08-15 10:19:31,143 INFO org.apache.hadoop.hdfs.server.blockmanagement.CacheReplicationMonitor: Rescanning after 30001 milliseconds
2014-08-15 10:19:31,145 INFO org.apache.hadoop.hdfs.server.blockmanagement.CacheReplicationMonitor: Scanned 0 directive(s) and 0 block(s) in 1 millisecond(s).
2014-08-15 10:20:01,144 INFO org.apache.hadoop.hdfs.server.blockmanagement.CacheReplicationMonitor: Rescanning after 30000 milliseconds
2014-08-15 10:20:01,145 INFO org.apache.hadoop.hdfs.server.blockmanagement.CacheReplicationMonitor: Scanned 0 directive(s) and 0 block(s) in 1 millisecond(s).
</code>```

Namenode jps:

```<code>/hadoop-2.5.0/logs$ jps
21145 NameNode
21409 ResourceManager
</code>```

Secondary jps:

```<code>hadoop-2.5.0$ jps
15534 SecondaryNameNode
</code>```

Datanode1 jps:

```<code>/hadoop-2.5.0$ jps
7350 DataNode
</code>```

Datanode2 jps:

```<code>/hadoop-2.5.0$ jps
11784 DataNode
</code>```

答:
Maybe you could have a try as follows:

edit /etc/hosts

127.0.0.1       master-hadoop  -> 127.0.0.1       localhost

stop all hadoop services

./sbin/stop-dfs.sh

./sbin/stop-yarn.sh

restart all hadoop services

./sbin/start-dfs.sh

./sbin/start-yarn.sh

Body:
I tried to deploy a test hadoop cluster environment. When I start it, all logs are right, but cann't run any hadoop command, and I found 9000 port didn't be listened.

Run hadoop command(ERROR, all commands are the same error):

hadoop-2.5.0/bin$ ./hdfs dfs -ls /
14/08/15 10:19:52 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
ls: Call From master-hadoop/172.17.65.225 to master-hadoop:9000 failed on connection exception: java.net.ConnectException: Connection refused; For more details see:  http://wiki.apache.org/hadoop/ConnectionRefused

Namenode 9000 port doesn't be listened

hadoop-2.5.0/bin$ sudo netstat -ntap | grep 9000
Terminal console doesn't output anything.

hadoop configuration:

core-site.xml

<configuration>
    <property>
        <name>fs.defaultFS</name>
        <value>hdfs://master-hadoop:9000</value>
    </property>
    <property>
        <name>io.file.buffer.size</name>
        <value>131072</value>
    </property>
    <property>
        <name>hadoop.tmp.dir</name>
        <value>file:/home/hadoop/hadoop/tmp</value>
    </property>
</configuration>

hdfs-site:xml

<configuration>
    <property>
        <name>dfs.namenode.rpc-address</name>
        <value>master-hadoop:9001</value>
    </property>
    <property>
        <name>dfs.namenode.secondary.http-address</name>
        <value>secondary-hadoop:50090</value>
    </property>
    <property>
        <name>dfs.namenode.name.dir</name>
        <value>file:/home/hadoop/hadoop/dfs/name</value>
    </property>
    <property>
        <name>dfs.namenode.data.dir</name>
        <value>file:/home/hadoop/hadoop/dfs/data</value>
    </property>
    <property>
        <name>dfs.replication</name>
        <value>2</value>
    </property>
    <property>
        <name>dfs.webhdfs.enabled</name>
        <value>true</value>
    </property>
</configuration>

mapred-site.xml

<configuration>
    <property>
        <name>mapreduce.framework.name</name>
        <value>yarn</value>
    </property>
    <property>
        <name>mapreduce.jobhistory.address</name>
        <value>master-hadoop:10020</value>
    </property>
    <property>
        <name>mapreduce.jobhistory.webapp.address</name>
        <value>master-hadoop:19888</value>
    </property>
</configuration>

yarn-site.xml

<configuration>
    <property>
        <name>yarn.nodemanager.aux-services</name>
        <value>mapreduce-shuffle</value>
    </property>
    <property>
        <name>yarn.nodemanager.aux-services.mapreduce.shuffle.class</name>
        <value>org.apache.hadoop.mapred.ShuffleHandler</value>
    </property>
    <property>
        <name>yarn.resourcemanager.address</name>
        <value>master-hadoop:8032</value>
    </property>
    <property>
        <name>yarn.resourcemanager.scheduler.address</name>
        <value>master-hadoop:8030</value>
    </property>
    <property>
        <name>yarn.resourcemanager.resource-tracker.address</name>
        <value>master-hadoop:8031</value>
    </property>
    <property>
        <name>yarn.resourcemanager.admin.address</name>
        <value>master-hadoop:8033</value>
    </property>
    <property>
        <name>yarn.resourcemanager.webapp.address</name>
        <value>master-hadoop:8088</value>
    </property>
</configuration>

Namenode /etc/hosts:

172.17.65.225  master-hadoop
127.0.0.1       master-hadoop

::1      master-hadoop localhost

172.17.65.151  slave1-hadoop
172.17.65.14   slave2-hadoop
172.17.65.117  secondary-hadoop

Namenode format log:

hadoop-2.5.0/bin$ ./hdfs namenode -format

14/08/15 10:16:16 INFO namenode.NameNode: STARTUP_MSG:
/************************************************************
STARTUP_MSG: Starting NameNode
STARTUP_MSG:   host = master-hadoop/172.17.65.225
STARTUP_MSG:   args = [-format]
STARTUP_MSG:   version = 2.5.0
STARTUP_MSG:   classpath = /home/hadoop/hadoop/hadoop-2.5.0/etc/hadoop:/home/hadoop/hadoop/hadoop-2.5.0/share/hadoop/common/lib/jersey-json-1.9.jar:
...
:/home/hadoop/hadoop/hadoop-2.5.0/contrib/capacity-scheduler/*.jar
STARTUP_MSG:   build = http://svn.apache.org/repos/asf/hadoop/common -r 1616291; compiled by 'jenkins' on 2014-08-06T17:31Z
STARTUP_MSG:   java = 1.7.0_21
************************************************************/
14/08/15 10:16:16 INFO namenode.NameNode: registered UNIX signal handlers for [TERM, HUP, INT]
14/08/15 10:16:16 INFO namenode.NameNode: createNameNode [-format]
14/08/15 10:16:16 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
Formatting using clusterid: CID-4d27991c-4852-407c-9c6b-70df76994d13
14/08/15 10:16:16 INFO namenode.FSNamesystem: fsLock is fair:true
14/08/15 10:16:16 INFO blockmanagement.DatanodeManager: dfs.block.invalidate.limit=1000
14/08/15 10:16:16 INFO blockmanagement.DatanodeManager: dfs.namenode.datanode.registration.ip-hostname-check=true
14/08/15 10:16:16 INFO blockmanagement.BlockManager: dfs.namenode.startup.delay.block.deletion.sec is set to 000:00:00:00.000
14/08/15 10:16:16 INFO blockmanagement.BlockManager: The block deletion will start around 2014 Aug 15 10:16:16
14/08/15 10:16:16 INFO util.GSet: Computing capacity for map BlocksMap
14/08/15 10:16:16 INFO util.GSet: VM type       = 32-bit
14/08/15 10:16:16 INFO util.GSet: 2.0% max memory 888.9 MB = 17.8 MB
14/08/15 10:16:16 INFO util.GSet: capacity      = 2^22 = 4194304 entries
14/08/15 10:16:16 INFO blockmanagement.BlockManager: dfs.block.access.token.enable=false
14/08/15 10:16:16 INFO blockmanagement.BlockManager: defaultReplication         = 2
14/08/15 10:16:16 INFO blockmanagement.BlockManager: maxReplication             = 512
14/08/15 10:16:16 INFO blockmanagement.BlockManager: minReplication             = 1
14/08/15 10:16:16 INFO blockmanagement.BlockManager: maxReplicationStreams      = 2
14/08/15 10:16:16 INFO blockmanagement.BlockManager: shouldCheckForEnoughRacks  = false
14/08/15 10:16:16 INFO blockmanagement.BlockManager: replicationRecheckInterval = 3000
14/08/15 10:16:16 INFO blockmanagement.BlockManager: encryptDataTransfer        = false
14/08/15 10:16:16 INFO blockmanagement.BlockManager: maxNumBlocksToLog          = 1000
14/08/15 10:16:16 INFO namenode.FSNamesystem: fsOwner             = hadoop (auth:SIMPLE)
14/08/15 10:16:16 INFO namenode.FSNamesystem: supergroup          = supergroup
14/08/15 10:16:16 INFO namenode.FSNamesystem: isPermissionEnabled = true
14/08/15 10:16:16 INFO namenode.FSNamesystem: HA Enabled: false
14/08/15 10:16:16 INFO namenode.FSNamesystem: Append Enabled: true
14/08/15 10:16:17 INFO util.GSet: Computing capacity for map INodeMap
14/08/15 10:16:17 INFO util.GSet: VM type       = 32-bit
14/08/15 10:16:17 INFO util.GSet: 1.0% max memory 888.9 MB = 8.9 MB
14/08/15 10:16:17 INFO util.GSet: capacity      = 2^21 = 2097152 entries
14/08/15 10:16:17 INFO namenode.NameNode: Caching file names occuring more than 10 times
14/08/15 10:16:17 INFO util.GSet: Computing capacity for map cachedBlocks
14/08/15 10:16:17 INFO util.GSet: VM type       = 32-bit
14/08/15 10:16:17 INFO util.GSet: 0.25% max memory 888.9 MB = 2.2 MB
14/08/15 10:16:17 INFO util.GSet: capacity      = 2^19 = 524288 entries
14/08/15 10:16:17 INFO namenode.FSNamesystem: dfs.namenode.safemode.threshold-pct = 0.9990000128746033
14/08/15 10:16:17 INFO namenode.FSNamesystem: dfs.namenode.safemode.min.datanodes = 0
14/08/15 10:16:17 INFO namenode.FSNamesystem: dfs.namenode.safemode.extension     = 30000
14/08/15 10:16:17 INFO namenode.FSNamesystem: Retry cache on namenode is enabled
14/08/15 10:16:17 INFO namenode.FSNamesystem: Retry cache will use 0.03 of total heap and retry cache entry expiry time is 600000 millis
14/08/15 10:16:17 INFO util.GSet: Computing capacity for map NameNodeRetryCache
14/08/15 10:16:17 INFO util.GSet: VM type       = 32-bit
14/08/15 10:16:17 INFO util.GSet: 0.029999999329447746% max memory 888.9 MB = 273.1 KB
14/08/15 10:16:17 INFO util.GSet: capacity      = 2^16 = 65536 entries
14/08/15 10:16:17 INFO namenode.NNConf: ACLs enabled? false
14/08/15 10:16:17 INFO namenode.NNConf: XAttrs enabled? true
14/08/15 10:16:17 INFO namenode.NNConf: Maximum size of an xattr: 16384
14/08/15 10:16:17 INFO namenode.FSImage: Allocated new BlockPoolId: BP-1935486596-172.17.65.225-1408068977173
14/08/15 10:16:17 INFO common.Storage: Storage directory /home/hadoop/hadoop/dfs/name has been successfully formatted.
14/08/15 10:16:17 INFO namenode.NNStorageRetentionManager: Going to retain 1 images with txid >= 0
14/08/15 10:16:17 INFO util.ExitUtil: Exiting with status 0
14/08/15 10:16:17 INFO namenode.NameNode: SHUTDOWN_MSG:
/************************************************************
SHUTDOWN_MSG: Shutting down NameNode at master-hadoop/172.17.65.225
************************************************************/

hadoop-hadoop-namenode-master-hadoop.log

2014-08-15 10:17:48,855 INFO org.apache.hadoop.hdfs.server.namenode.NameNode: STARTUP_MSG:
/************************************************************
STARTUP_MSG: Starting NameNode
STARTUP_MSG:   host = master-hadoop/172.17.65.225
STARTUP_MSG:   args = []
STARTUP_MSG:   version = 2.5.0
STARTUP_MSG:   classpath = /home/hadoop/hadoop/hadoop-2.5.0/etc/hadoop:/home/hadoop/hadoop/hadoop-2.5.0/share/hadoop/common/lib/jersey-json-1.9.jar:
...
...
:/contrib/capacity-scheduler/*.jar
STARTUP_MSG:   build = http://svn.apache.org/repos/asf/hadoop/common -r 1616291; compiled by 'jenkins' on 2014-08-06T17:31Z
STARTUP_MSG:   java = 1.7.0_21
************************************************************/
2014-08-15 10:17:48,870 INFO org.apache.hadoop.hdfs.server.namenode.NameNode: registered UNIX signal handlers for [TERM, HUP, INT]
2014-08-15 10:17:48,880 INFO org.apache.hadoop.hdfs.server.namenode.NameNode: createNameNode []
2014-08-15 10:17:49,117 INFO org.apache.hadoop.metrics2.impl.MetricsConfig: loaded properties from hadoop-metrics2.properties
2014-08-15 10:17:49,209 INFO org.apache.hadoop.metrics2.impl.MetricsSystemImpl: Scheduled snapshot period at 10 second(s).
2014-08-15 10:17:49,209 INFO org.apache.hadoop.metrics2.impl.MetricsSystemImpl: NameNode metrics system started
2014-08-15 10:17:49,211 INFO org.apache.hadoop.hdfs.server.namenode.NameNode: fs.defaultFS is hdfs://master-hadoop:9000
2014-08-15 10:17:49,211 INFO org.apache.hadoop.hdfs.server.namenode.NameNode: Clients are to use master-hadoop:9000 to access this namenode/service.
2014-08-15 10:17:49,389 WARN org.apache.hadoop.util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
2014-08-15 10:17:54,555 INFO org.apache.hadoop.hdfs.DFSUtil: Starting web server as: ${dfs.web.authentication.kerberos.principal}
2014-08-15 10:17:54,556 INFO org.apache.hadoop.hdfs.DFSUtil: Starting Web-server for hdfs at: http://0.0.0.0:50070
2014-08-15 10:17:54,605 INFO org.mortbay.log: Logging to org.slf4j.impl.Log4jLoggerAdapter(org.mortbay.log) via org.mortbay.log.Slf4jLog
2014-08-15 10:17:54,609 INFO org.apache.hadoop.http.HttpRequestLog: Http request log for http.requests.namenode is not defined
2014-08-15 10:17:54,620 INFO org.apache.hadoop.http.HttpServer2: Added global filter 'safety' (class=org.apache.hadoop.http.HttpServer2$QuotingInputFilter)
2014-08-15 10:17:54,622 INFO org.apache.hadoop.http.HttpServer2: Added filter static_user_filter (class=org.apache.hadoop.http.lib.StaticUserWebFilter$StaticUserFilter) to context hdfs
2014-08-15 10:17:54,622 INFO org.apache.hadoop.http.HttpServer2: Added filter static_user_filter (class=org.apache.hadoop.http.lib.StaticUserWebFilter$StaticUserFilter) to context logs
2014-08-15 10:17:54,623 INFO org.apache.hadoop.http.HttpServer2: Added filter static_user_filter (class=org.apache.hadoop.http.lib.StaticUserWebFilter$StaticUserFilter) to context static
2014-08-15 10:17:54,653 INFO org.apache.hadoop.http.HttpServer2: Added filter 'org.apache.hadoop.hdfs.web.AuthFilter' (class=org.apache.hadoop.hdfs.web.AuthFilter)
2014-08-15 10:17:54,655 INFO org.apache.hadoop.http.HttpServer2: addJerseyResourcePackage: packageName=org.apache.hadoop.hdfs.server.namenode.web.resources;org.apache.hadoop.hdfs.web.resources, pathSpec=/webhdfs/v1/*
2014-08-15 10:17:54,676 INFO org.apache.hadoop.http.HttpServer2: Jetty bound to port 50070
2014-08-15 10:17:54,676 INFO org.mortbay.log: jetty-6.1.26
2014-08-15 10:17:54,883 WARN org.apache.hadoop.security.authentication.server.AuthenticationFilter: 'signature.secret' configuration not set, using a random value as secret
2014-08-15 10:17:54,948 INFO org.mortbay.log: Started HttpServer2$SelectChannelConnectorWithSafeStartup@`0.0.0.0`:50070
2014-08-15 10:17:59,984 WARN org.apache.hadoop.hdfs.server.namenode.FSNamesystem: Only one image storage directory (dfs.namenode.name.dir) configured. Beware of data loss due to lack of redundant storage directories!
2014-08-15 10:17:59,984 WARN org.apache.hadoop.hdfs.server.namenode.FSNamesystem: Only one namespace edits storage directory (dfs.namenode.edits.dir) configured. Beware of data loss due to lack of redundant storage directories!
2014-08-15 10:18:00,023 INFO org.apache.hadoop.hdfs.server.namenode.FSNamesystem: fsLock is fair:true
2014-08-15 10:18:00,062 INFO org.apache.hadoop.hdfs.server.blockmanagement.DatanodeManager: dfs.block.invalidate.limit=1000
2014-08-15 10:18:00,062 INFO org.apache.hadoop.hdfs.server.blockmanagement.DatanodeManager: dfs.namenode.datanode.registration.ip-hostname-check=true
2014-08-15 10:18:00,065 INFO org.apache.hadoop.hdfs.server.blockmanagement.BlockManager: dfs.namenode.startup.delay.block.deletion.sec is set to 000:00:00:00.000
2014-08-15 10:18:00,066 INFO org.apache.hadoop.hdfs.server.blockmanagement.BlockManager: The block deletion will start around 2014 Aug 15 10:18:00
2014-08-15 10:18:00,068 INFO org.apache.hadoop.util.GSet: Computing capacity for map BlocksMap
2014-08-15 10:18:00,068 INFO org.apache.hadoop.util.GSet: VM type       = 32-bit
2014-08-15 10:18:00,069 INFO org.apache.hadoop.util.GSet: 2.0% max memory 888.9 MB = 17.8 MB
2014-08-15 10:18:00,069 INFO org.apache.hadoop.util.GSet: capacity      = 2^22 = 4194304 entries
2014-08-15 10:18:00,087 INFO org.apache.hadoop.hdfs.server.blockmanagement.BlockManager: dfs.block.access.token.enable=false
2014-08-15 10:18:00,087 INFO org.apache.hadoop.hdfs.server.blockmanagement.BlockManager: defaultReplication         = 2
2014-08-15 10:18:00,087 INFO org.apache.hadoop.hdfs.server.blockmanagement.BlockManager: maxReplication             = 512
2014-08-15 10:18:00,087 INFO org.apache.hadoop.hdfs.server.blockmanagement.BlockManager: minReplication             = 1
2014-08-15 10:18:00,087 INFO org.apache.hadoop.hdfs.server.blockmanagement.BlockManager: maxReplicationStreams      = 2
2014-08-15 10:18:00,087 INFO org.apache.hadoop.hdfs.server.blockmanagement.BlockManager: shouldCheckForEnoughRacks  = false
2014-08-15 10:18:00,087 INFO org.apache.hadoop.hdfs.server.blockmanagement.BlockManager: replicationRecheckInterval = 3000
2014-08-15 10:18:00,087 INFO org.apache.hadoop.hdfs.server.blockmanagement.BlockManager: encryptDataTransfer        = false
2014-08-15 10:18:00,087 INFO org.apache.hadoop.hdfs.server.blockmanagement.BlockManager: maxNumBlocksToLog          = 1000
2014-08-15 10:18:00,092 INFO org.apache.hadoop.hdfs.server.namenode.FSNamesystem: fsOwner             = hadoop (auth:SIMPLE)
2014-08-15 10:18:00,092 INFO org.apache.hadoop.hdfs.server.namenode.FSNamesystem: supergroup          = supergroup
2014-08-15 10:18:00,092 INFO org.apache.hadoop.hdfs.server.namenode.FSNamesystem: isPermissionEnabled = true
2014-08-15 10:18:00,092 INFO org.apache.hadoop.hdfs.server.namenode.FSNamesystem: HA Enabled: false
2014-08-15 10:18:00,094 INFO org.apache.hadoop.hdfs.server.namenode.FSNamesystem: Append Enabled: true
2014-08-15 10:18:00,279 INFO org.apache.hadoop.util.GSet: Computing capacity for map INodeMap
2014-08-15 10:18:00,279 INFO org.apache.hadoop.util.GSet: VM type       = 32-bit
2014-08-15 10:18:00,280 INFO org.apache.hadoop.util.GSet: 1.0% max memory 888.9 MB = 8.9 MB
2014-08-15 10:18:00,280 INFO org.apache.hadoop.util.GSet: capacity      = 2^21 = 2097152 entries
2014-08-15 10:18:00,297 INFO org.apache.hadoop.hdfs.server.namenode.NameNode: Caching file names occuring more than 10 times
2014-08-15 10:18:00,305 INFO org.apache.hadoop.util.GSet: Computing capacity for map cachedBlocks
2014-08-15 10:18:00,305 INFO org.apache.hadoop.util.GSet: VM type       = 32-bit
2014-08-15 10:18:00,306 INFO org.apache.hadoop.util.GSet: 0.25% max memory 888.9 MB = 2.2 MB
2014-08-15 10:18:00,306 INFO org.apache.hadoop.util.GSet: capacity      = 2^19 = 524288 entries
2014-08-15 10:18:00,308 INFO org.apache.hadoop.hdfs.server.namenode.FSNamesystem: dfs.namenode.safemode.threshold-pct = 0.9990000128746033
2014-08-15 10:18:00,308 INFO org.apache.hadoop.hdfs.server.namenode.FSNamesystem: dfs.namenode.safemode.min.datanodes = 0
2014-08-15 10:18:00,308 INFO org.apache.hadoop.hdfs.server.namenode.FSNamesystem: dfs.namenode.safemode.extension     = 30000
2014-08-15 10:18:00,310 INFO org.apache.hadoop.hdfs.server.namenode.FSNamesystem: Retry cache on namenode is enabled
2014-08-15 10:18:00,310 INFO org.apache.hadoop.hdfs.server.namenode.FSNamesystem: Retry cache will use 0.03 of total heap and retry cache entry expiry time is 600000 millis
2014-08-15 10:18:00,312 INFO org.apache.hadoop.util.GSet: Computing capacity for map NameNodeRetryCache
2014-08-15 10:18:00,312 INFO org.apache.hadoop.util.GSet: VM type       = 32-bit
2014-08-15 10:18:00,312 INFO org.apache.hadoop.util.GSet: 0.029999999329447746% max memory 888.9 MB = 273.1 KB
2014-08-15 10:18:00,312 INFO org.apache.hadoop.util.GSet: capacity      = 2^16 = 65536 entries
2014-08-15 10:18:00,316 INFO org.apache.hadoop.hdfs.server.namenode.NNConf: ACLs enabled? false
2014-08-15 10:18:00,316 INFO org.apache.hadoop.hdfs.server.namenode.NNConf: XAttrs enabled? true
2014-08-15 10:18:00,317 INFO org.apache.hadoop.hdfs.server.namenode.NNConf: Maximum size of an xattr: 16384
2014-08-15 10:18:00,355 INFO org.apache.hadoop.hdfs.server.common.Storage: Lock on /home/hadoop/hadoop/dfs/name/in_use.lock acquired by nodename 21145@master-hadoop
2014-08-15 10:18:00,433 INFO org.apache.hadoop.hdfs.server.namenode.FileJournalManager: Recovering unfinalized segments in /home/hadoop/hadoop/dfs/name/current
2014-08-15 10:18:00,433 INFO org.apache.hadoop.hdfs.server.namenode.FSImage: No edit log streams selected.
2014-08-15 10:18:00,488 INFO org.apache.hadoop.hdfs.server.namenode.FSImageFormatPBINode: Loading 1 INodes.
2014-08-15 10:18:00,534 INFO org.apache.hadoop.hdfs.server.namenode.FSImageFormatProtobuf: Loaded FSImage in 0 seconds.
2014-08-15 10:18:00,534 INFO org.apache.hadoop.hdfs.server.namenode.FSImage: Loaded image for txid 0 from /home/hadoop/hadoop/dfs/name/current/fsimage_0000000000000000000
2014-08-15 10:18:00,542 INFO org.apache.hadoop.hdfs.server.namenode.FSNamesystem: Need to save fs image? false (staleImage=false, haEnabled=false, isRollingUpgrade=false)
2014-08-15 10:18:00,543 INFO org.apache.hadoop.hdfs.server.namenode.FSEditLog: Starting log segment at 1
2014-08-15 10:18:00,689 INFO org.apache.hadoop.hdfs.server.namenode.NameCache: initialized with 0 entries 0 lookups
2014-08-15 10:18:00,689 INFO org.apache.hadoop.hdfs.server.namenode.FSNamesystem: Finished loading FSImage in 372 msecs
2014-08-15 10:18:00,902 INFO org.apache.hadoop.hdfs.server.namenode.NameNode: RPC server is binding to master-hadoop:9001
2014-08-15 10:18:00,909 INFO org.apache.hadoop.ipc.CallQueueManager: Using callQueue class java.util.concurrent.LinkedBlockingQueue
2014-08-15 10:18:00,923 INFO org.apache.hadoop.ipc.Server: Starting Socket Reader #1 for port 9001
2014-08-15 10:18:00,954 INFO org.apache.hadoop.hdfs.server.namenode.FSNamesystem: Registered FSNamesystemState MBean
2014-08-15 10:18:00,963 INFO org.apache.hadoop.hdfs.server.namenode.FSNamesystem: Number of blocks under construction: 0
2014-08-15 10:18:00,963 INFO org.apache.hadoop.hdfs.server.namenode.FSNamesystem: Number of blocks under construction: 0
2014-08-15 10:18:00,963 INFO org.apache.hadoop.hdfs.server.namenode.FSNamesystem: initializing replication queues
2014-08-15 10:18:00,963 INFO org.apache.hadoop.hdfs.StateChange: STATE* Leaving safe mode after 0 secs
2014-08-15 10:18:00,963 INFO org.apache.hadoop.hdfs.StateChange: STATE* Network topology has 0 racks and 0 datanodes
2014-08-15 10:18:00,964 INFO org.apache.hadoop.hdfs.StateChange: STATE* UnderReplicatedBlocks has 0 blocks
2014-08-15 10:18:00,982 INFO org.apache.hadoop.hdfs.server.blockmanagement.BlockManager: Total number of blocks            = 0
2014-08-15 10:18:00,994 INFO org.apache.hadoop.hdfs.server.blockmanagement.BlockManager: Number of invalid blocks          = 0
2014-08-15 10:18:00,994 INFO org.apache.hadoop.hdfs.server.blockmanagement.BlockManager: Number of under-replicated blocks = 0
2014-08-15 10:18:00,994 INFO org.apache.hadoop.hdfs.server.blockmanagement.BlockManager: Number of  over-replicated blocks = 0
2014-08-15 10:18:00,994 INFO org.apache.hadoop.hdfs.server.blockmanagement.BlockManager: Number of blocks being written    = 0
2014-08-15 10:18:00,994 INFO org.apache.hadoop.hdfs.StateChange: STATE* Replication Queue initialization scan for invalid, over- and under-replicated blocks completed in 31 msec
2014-08-15 10:18:01,010 INFO org.apache.hadoop.ipc.Server: IPC Server Responder: starting
2014-08-15 10:18:01,011 INFO org.apache.hadoop.ipc.Server: IPC Server listener on 9001: starting
2014-08-15 10:18:01,131 INFO org.apache.hadoop.hdfs.server.namenode.NameNode: NameNode RPC up at: master-hadoop/172.17.65.225:9001
2014-08-15 10:18:01,132 INFO org.apache.hadoop.hdfs.server.namenode.FSNamesystem: Starting services required for active state
2014-08-15 10:18:01,142 INFO org.apache.hadoop.hdfs.server.blockmanagement.CacheReplicationMonitor: Starting CacheReplicationMonitor with interval 30000 milliseconds
2014-08-15 10:18:01,142 INFO org.apache.hadoop.hdfs.server.blockmanagement.CacheReplicationMonitor: Rescanning because of pending operations
2014-08-15 10:18:01,147 INFO org.apache.hadoop.hdfs.server.blockmanagement.CacheReplicationMonitor: Scanned 0 directive(s) and 0 block(s) in 5 millisecond(s).
2014-08-15 10:18:02,566 INFO org.apache.hadoop.hdfs.StateChange: BLOCK* registerDatanode: from DatanodeRegistration(172.17.65.14, datanodeUuid=e3b6ade5-3534-4f5f-99fa-959bbbd9dce9, infoPort=50075, ipcPort=50020, storageInfo=lv=-55;cid=CID-4d27991c-4852-407c-9c6b-70df76994d13;nsid=995055688;c=0) storage e3b6ade5-3534-4f5f-99fa-959bbbd9dce9
2014-08-15 10:18:02,571 INFO org.apache.hadoop.net.NetworkTopology: Adding a new node: /default-rack/172.17.65.14:50010
2014-08-15 10:18:02,648 INFO org.apache.hadoop.hdfs.server.blockmanagement.DatanodeDescriptor: Adding new storage ID DS-8dee85fa-82b5-40a6-98e4-db44cca23371 for DN 172.17.65.14:50010
2014-08-15 10:18:02,698 INFO org.apache.hadoop.hdfs.server.blockmanagement.BlockManager: BLOCK* processReport: Received first block report from DatanodeStorage[DS-8dee85fa-82b5-40a6-98e4-db44cca23371,DISK,NORMAL] after starting up or becoming active. Its block contents are no longer considered stale
2014-08-15 10:18:02,698 INFO BlockStateChange: BLOCK* processReport: from storage DS-8dee85fa-82b5-40a6-98e4-db44cca23371 node DatanodeRegistration(172.17.65.14, datanodeUuid=e3b6ade5-3534-4f5f-99fa-959bbbd9dce9, infoPort=50075, ipcPort=50020, storageInfo=lv=-55;cid=CID-4d27991c-4852-407c-9c6b-70df76994d13;nsid=995055688;c=0), blocks: 0, hasStaleStorages: false, processing time: 3 msecs
2014-08-15 10:18:05,783 INFO org.apache.hadoop.hdfs.server.namenode.FSNamesystem: there are no corrupt file blocks.
2014-08-15 10:18:09,235 INFO org.apache.hadoop.hdfs.server.namenode.FSNamesystem: there are no corrupt file blocks.
2014-08-15 10:18:14,099 INFO org.apache.hadoop.hdfs.server.namenode.FSNamesystem: there are no corrupt file blocks.
2014-08-15 10:18:14,578 INFO org.apache.hadoop.hdfs.StateChange: BLOCK* registerDatanode: from DatanodeRegistration(172.17.65.151, datanodeUuid=43bc6f34-b8ad-4355-9fe4-9951f40e982a, infoPort=50075, ipcPort=50020, storageInfo=lv=-55;cid=CID-4d27991c-4852-407c-9c6b-70df76994d13;nsid=995055688;c=0) storage 43bc6f34-b8ad-4355-9fe4-9951f40e982a
2014-08-15 10:18:14,578 INFO org.apache.hadoop.net.NetworkTopology: Adding a new node: /default-rack/172.17.65.151:50010
2014-08-15 10:18:14,628 INFO org.apache.hadoop.hdfs.server.blockmanagement.DatanodeDescriptor: Adding new storage ID DS-1e42ed67-0da7-476a-9e67-d778cd56b2b1 for DN 172.17.65.151:50010
2014-08-15 10:18:14,660 INFO org.apache.hadoop.hdfs.server.blockmanagement.BlockManager: BLOCK* processReport: Received first block report from DatanodeStorage[DS-1e42ed67-0da7-476a-9e67-d778cd56b2b1,DISK,NORMAL] after starting up or becoming active. Its block contents are no longer considered stale
2014-08-15 10:18:14,660 INFO BlockStateChange: BLOCK* processReport: from storage DS-1e42ed67-0da7-476a-9e67-d778cd56b2b1 node DatanodeRegistration(172.17.65.151, datanodeUuid=43bc6f34-b8ad-4355-9fe4-9951f40e982a, infoPort=50075, ipcPort=50020, storageInfo=lv=-55;cid=CID-4d27991c-4852-407c-9c6b-70df76994d13;nsid=995055688;c=0), blocks: 0, hasStaleStorages: false, processing time: 1 msecs
2014-08-15 10:18:19,074 INFO org.apache.hadoop.hdfs.server.namenode.FSNamesystem: there are no corrupt file blocks.
2014-08-15 10:18:31,143 INFO org.apache.hadoop.hdfs.server.blockmanagement.CacheReplicationMonitor: Rescanning after 30000 milliseconds
2014-08-15 10:18:31,144 INFO org.apache.hadoop.hdfs.server.blockmanagement.CacheReplicationMonitor: Scanned 0 directive(s) and 0 block(s) in 1 millisecond(s).
2014-08-15 10:19:01,143 INFO org.apache.hadoop.hdfs.server.blockmanagement.CacheReplicationMonitor: Rescanning after 30000 milliseconds
2014-08-15 10:19:01,144 INFO org.apache.hadoop.hdfs.server.blockmanagement.CacheReplicationMonitor: Scanned 0 directive(s) and 0 block(s) in 1 millisecond(s).
2014-08-15 10:19:01,521 INFO org.apache.hadoop.hdfs.server.namenode.FSNamesystem: Roll Edit Log from 172.17.65.117
2014-08-15 10:19:01,521 INFO org.apache.hadoop.hdfs.server.namenode.FSEditLog: Rolling edit logs
2014-08-15 10:19:01,521 INFO org.apache.hadoop.hdfs.server.namenode.FSEditLog: Ending log segment 1
2014-08-15 10:19:01,522 INFO org.apache.hadoop.hdfs.server.namenode.FSEditLog: Number of transactions: 2 Total time for transactions(ms): 0 Number of transactions batched in Syncs: 0 Number of syncs: 2 SyncTimes(ms): 55
2014-08-15 10:19:01,536 INFO org.apache.hadoop.hdfs.server.namenode.FSEditLog: Number of transactions: 2 Total time for transactions(ms): 0 Number of transactions batched in Syncs: 0 Number of syncs: 3 SyncTimes(ms): 69
2014-08-15 10:19:01,538 INFO org.apache.hadoop.hdfs.server.namenode.FileJournalManager: Finalizing edits file /home/hadoop/hadoop/dfs/name/current/edits_inprogress_0000000000000000001 -> /home/hadoop/hadoop/dfs/name/current/edits_0000000000000000001-0000000000000000002
2014-08-15 10:19:01,542 INFO org.apache.hadoop.hdfs.server.namenode.FSEditLog: Starting log segment at 3
2014-08-15 10:19:02,094 WARN org.apache.hadoop.security.ssl.FileBasedKeyStoresFactory: The property 'ssl.client.truststore.location' has not been set, no TrustStore will be loaded
2014-08-15 10:19:02,969 INFO org.apache.hadoop.hdfs.server.namenode.TransferFsImage: Transfer took 0.05s at 0.00 KB/s
2014-08-15 10:19:02,969 INFO org.apache.hadoop.hdfs.server.namenode.TransferFsImage: Downloaded file fsimage.ckpt_0000000000000000002 size 353 bytes.
2014-08-15 10:19:03,014 INFO org.apache.hadoop.hdfs.server.namenode.NNStorageRetentionManager: Going to retain 2 images with txid >= 0
2014-08-15 10:19:31,143 INFO org.apache.hadoop.hdfs.server.blockmanagement.CacheReplicationMonitor: Rescanning after 30001 milliseconds
2014-08-15 10:19:31,145 INFO org.apache.hadoop.hdfs.server.blockmanagement.CacheReplicationMonitor: Scanned 0 directive(s) and 0 block(s) in 1 millisecond(s).
2014-08-15 10:20:01,144 INFO org.apache.hadoop.hdfs.server.blockmanagement.CacheReplicationMonitor: Rescanning after 30000 milliseconds
2014-08-15 10:20:01,145 INFO org.apache.hadoop.hdfs.server.blockmanagement.CacheReplicationMonitor: Scanned 0 directive(s) and 0 block(s) in 1 millisecond(s).

Namenode jps:

/hadoop-2.5.0/logs$ jps
21145 NameNode
21409 ResourceManager

Secondary jps:

hadoop-2.5.0$ jps
15534 SecondaryNameNode

Datanode1 jps:

/hadoop-2.5.0$ jps
7350 DataNode

Datanode2 jps:

/hadoop-2.5.0$ jps
11784 DataNode


来源: stackexchange

问:
What's the point of throwing an exception?
I'm writing a login class in c#, and I'm trying to be diligent about throwing exceptions for null passwords, insufficiant password characters, etc. The thing that suddenly occured to me was - What do I do with these exception? What/who are they for? Whether I handle the exception or not, the app will still fail at that point. Is the exception for other developers, the customer!? </p>

答:
So. you've written an excellent program. this program has a possible fail point. if for whatever reason the part of the program fails you might still want to continue the rest of the program and either call explicit attention to failure, log it, or just keep on going.

I'm going to use a pseudo-code syntax, but you should be able to follow it:

```<code>  var pw=$_POST['pw'];
    var un=$_POST['un'];
    try{
      $sql="select lastlogin,access from users where un=q(/'$un'/) and pw= q(/'md5($pw)'/)";
      $user=$db->getRow($sql);
      if(!$user) {
          //they don't exist
      }else{
        //process their login
      }
    }catch(Exception $e){
          //we has a Database error. either my query s really screwed up or the DB is down. let's log it and exit this stream; service
           $mylogger->log("Error while logging in using module $MODULENAME$ ".implode("<br/>",(array)$e));

         exit;
    }
</code>```

ContentLicense: CC BY-SA 2.5

Body:
So. you've written an excellent program. this program has a possible fail point. if for whatever reason the part of the program fails you might still want to continue the rest of the program and either call explicit attention to failure, log it, or just keep on going.

I'm going to use a pseudo-code syntax, but you should be able to follow it:

  var pw=$_POST['pw'];
    var un=$_POST['un'];
    try{
      $sql="select lastlogin,access from users where un=q(/'$un'/) and pw= q(/'md5($pw)'/)";
      $user=$db->getRow($sql);
      if(!$user) {
          //they don't exist
      }else{
        //process their login
      }
    }catch(Exception $e){
          //we has a Database error. either my query s really screwed up or the DB is down. let's log it and exit this stream; service
           $mylogger->log("Error while logging in using module $MODULENAME$ ".implode("<br/>",(array)$e));

         exit;
    }


问:
Error with chinese encoding with php
I have a file that contain Chinese character Like this :

```<code>合作伙伴
</code>```

problem and result looks like this :

```<code>ºÏ×÷»ï°é£º
</code>```

Even if I try to print the content in the browser , I get the same encoding problem.

I m sure it's an encoding problem but I can't fix it.

答:
Convert character encoding to utf-8 and use that only:</p>

```<code>$string = iconv('gb2312', 'utf-8', $string);
</code>```

ContentLicense: CC BY-SA 3.0

Title: Error with chinese encoding with php

Body:
I have a file that contain Chinese character Like this :

合作伙伴

problem and result looks like this :

ºÏ×÷»ï°é£º

Even if I try to print the content in the browser , I get the same encoding problem.

I m sure it's an encoding problem but I can't fix it.

Body:
Convert character encoding to utf-8 and use that only:

$string = iconv('gb2312', 'utf-8', $string);


问:
Dictionary only Storing One Key and Value/Overwriting Previous Key and Value
I am currently using a dictionary to store the index values of segmented controls which I have in each TableView cell. Each segmented control has a tag that corresponds to the index path of the row that it is in.

In the dictionary, the key is the segmented control's tag (or the index path of the row which the segmented control is in, however you please), and the value is the index of the segmented control itself (i.e. option 0 corresponds to index 0 and option 1 corresponds to index 1).

So, the dictionary would look something like this if there were three rows and the first segmented control had option 0 selected, the second segmented control had option 1 selected, and the third segmented control had option 1 selected:

```<code>[0:0, 1:1, 2:1]
</code>```

However, this is not what I get. When I print the dictionary, the only value in it is the key and index of the button which I had just pressed. Something like this:

```<code> [0:0]
 [1:1]
 [2:1]
</code>```

If I had selected option 0 for segmented control 1, option 1 for segmented control 2, and option 1 for segmented control 3 in that order.

Here is my code for reference:

```<code>import UIKit

class MyTableViewController: UITableViewController {

override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    return 150
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
    return 3
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{
    let cell = tableView.dequeueReusableCell(withIdentifier: "cellId", for: indexPath)

    let nameLabel: UILabel = {
        let label = UILabel()
        label.text = "Sample Item"
        label.translatesAutoresizingMaskIntoConstraints = false
        return label
    }()

    let actionButton = YSSegmentedControl(
        frame: CGRect.zero,
        titles: [
            "Yes",
            "No"
        ])

actionButton.delegate = self
cell.addSubview(nameLabel)
cell.addSubview(actionButton)
actionButton.translatesAutoresizingMaskIntoConstraints = false

cell.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|-16-[v0]-160-[v1]-16-|", options: NSLayoutFormatOptions(), metrics: nil, views: ["v0": nameLabel, "v1": actionButton]));
cell.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|[v0]|", options: NSLayoutFormatOptions(), metrics: nil, views: ["v0": nameLabel]))
cell.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|-60-[v0]-60-|", options: NSLayoutFormatOptions(), metrics: nil, views: ["v0": actionButton]))

actionButton.tag = indexPath.row

    cell.backgroundColor = .green
    return cell

}

override func viewDidLoad() {
    super.viewDidLoad()

    tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cellId")

    // Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}
</code>```

}

```<code>extension MyTableViewController: YSSegmentedControlDelegate {
func segmentedControl(_ segmentedControl: YSSegmentedControl, willPressItemAt     index: Int) {
    var indexToTag = [Int:Int]()
    indexToTag[index] = segmentedControl.tag

    // Looking up tag
    let tag = indexToTag[index]

    print("\(indexToTag)")

}

func segmentedControl(_ segmentedControl: YSSegmentedControl, didPressItemAt index: Int) {

}
</code>```

}

As well as a picture of my app:

https://i.stack.imgur.com/ezMUJ.png

Thanks,
Nick

答:
Revised:  It looks to me like you are getting a new dictionary before each

```<code>indexToTag[index] = segmentedControl.tag
</code>```

The code example uses a variable, indexToTag, whose scope is local to the function and does not survive.

If one could move the dictionary (indexToTag) from inside the function,
but still in the extension,then the stored property for the instance could be remember.

The problem with that is swift extensions do not directly permit stored properties in extensions.
(Check entries in Stack Overflow for stored properties and swift extensions).

The challenge is getting your code to have the desired class or instance variable to remember the dictionary contents.

Here is a sandbox example using a trivial extension.  The dictionary is outside the extension.

I don't know how your code might best accomplish something similar.

```<code>import Foundation

var indexToTag = [Int:Int]()

extension String {
   func control( index: Int, scTag: Int) {
      indexToTag[index] = scTag

      let tag = indexToTag[index]!
      print(" tag is \(tag)    indexToTag  contains: \(indexToTag)")
   }
}

let bst = String()

bst.control(index: 0, scTag: 0)
bst.control(index: 1, scTag: 1)
bst.control(index: 2, scTag: 1)
</code>```

which prints

```<code> tag is 0    indexToTag  contains: [0: 0]
 tag is 1    indexToTag  contains: [0: 0, 1: 1]
 tag is 1    indexToTag  contains: [2: 1, 0: 0, 1: 1]
</code>```

Note that indexToTag is a dictionary, thus the contents do not have the original order of insertion.

Body:
I am currently using a dictionary to store the index values of segmented controls which I have in each TableView cell. Each segmented control has a tag that corresponds to the index path of the row that it is in.

In the dictionary, the key is the segmented control's tag (or the index path of the row which the segmented control is in, however you please), and the value is the index of the segmented control itself (i.e. option 0 corresponds to index 0 and option 1 corresponds to index 1).

So, the dictionary would look something like this if there were three rows and the first segmented control had option 0 selected, the second segmented control had option 1 selected, and the third segmented control had option 1 selected:

[0:0, 1:1, 2:1]

However, this is not what I get. When I print the dictionary, the only value in it is the key and index of the button which I had just pressed. Something like this:

 [0:0]
 [1:1]
 [2:1]

If I had selected option 0 for segmented control 1, option 1 for segmented control 2, and option 1 for segmented control 3 in that order.

Here is my code for reference:

import UIKit

class MyTableViewController: UITableViewController {

override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
    return 150
}

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int{
    return 3
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell{
    let cell = tableView.dequeueReusableCell(withIdentifier: "cellId", for: indexPath)

    let nameLabel: UILabel = {
        let label = UILabel()
        label.text = "Sample Item"
        label.translatesAutoresizingMaskIntoConstraints = false
        return label
    }()

    let actionButton = YSSegmentedControl(
        frame: CGRect.zero,
        titles: [
            "Yes",
            "No"
        ])

actionButton.delegate = self
cell.addSubview(nameLabel)
cell.addSubview(actionButton)
actionButton.translatesAutoresizingMaskIntoConstraints = false

cell.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "H:|-16-[v0]-160-[v1]-16-|", options: NSLayoutFormatOptions(), metrics: nil, views: ["v0": nameLabel, "v1": actionButton]));
cell.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|[v0]|", options: NSLayoutFormatOptions(), metrics: nil, views: ["v0": nameLabel]))
cell.addConstraints(NSLayoutConstraint.constraints(withVisualFormat: "V:|-60-[v0]-60-|", options: NSLayoutFormatOptions(), metrics: nil, views: ["v0": actionButton]))

actionButton.tag = indexPath.row

    cell.backgroundColor = .green
    return cell

}

override func viewDidLoad() {
    super.viewDidLoad()

    tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cellId")

    // Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

}

extension MyTableViewController: YSSegmentedControlDelegate {
func segmentedControl(_ segmentedControl: YSSegmentedControl, willPressItemAt     index: Int) {
    var indexToTag = [Int:Int]()
    indexToTag[index] = segmentedControl.tag

    // Looking up tag
    let tag = indexToTag[index]

    print("\(indexToTag)")

}

func segmentedControl(_ segmentedControl: YSSegmentedControl, didPressItemAt index: Int) {

}

}

As well as a picture of my app:

https://i.stack.imgur.com/ezMUJ.png

Thanks,
Nick

Body:
Revised:  It looks to me like you are getting a new dictionary before each

indexToTag[index] = segmentedControl.tag

The code example uses a variable, indexToTag, whose scope is local to the function and does not survive.

If one could move the dictionary (indexToTag) from inside the function,
but still in the extension,then the stored property for the instance could be remember.

The problem with that is swift extensions do not directly permit stored properties in extensions.
(Check entries in Stack Overflow for stored properties and swift extensions).

The challenge is getting your code to have the desired class or instance variable to remember the dictionary contents.

Here is a sandbox example using a trivial extension.  The dictionary is outside the extension.

I don't know how your code might best accomplish something similar.

import Foundation

var indexToTag = [Int:Int]()

extension String {
   func control( index: Int, scTag: Int) {
      indexToTag[index] = scTag

      let tag = indexToTag[index]!
      print(" tag is \(tag)    indexToTag  contains: \(indexToTag)")
   }
}

let bst = String()

bst.control(index: 0, scTag: 0)
bst.control(index: 1, scTag: 1)
bst.control(index: 2, scTag: 1)

which prints

 tag is 0    indexToTag  contains: [0: 0]
 tag is 1    indexToTag  contains: [0: 0, 1: 1]
 tag is 1    indexToTag  contains: [2: 1, 0: 0, 1: 1]

Note that indexToTag is a dictionary, thus the contents do not have the original order of insertion.


问:
What are the consequences of removing the header image in a WordPress theme?
I'm working on my first WordPress theme.

The client doesn't seem to want a header image on every page, so I was just going to remove the  tag for the header image, but I want to double check first, what kind of impact will that have?

For example, does it affect certain widgets?

答: It really shouldn't affect anything.</p>

Body: It really shouldn't affect anything.


答:
Use JOIN Syntax to join the tables by id field:

```<code>SELECT
  host, size, winner, player, score
FROM
  tournaments INNER JOIN matchs USING (id);
</code>```

If you want to select rows that contains specific idonly,  then use WHERE  clause. In your case append following to the query before semicolon:

```<code>WHERE `id` IN (7, 8)
</code>```

Note, the MySQL can not create complex objects. SELECT returns set of rows only. To convert returned data set to structure, use external tools of your server side platform: C,  C++, C#, VB.NET, Python, PHP, etc.

Title: Get one row in table1 and Two or more rows in table2 in one array

Body:
Im newbie here. Suppose 2 tables in database:

Table 1: tournaments

+------------+----------+---------+----------+
|    id      |  format  |  Size   |  host    |
+------------+----------+---------+----------+
|     7      |  Single  |   9     |  Daniel  |
|     8      |  Single  |   4     |  Oscar   |
+------------+----------+---------+----------+

Table 2: matchs

+------------+----------+-------------+----------+----------+
|    id      |  player  |  position   |  score   |  winner  |
+------------+----------+-------------+----------+----------+
|     7      |  Arturo  |     0       |    3     |    1     |
|     7      |  Pablo   |     1       |    2     |    0     |
|     8      |  Ale     |     0       |    1     |    0     |
|     8      |  Maria   |     1       |    5     |    1     |
+------------+----------+-------------+----------+----------+

Now i want to get the host, size, winner, player, Score where ID is 7 and 8. Do you know how iget the following structure?:

[ Host:Daniel, size: 9, [ winner:1, player: Arturo, Score: 3], [winner:0, player: Pablo, Score: 2]], [host:Óscar, size:4,[winner:0, player: Ale, Score:0],....

Thanks in advance :)

Body:
Use JOIN Syntax to join the tables by id field:

SELECT
  host, size, winner, player, score
FROM
  tournaments INNER JOIN matchs USING (id);

If you want to select rows that contains specific idonly,  then use WHERE  clause. In your case append following to the query before semicolon:

WHERE `id` IN (7, 8)

Note, the MySQL can not create complex objects. SELECT returns set of rows only. To convert returned data set to structure, use external tools of your server side platform: C,  C++, C#, VB.NET, Python, PHP, etc.


问:
error installing RandForestGUI (hence 'rgl', 'X11) in "R version 2.13.1 (2011-07-08)"
I have installed "R version 2.13.1 (2011-07-08)", over "Ubuntu 10.04 - Lucid Lynx".
(I use RStudio 0.94.92), with all the headers needed to compile the many different packages I already installed.
I got stuck with   :  install.packages("RandForestGUI"). Everything ran smoothly until

```<code>.....
* DONE (sciplot)
ERROR: dependency ‘rgl’ is not available for package ‘clusterSim’
* removing ‘/home/rs/R/i486-pc-linux-gnu-library/2.13/clusterSim’
Warning in install.packages :
  installation of package 'clusterSim' had non-zero exit status
ERROR: dependency ‘clusterSim’ is not available for package ‘RandForestGUI’
* removing ‘/home/rs/R/i486-pc-linux-gnu-library/2.13/RandForestGUI’
Warning in install.packages :
  installation of package 'RandForestGUI' had non-zero exit status
</code>```

I tried to   : install.packages("rgl")    but

```<code>Installing package(s) into ‘/home/rs/R/i486-pc-linux-gnu-library/2.13’
(as ‘lib’ is unspecified)
provo con l'URL 'http://rm.mirror.garr.it/mirrors/CRAN/src/contrib/rgl_0.92.798.tar.gz'
Content type 'application/x-gzip' length 1677772 bytes (1.6 Mb)
URL aperto
==================================================
downloaded 1.6 Mb

* installing *source* package ‘rgl’ ...
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
….
checking for libpng-config... yes
configure: using libpng-config
configure: using libpng dynamic linkage
checking for X... no
configure: error: X11 not found but required, configure aborted.
ERROR: configuration failed for package ‘rgl’
* removing ‘/home/rs/R/i486-pc-linux-gnu-library/2.13/rgl’
Warning in install.packages :
  installation of package 'rgl' had non-zero exit status
</code>```

Finally I tried    : install.packages("X11") and

```<code>Installing package(s) into ‘/home/rs/R/i486-pc-linux-gnu-library/2.13’
(as ‘lib’ is unspecified)
Warning in install.packages :
  package ‘X11’ is not available (for R version 2.13.1)
</code>```

... was stuck!.

Is it possible to have RandForestGUI  in "R version 2.13.1 (2011-07-08)"?
Many thanks, Roberto Scotti

答:
Had a similar problem for the clusterSim package in OS X.

Found the solution on the rstudio board:

X11 isn't installed by default on newer versions of OS X, so I had to install Quartz (the osx distribution of X11)

Body:
I have installed "R version 2.13.1 (2011-07-08)", over "Ubuntu 10.04 - Lucid Lynx".
(I use RStudio 0.94.92), with all the headers needed to compile the many different packages I already installed.
I got stuck with   :  install.packages("RandForestGUI"). Everything ran smoothly until

.....
* DONE (sciplot)
ERROR: dependency ‘rgl’ is not available for package ‘clusterSim’
* removing ‘/home/rs/R/i486-pc-linux-gnu-library/2.13/clusterSim’
Warning in install.packages :
  installation of package 'clusterSim' had non-zero exit status
ERROR: dependency ‘clusterSim’ is not available for package ‘RandForestGUI’
* removing ‘/home/rs/R/i486-pc-linux-gnu-library/2.13/RandForestGUI’
Warning in install.packages :
  installation of package 'RandForestGUI' had non-zero exit status

I tried to   : install.packages("rgl")    but

Installing package(s) into ‘/home/rs/R/i486-pc-linux-gnu-library/2.13’
(as ‘lib’ is unspecified)
provo con l'URL 'http://rm.mirror.garr.it/mirrors/CRAN/src/contrib/rgl_0.92.798.tar.gz'
Content type 'application/x-gzip' length 1677772 bytes (1.6 Mb)
URL aperto
==================================================
downloaded 1.6 Mb

* installing *source* package ‘rgl’ ...
checking for gcc... gcc
checking for C compiler default output file name... a.out
checking whether the C compiler works... yes
checking whether we are cross compiling... no
….
checking for libpng-config... yes
configure: using libpng-config
configure: using libpng dynamic linkage
checking for X... no
configure: error: X11 not found but required, configure aborted.
ERROR: configuration failed for package ‘rgl’
* removing ‘/home/rs/R/i486-pc-linux-gnu-library/2.13/rgl’
Warning in install.packages :
  installation of package 'rgl' had non-zero exit status

Finally I tried    : install.packages("X11") and

Installing package(s) into ‘/home/rs/R/i486-pc-linux-gnu-library/2.13’
(as ‘lib’ is unspecified)
Warning in install.packages :
  package ‘X11’ is not available (for R version 2.13.1)

... was stuck!.

Is it possible to have RandForestGUI  in "R version 2.13.1 (2011-07-08)"?
Many thanks, Roberto Scotti


问:
Javascript in HTML not calling correctly
I'm trying to create a simple website using basic java script but I think i'm not able to call to the file correctly have tried multiple sources online but to no success. Can you have a look at my code and tell me what's wrong ?

html:

```<code><html>
<head>
<script src="js/js1.js" type="text/javascript"></script>
</head>
The total number of square feet in your house is:<br>
<script src="js/js1.js">test()</script>square feet.
</code>```

js:

```<code>function test() {
    var test = 15;
    document.write(test);
    return test;
}
</code>```

答:
This:

```<code><script src="js/js1.js">test()></script>
</code>```

Should be:

```<code><script>test()</script>
</code>```

Body:
I'm trying to create a simple website using basic java script but I think i'm not able to call to the file correctly have tried multiple sources online but to no success. Can you have a look at my code and tell me what's wrong ?

html:

The total number of square feet in your house is:

square feet.

js:

function test() {
    var test = 15;
    document.write(test);
    return test;
}

Body:
This:

<script src="js/js1.js">test()></script>

Should be:

<script>test()</script>


问:
VBA vlookup for value in a string and inverse
These are columns A, B and C in an excel sheet.

If the middle account number in column A is >=40000 and <60000 Then the Actual Amount is value should multiply by -1. What VB code does this?

```<code>Account Number    Account Description      Actual Amount

10-40100-400    Contributions - Support    ($12,843.63)
10-53450-400    Rental Income              ($9,584.60)
10-53500-400    Housing Income             ($67,933.38)
10-54900-400    Miscellanous Revenue       ($2,615.56)
10-72100-400    Salary and Wages            $43,378.11
10-72100-420    Salary and Wages            $607.91
10-72400-400    Health Insurance            $14,843.94
10-72440-400    Life Insurance              $286.62
10-72500-400    FICA Expense                $3,283.73
10-72500-420    FICA Expense                $46.50
10-75400-400    Professional Services       $9,392.28
10-81100-400    Office Supplies             $3,754.16
10-81300-400    Telephone                   $540.00
10-82110-400    Furnishings and Equipment   $6,186.20
10-82140-400    Maintenance & Repair-Equi   $4,658.21
10-82160-400    Maintenance & Repair-Buil   $13,576.61
10-82200-400    Utilities                   $35,467.33
10-82600-400    Vehicle Expenses            $196.18
10-83100-400    Meals and Entertainment     $10.83
10-83140-400    Travel                      $34.84
10-85240-400    Prop/Casualty Insurance     $22,535.60
10-85260-400    Auto Insurance              $691.47
10-85300-400    Dues and Subscriptions      $145.00
10-85980-400    Miscellaneous Expense      ($45.00)
10-86500-400    Permits and Licenses        $1,010.00
10-99150-400    Ministry Grant Transfers    $32,249.97
10-99200-400    Ministry Transfers         ($8,992.44)
20-72100-400    Salary and Wages            $0.00
Totals for 71500:                           $0.00

Grand Totals:                               $0.00
</code>```

I have tried copying column A into column D and then trimming it to the number.

Then use an if statement to do the inverse.

```<code>lastrow = Cells(Rows.Count, 2).End(xlUp).Row
Range("A15:A" & lastrow).Copy Range("D15")
Dim rng As Range
Dim rngsear As Range
Set rng = Range("D15:D" & lastrow)
For Each rng In Selection
rng = Mid(rng, 4, 5)
Next rng
With ActiveSheet
     lastrow = .Range("D" & .Rows.Count).End(xlUp).Row
     Set rng = .Range("D15:D" & lastrow)
     Set rngsear = .Range("C15:C" & lastrow)
     rngsear.Value = .Evaluate("IF((" & rng.Address & " >= 40000)*(" & rng.Address & " < 60000)," & rngsear.Address & " * -1," & rngsear.Address & ")")
End With
</code>```

But it conflicts with the previous code I used to get the 3 columns.

```<code>Dim sSheetName As String
Dim sDataRange As String
sSheetName = ActiveSheet.Name
sDataRange = Selection.Address
Range("C9:F9").Select
Selection.Cut Destination:=Range("D9:G9")
Range("C:C,D:D,F:F,G:G").Select
Range("G1").Activate
Selection.Delete Shift:=xlToLeft
    Dim lastrow As Long
lastrow = Cells(Rows.Count, 2).End(xlUp).Row
Range("A15:C" & lastrow).Sort key1:=Range("A15:A" & lastrow), _
order1:=xlAscending, Header:=xlNo
</code>```

Whats the best method to do this?

答:
Have a look at below and see if it helps.</p>

```<code>Sub Check()

Dim str_extract As String
Dim lastrow As Integer

lastrow = Cells(Rows.Count, 2).End(xlUp).Row

For x = 1 To lastrow

    If (Right(Left(Cells(x, 1).Value, 8), 5) >= 40000 And Right(Left(Cells(x, 1).Value, 8), 5) < 60000) _
    Then Cells(x, 3).Value = Cells(x, 3).Value * -1

Next x

MsgBox "Done"

End Sub
</code>```

Body:
These are columns A, B and C in an excel sheet.

If the middle account number in column A is >=40000 and <60000 Then the Actual Amount is value should multiply by -1. What VB code does this?

Account Number    Account Description      Actual Amount

10-40100-400    Contributions - Support    ($12,843.63)
10-53450-400    Rental Income              ($9,584.60)
10-53500-400    Housing Income             ($67,933.38)
10-54900-400    Miscellanous Revenue       ($2,615.56)
10-72100-400    Salary and Wages            $43,378.11
10-72100-420    Salary and Wages            $607.91
10-72400-400    Health Insurance            $14,843.94
10-72440-400    Life Insurance              $286.62
10-72500-400    FICA Expense                $3,283.73
10-72500-420    FICA Expense                $46.50
10-75400-400    Professional Services       $9,392.28
10-81100-400    Office Supplies             $3,754.16
10-81300-400    Telephone                   $540.00
10-82110-400    Furnishings and Equipment   $6,186.20
10-82140-400    Maintenance & Repair-Equi   $4,658.21
10-82160-400    Maintenance & Repair-Buil   $13,576.61
10-82200-400    Utilities                   $35,467.33
10-82600-400    Vehicle Expenses            $196.18
10-83100-400    Meals and Entertainment     $10.83
10-83140-400    Travel                      $34.84
10-85240-400    Prop/Casualty Insurance     $22,535.60
10-85260-400    Auto Insurance              $691.47
10-85300-400    Dues and Subscriptions      $145.00
10-85980-400    Miscellaneous Expense      ($45.00)
10-86500-400    Permits and Licenses        $1,010.00
10-99150-400    Ministry Grant Transfers    $32,249.97
10-99200-400    Ministry Transfers         ($8,992.44)
20-72100-400    Salary and Wages            $0.00
Totals for 71500:                           $0.00

Grand Totals:                               $0.00

I have tried copying column A into column D and then trimming it to the number.

Then use an if statement to do the inverse.

lastrow = Cells(Rows.Count, 2).End(xlUp).Row
Range("A15:A" & lastrow).Copy Range("D15")
Dim rng As Range
Dim rngsear As Range
Set rng = Range("D15:D" & lastrow)
For Each rng In Selection
rng = Mid(rng, 4, 5)
Next rng
With ActiveSheet
     lastrow = .Range("D" & .Rows.Count).End(xlUp).Row
     Set rng = .Range("D15:D" & lastrow)
     Set rngsear = .Range("C15:C" & lastrow)
     rngsear.Value = .Evaluate("IF((" & rng.Address & " >= 40000)*(" & rng.Address & " < 60000)," & rngsear.Address & " * -1," & rngsear.Address & ")")
End With

But it conflicts with the previous code I used to get the 3 columns.

Dim sSheetName As String
Dim sDataRange As String
sSheetName = ActiveSheet.Name
sDataRange = Selection.Address
Range("C9:F9").Select
Selection.Cut Destination:=Range("D9:G9")
Range("C:C,D:D,F:F,G:G").Select
Range("G1").Activate
Selection.Delete Shift:=xlToLeft
    Dim lastrow As Long
lastrow = Cells(Rows.Count, 2).End(xlUp).Row
Range("A15:C" & lastrow).Sort key1:=Range("A15:A" & lastrow), _
order1:=xlAscending, Header:=xlNo

Whats the best method to do this?

Body:
Have a look at below and see if it helps.

Sub Check()

Dim str_extract As String
Dim lastrow As Integer

lastrow = Cells(Rows.Count, 2).End(xlUp).Row

For x = 1 To lastrow

    If (Right(Left(Cells(x, 1).Value, 8), 5) >= 40000 And Right(Left(Cells(x, 1).Value, 8), 5) < 60000) _
    Then Cells(x, 3).Value = Cells(x, 3).Value * -1

Next x

MsgBox "Done"

End Sub